Add a _createField hook
authorSverre Rabbelier <srabbelier@gmail.com>
Thu, 26 Feb 2009 16:53:05 +0000
changeset 1518 f6f43a1675eb
parent 1517 a467d13e34ea
child 1519 eb70b27696de
Add a _createField hook Patch by: Sverre Rabbelier
app/soc/logic/models/base.py
--- a/app/soc/logic/models/base.py	Thu Feb 26 16:52:29 2009 +0000
+++ b/app/soc/logic/models/base.py	Thu Feb 26 16:53:05 2009 +0000
@@ -383,6 +383,9 @@
     create_entity = not entity
 
     if create_entity:
+      for property_name in properties:
+        self._createField(properties, property_name)
+
       # entity did not exist, so create one in a transaction
       entity = self._model.get_or_insert(key_name, **properties)
     else:
@@ -419,6 +422,23 @@
     # entity has been deleted call _onDelete
     self._onDelete(entity)
 
+  def _createField(self, entity_properties, name):
+    """Hook called when a field is created.
+
+    To be exact, this method is called for each field (that has a value
+    specified) on an entity that is being created.
+
+    Base classes should override if any special actions need to be
+    taken when a field is updated.
+
+    Args:
+      name: the name of the field to be created
+      value: the value
+    """
+
+    if not entity_properties or (name not in entity_properties):
+      raise InvalidArgumentError
+
   def _updateField(self, entity, entity_properties, name):
     """Hook called when a field is updated.