Source

flowrate / flowrate / flows.py

Diff from to

flowrate/flows.py

 
 class Flow(object):
 
-    def __init__(self, id):
+    def __init__(self, id, row=None):
         self.id = id
-        self.row = None
+        self.row = row
 
     def find(self):
         """Set self.row to a DB row matching the given ID, or None."""
         refs = set()
         finder = ReferenceFinder()
         for key in ('start', 'end', 'amount'):
-            val = vals[key].strip()
+            val = vals[key]
+            if not isinstance(val, basestring):
+                # Allow 'amount' entries to be numbers
+                val = str(val)
+            val = val.strip()
             if val.startswith("="):
                 newrefs = finder.find(val[1:])
                 refs.update(newrefs)
         elif self.unit == 'years':
             unit, day = lambda d: d.year, lambda d: d.timetuple().tm_yday
 
-        escrow = datetime.date(2014, 2, 1)
-
         start = self.range_start.strip()
         if start.startswith("="):
             # It's a Python expression
-            start = eval(start[1:], env, locals())
+            start = env.eval(start[1:], locals())
         else:
             # Assume it's an ISO date YYYY-MM-DD
             start = datetime.date(*map(int, start.split("-")))
         end = self.range_end.strip()
         if end.startswith("="):
             # It's a Python expression
-            end = eval(end[1:], env, locals())
+            end = env.eval(end[1:], locals())
         else:
             # Assume it's an ISO date YYYY-MM-DD
             end = datetime.date(*map(int, end.split("-")))
                 amount = self.amount.strip()
                 if amount.startswith("="):
                     # It's a Python expression
-                    amount = eval(amount[1:], env, locals())
+                    amount = env.eval(amount[1:], locals())
                 else:
                     # Assume it's a number
                     amount = decimal.Decimal(amount)
 
         obs = {}
         for ob in self.obligations():
-            print ob
             # TODO: this is slow. Can we change it to an "INSERT INTO ... FROM"?
             row = flowrate.db.execute(
                 "INSERT INTO obligations "