--- a/sobjects/hooks.py Fri Jul 24 17:50:41 2009 +0200
+++ b/sobjects/hooks.py Fri Jul 24 17:59:49 2009 +0200
@@ -12,6 +12,24 @@
from cubicweb.server.pool import PreCommitOperation
+class SetModificationDateOnStateChange(hooksmanager.Hook):
+ """update entity's modification date after changing its state"""
+ events = ('after_add_relation',)
+ accepts = ('in_state',)
+
+ def call(self, session, fromeid, rtype, toeid):
+ if fromeid in session.transaction_data.get('neweids', ()):
+ # new entity, not needed
+ return
+ entity = session.entity_from_eid(fromeid)
+ try:
+ entity.set_attributes(modification_date=datetime.now())
+ except RepositoryError, ex:
+ # usually occurs if entity is coming from a read-only source
+ # (eg ldap user)
+ self.warning('cant change modification date for %s: %s', entity, ex)
+
+
class AddUpdateCWUserHook(Hook):
"""ensure user logins are stripped"""
events = ('before_add_entity', 'before_update_entity',)