app/soc/logic/models/base.py
changeset 1518 f6f43a1675eb
parent 1517 a467d13e34ea
child 1549 bd07b231fe39
equal deleted inserted replaced
1517:a467d13e34ea 1518:f6f43a1675eb
   381     entity = self.getFromKeyName(key_name)
   381     entity = self.getFromKeyName(key_name)
   382 
   382 
   383     create_entity = not entity
   383     create_entity = not entity
   384 
   384 
   385     if create_entity:
   385     if create_entity:
       
   386       for property_name in properties:
       
   387         self._createField(properties, property_name)
       
   388 
   386       # entity did not exist, so create one in a transaction
   389       # entity did not exist, so create one in a transaction
   387       entity = self._model.get_or_insert(key_name, **properties)
   390       entity = self._model.get_or_insert(key_name, **properties)
   388     else:
   391     else:
   389       # If someone else already created the entity (due to a race), we
   392       # If someone else already created the entity (due to a race), we
   390       # should not update the propties (as they 'won' the race).
   393       # should not update the propties (as they 'won' the race).
   417 
   420 
   418     entity.delete()
   421     entity.delete()
   419     # entity has been deleted call _onDelete
   422     # entity has been deleted call _onDelete
   420     self._onDelete(entity)
   423     self._onDelete(entity)
   421 
   424 
       
   425   def _createField(self, entity_properties, name):
       
   426     """Hook called when a field is created.
       
   427 
       
   428     To be exact, this method is called for each field (that has a value
       
   429     specified) on an entity that is being created.
       
   430 
       
   431     Base classes should override if any special actions need to be
       
   432     taken when a field is updated.
       
   433 
       
   434     Args:
       
   435       name: the name of the field to be created
       
   436       value: the value
       
   437     """
       
   438 
       
   439     if not entity_properties or (name not in entity_properties):
       
   440       raise InvalidArgumentError
       
   441 
   422   def _updateField(self, entity, entity_properties, name):
   442   def _updateField(self, entity, entity_properties, name):
   423     """Hook called when a field is updated.
   443     """Hook called when a field is updated.
   424 
   444 
   425     Base classes should override if any special actions need to be
   445     Base classes should override if any special actions need to be
   426     taken when a field is updated. The field is not updated if the
   446     taken when a field is updated. The field is not updated if the