Generic function to modify rows if write policy permits it
authorSapan Bhatia <sapanbhatia@boring3.CS.Princeton.EDU>
Tue, 27 Jul 2010 18:58:13 +0000 (14:58 -0400)
committerSapan Bhatia <sapanbhatia@boring3.CS.Princeton.EDU>
Tue, 27 Jul 2010 18:58:13 +0000 (14:58 -0400)
PLC/Table.py

index b811c62..86f60cb 100644 (file)
@@ -436,3 +436,16 @@ class Table(list):
             key_field = self.classobj.primary_key
 
         return dict([(obj[key_field], obj) for obj in self])
+
+    def update_rows(self, update_spec):
+        """
+        Dispatch requested change to individual rows, if write policy permits it
+        """
+        if (self.modify_ok(values)):
+            for row in self:
+                for update in update_spec:
+                    key = update['key']
+                    type = update['type']
+                    value = update['value']
+                    add_fn = row.add_object(type, key)
+                    add_fn(value)