Renders Pod Destriptor File earlier
authorParker Berberian <pberberian@iol.unh.edu>
Fri, 9 Nov 2018 16:10:03 +0000 (11:10 -0500)
committerParker Berberian <pberberian@iol.unh.edu>
Wed, 2 Jan 2019 14:35:41 +0000 (09:35 -0500)
Currently, the PDF is rendered 'on-demand' every time you
visit the booking detail page. This change renders the pdf once
and saves it in the booking model. Advantages:
- saves computation of re-rendering pdf constantly
- fixes issue where pdf fails to render after booking expires

Change-Id: I58d20fadce088d78ebd22f1d6f67cab371823542
Signed-off-by: Parker Berberian <pberberian@iol.unh.edu>
src/booking/migrations/0002_booking_pdf.py [new file with mode: 0644]
src/booking/models.py
src/booking/views.py
src/workflow/models.py

diff --git a/src/booking/migrations/0002_booking_pdf.py b/src/booking/migrations/0002_booking_pdf.py
new file mode 100644 (file)
index 0000000..53232c9
--- /dev/null
@@ -0,0 +1,18 @@
+# Generated by Django 2.1 on 2018-11-09 16:09
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('booking', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='booking',
+            name='pdf',
+            field=models.TextField(blank=True, default=''),
+        ),
+    ]
index d0c77b4..74b766d 100644 (file)
@@ -57,6 +57,7 @@ class Booking(models.Model):
     config_bundle = models.ForeignKey(ConfigBundle, on_delete=models.SET_NULL, null=True)
     project = models.CharField(max_length=100, default="", blank=True, null=True)
     lab = models.ForeignKey(Lab, null=True, on_delete=models.SET_NULL)
+    pdf = models.TextField(blank=True, default="")
 
     class Meta:
         db_table = 'booking'
index ab43519..29b53e2 100644 (file)
@@ -112,7 +112,7 @@ def booking_detail_view(request, booking_id):
         {
             'title': 'Booking Details',
             'booking': booking,
-            'pdf': ResourceManager().makePDF(booking.resource),
+            'pdf': booking.pdf,
             'user_id': user.id
         })
 
index 966582c..6a8eca1 100644 (file)
@@ -458,6 +458,12 @@ class Repository():
         for collaborator in collaborators:
             booking.collaborators.add(collaborator)
 
+        try:
+            booking.pdf = ResourceManager().makePDF(booking.resource)
+            booking.save()
+        except Exception as e:
+            return "BOOK, failed to create Pod Desriptor File: " + str(e)
+
         try:
             JobFactory.makeCompleteJob(booking)
         except Exception as e: