diff mbox

[Branch,~linaro-validation/lava-dashboard/trunk] Rev 332: make the bundle page robust against the bundle not existing on disk

Message ID 20120827143411.7595.84118.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Michael-Doyle Hudson Aug. 27, 2012, 2:34 p.m. UTC
------------------------------------------------------------
revno: 332
committer: Michael Hudson-Doyle <michael.hudson@linaro.org>
branch nick: missing-bundles-working-page
timestamp: Mon 2012-08-27 12:31:59 +1200
message:
  make the bundle page robust against the bundle not existing on disk
modified:
  dashboard_app/models.py
  dashboard_app/templates/dashboard_app/bundle_detail.html


--
lp:lava-dashboard
https://code.launchpad.net/~linaro-validation/lava-dashboard/trunk

You are subscribed to branch lp:lava-dashboard.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-dashboard/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'dashboard_app/models.py'
--- dashboard_app/models.py	2012-08-05 22:25:32 +0000
+++ dashboard_app/models.py	2012-08-27 00:31:59 +0000
@@ -43,6 +43,7 @@ 
 from django.db.models.signals import post_delete
 from django.dispatch import receiver
 from django.template import Template, Context
+from django.template.defaultfilters import filesizeformat
 from django.utils.translation import ugettext as _
 from django.utils.translation import ungettext
 
@@ -543,16 +544,26 @@ 
             self.content.close()
 
     def get_document_format(self):
-        self.content.open('rb')
         try:
-            fmt, doc = DocumentIO.load(self.content)
-            return fmt
-        finally:
-            self.content.close()
+            self.content.open('rb')
+        except IOError:
+            return "unknown"
+        else:
+            try:
+                fmt, doc = DocumentIO.load(self.content)
+                return fmt
+            finally:
+                self.content.close()
 
     def get_serialization_format(self):
         return "JSON"
 
+    def get_content_size(self):
+        try:
+            return filesizeformat(self.content.size)
+        except OSError:
+            return "unknown"
+
 
 class SanitizedBundle(object):
 

=== modified file 'dashboard_app/templates/dashboard_app/bundle_detail.html'
--- dashboard_app/templates/dashboard_app/bundle_detail.html	2012-06-25 02:17:16 +0000
+++ dashboard_app/templates/dashboard_app/bundle_detail.html	2012-08-27 00:31:59 +0000
@@ -44,7 +44,7 @@ 
   <dt>Content SHA1:</dt>
   <dd>{{ bundle.content_sha1 }}</dd>
   <dt>Content size:</dt>
-  <dd>{{ bundle.content.size|filesizeformat }}</dd>
+  <dd>{{ bundle.get_content_size }}</dd>
 </dl>
 
 <h3>Storage and format</h3>