server/hook.py
changeset 4011 394f853bb653
parent 4008 fce83937a885
child 4025 de69adda0781
--- a/server/hook.py	Mon Dec 07 17:57:19 2009 +0100
+++ b/server/hook.py	Mon Dec 07 19:14:49 2009 +0100
@@ -87,6 +87,19 @@
 VRegistry.REGISTRY_FACTORY['hooks'] = HooksRegistry
 
 
+def entity_oldnewvalue(entity, attr):
+    """returns the couple (old attr value, new attr value)
+    NOTE: will only work in a before_update_entity hook
+    """
+    # get new value and remove from local dict to force a db query to
+    # fetch old value
+    newvalue = entity.pop(attr, None)
+    oldvalue = getattr(entity, attr)
+    if newvalue is not None:
+        entity[attr] = newvalue
+    return oldvalue, newvalue
+
+
 # some hook specific selectors #################################################
 
 @objectify_selector