Prevent modification of key fields
authorSverre Rabbelier <srabbelier@gmail.com>
Tue, 22 Sep 2009 13:07:27 +0200
changeset 2968 7ba28890eb75
parent 2967 676c0ca67e21
child 2969 d0914c76ecc3
Prevent modification of key fields Only non-id-based entities are affected as id-based entities do not have any un-modificable fields.
app/soc/logic/models/base.py
--- a/app/soc/logic/models/base.py	Tue Sep 22 13:15:33 2009 +0200
+++ b/app/soc/logic/models/base.py	Tue Sep 22 13:07:27 2009 +0200
@@ -87,6 +87,21 @@
     else:
       self._skip_properties = []
 
+  def skipField(self, name):
+    """Returns whether a field with the specified name should be saved.
+    """
+
+    if name in self._skip_properties:
+      return True
+
+    if self._id_based:
+      return False
+
+    if name in self.getKeyFieldNames():
+      return True
+
+    return False
+
   def getModel(self):
     """Returns the model this logic class uses.
     """
@@ -453,7 +468,7 @@
 
     for name, prop in properties.iteritems():
       # if the property is not updateable or is not updated, skip it
-      if name in self._skip_properties or (name not in entity_properties):
+      if self.skipField(name) or (name not in entity_properties):
         continue
 
       if self._updateField(entity, entity_properties, name):