[iprogress] None resilience stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 14 Oct 2010 16:57:56 +0200
branchstable
changeset 6496 21bbb561809b
parent 6495 3187112bc7cc
child 6501 fc71e75c410d
[iprogress] None resilience
web/views/iprogress.py
--- a/web/views/iprogress.py	Wed Oct 13 18:54:59 2010 +0200
+++ b/web/views/iprogress.py	Thu Oct 14 16:57:56 2010 +0200
@@ -178,8 +178,11 @@
     @classmethod
     def overrun(cls, iprogress):
         """overrun = done + todo - """
-        if iprogress.done + iprogress.todo > iprogress.revised_cost:
-            overrun = iprogress.done + iprogress.todo - iprogress.revised_cost
+        done = iprogress.done or 0
+        todo = iprogress.todo or 0
+        revised_cost = iprogress.revised_cost or 0
+        if done + todo > revised_cost:
+            overrun = done + todo - revised_cost
         else:
             overrun = 0
         if overrun < cls.precision:
@@ -189,19 +192,19 @@
     @classmethod
     def overrun_percentage(cls, iprogress):
         """pourcentage overrun = overrun / budget"""
-        if iprogress.revised_cost == 0:
+        revised_cost = iprogress.revised_cost or 0
+        if revised_cost == 0:
             return 0
-        else:
-            return cls.overrun(iprogress) * 100. / iprogress.revised_cost
+        return cls.overrun(iprogress) * 100. / revised_cost
 
     def cell_call(self, row, col):
         self._cw.add_css('cubicweb.iprogress.css')
         self._cw.add_js('cubicweb.iprogress.js')
         entity = self.cw_rset.get_entity(row, col)
         iprogress = entity.cw_adapt_to('IProgress')
-        done = iprogress.done
-        todo = iprogress.todo
-        budget = iprogress.revised_cost
+        done = iprogress.done or 0
+        todo = iprogress.todo or 0
+        budget = iprogress.revised_cost or 0
         if budget == 0:
             pourcent = 100
         else: