84 else: |
84 else: |
85 warn('[3.6] %s: enabled is deprecated' % hook.__class__) |
85 warn('[3.6] %s: enabled is deprecated' % hook.__class__) |
86 |
86 |
87 VRegistry.REGISTRY_FACTORY['hooks'] = HooksRegistry |
87 VRegistry.REGISTRY_FACTORY['hooks'] = HooksRegistry |
88 |
88 |
89 |
89 _MARKER = object() |
90 def entity_oldnewvalue(entity, attr): |
90 def entity_oldnewvalue(entity, attr): |
91 """returns the couple (old attr value, new attr value) |
91 """returns the couple (old attr value, new attr value) |
92 NOTE: will only work in a before_update_entity hook |
92 NOTE: will only work in a before_update_entity hook |
93 """ |
93 """ |
94 # get new value and remove from local dict to force a db query to |
94 # get new value and remove from local dict to force a db query to |
95 # fetch old value |
95 # fetch old value |
96 newvalue = entity.pop(attr, None) |
96 newvalue = entity.pop(attr, _MARKER) |
97 oldvalue = getattr(entity, attr) |
97 oldvalue = getattr(entity, attr) |
98 if newvalue is not None: |
98 if newvalue is not _MARKER: |
99 entity[attr] = newvalue |
99 entity[attr] = newvalue |
100 return oldvalue, newvalue |
100 return oldvalue, newvalue |
101 |
101 |
102 |
102 |
103 # some hook specific selectors ################################################# |
103 # some hook specific selectors ################################################# |