server/hook.py
changeset 4845 dc351b96f596
parent 4835 13b0b96d7982
parent 4838 d4187a08ccdf
child 5019 72734c210836
equal deleted inserted replaced
4844:ad78b118b124 4845:dc351b96f596
    93                     for hook in hooks:
    93                     for hook in hooks:
    94                         hook()
    94                         hook()
    95 
    95 
    96 VRegistry.REGISTRY_FACTORY['hooks'] = HooksRegistry
    96 VRegistry.REGISTRY_FACTORY['hooks'] = HooksRegistry
    97 
    97 
    98 
    98 _MARKER = object()
    99 def entity_oldnewvalue(entity, attr):
    99 def entity_oldnewvalue(entity, attr):
   100     """returns the couple (old attr value, new attr value)
   100     """returns the couple (old attr value, new attr value)
   101     NOTE: will only work in a before_update_entity hook
   101     NOTE: will only work in a before_update_entity hook
   102     """
   102     """
   103     # get new value and remove from local dict to force a db query to
   103     # get new value and remove from local dict to force a db query to
   104     # fetch old value
   104     # fetch old value
   105     newvalue = entity.pop(attr, None)
   105     newvalue = entity.pop(attr, _MARKER)
   106     oldvalue = getattr(entity, attr)
   106     oldvalue = getattr(entity, attr)
   107     if newvalue is not None:
   107     if newvalue is not _MARKER:
   108         entity[attr] = newvalue
   108         entity[attr] = newvalue
   109     return oldvalue, newvalue
   109     return oldvalue, newvalue
   110 
   110 
   111 
   111 
   112 # some hook specific selectors #################################################
   112 # some hook specific selectors #################################################