server/hook.py
branchstable
changeset 5744 6b2a987370e8
parent 5538 752bc67064f2
child 5837 67c722b36f7c
equal deleted inserted replaced
5741:bbef88618fbb 5744:6b2a987370e8
   120     VRegistry.REGISTRY_FACTORY['%s_hooks' % event] = HooksRegistry
   120     VRegistry.REGISTRY_FACTORY['%s_hooks' % event] = HooksRegistry
   121 
   121 
   122 _MARKER = object()
   122 _MARKER = object()
   123 def entity_oldnewvalue(entity, attr):
   123 def entity_oldnewvalue(entity, attr):
   124     """returns the couple (old attr value, new attr value)
   124     """returns the couple (old attr value, new attr value)
       
   125 
   125     NOTE: will only work in a before_update_entity hook
   126     NOTE: will only work in a before_update_entity hook
   126     """
   127     """
   127     # get new value and remove from local dict to force a db query to
   128     # get new value and remove from local dict to force a db query to
   128     # fetch old value
   129     # fetch old value
   129     newvalue = entity.pop(attr, _MARKER)
   130     newvalue = entity.pop(attr, _MARKER)
   130     oldvalue = getattr(entity, attr)
   131     oldvalue = getattr(entity, attr)
   131     if newvalue is not _MARKER:
   132     if newvalue is not _MARKER:
   132         entity[attr] = newvalue
   133         entity[attr] = newvalue
       
   134     else:
       
   135         newvalue = oldvalue
   133     return oldvalue, newvalue
   136     return oldvalue, newvalue
   134 
   137 
   135 
   138 
   136 # some hook specific selectors #################################################
   139 # some hook specific selectors #################################################
   137 
   140