Argument store added to updateEntityProperties.
authorDaniel Hans <Daniel.M.Hans@gmail.com>
Fri, 07 Aug 2009 01:27:24 +0200
changeset 2736 8f3935f0f4ba
parent 2735 74f0972f523f
child 2737 5b43af491b93
Argument store added to updateEntityProperties. This argument determines if an entity should be stored in the data model after its properties are updated. It may be useful, for example, along with tasks (Task Queue API). One may want to make some modifications to an entity during execution of a task, but the developer is sure that at least one new task, which also wants to modify the entity, will be queued, so he or she can just update the entity without saving the changes to the data model, set the entity in memcache and the following task (which is to be executed very shortly) is to retrive the current entity from the memcache (without any expensive calls to the actual data model).
app/soc/logic/models/base.py
app/soc/logic/models/expando_base.py
--- a/app/soc/logic/models/base.py	Fri Aug 07 01:00:58 2009 +0200
+++ b/app/soc/logic/models/base.py	Fri Aug 07 01:27:24 2009 +0200
@@ -378,7 +378,8 @@
 
     return query
 
-  def updateEntityProperties(self, entity, entity_properties, silent=False):
+  def updateEntityProperties(self, entity, entity_properties, silent=False,
+                             store=True):
     """Update existing entity using supplied properties.
 
     Args:
@@ -386,6 +387,7 @@
       entity_properties: keyword arguments that correspond to entity
         properties and their values
       silent: iff True does not call _onUpdate method
+      store: iff True updated entity is actually stored in the data model
 
     Returns:
       The original entity with any supplied properties changed.
@@ -408,7 +410,8 @@
         value = entity_properties[name]
         prop.__set__(entity, value)
 
-    entity.put()
+    if store:
+      entity.put()
 
     # call the _onUpdate method
     if not silent:
--- a/app/soc/logic/models/expando_base.py	Fri Aug 07 01:00:58 2009 +0200
+++ b/app/soc/logic/models/expando_base.py	Fri Aug 07 01:27:24 2009 +0200
@@ -39,7 +39,8 @@
                                 skip_properties=skip_properties,
                                 id_based=id_based)
 
-  def updateEntityProperties(self, entity, entity_properties, silent=False):
+  def updateEntityProperties(self, entity, entity_properties, silent=False,
+                             store=True):
     """Update existing entity using supplied properties.
 
     Overwrites base because of Expando properties.
@@ -49,7 +50,8 @@
       entity_properties: keyword arguments that correspond to entity
         properties and their values
       silent: iff True does not call _onUpdate method
-
+      store: iff True updated entity is actually stored in the data model 
+      
     Returns:
       The original entity with any supplied properties changed.
     """
@@ -68,7 +70,8 @@
       if self._updateField(entity, entity_properties, name):
         setattr(entity, name, value)
 
-    entity.put()
+    if store:
+      entity.put()
 
     # call the _onUpdate method
     if not silent: