hooks/bookmark.py
changeset 2841 107ba1c45227
child 2847 c2ee28f4d4b1
equal deleted inserted replaced
2840:06daf13195d4 2841:107ba1c45227
       
     1 """bookmark related hooks
       
     2 
       
     3 :organization: Logilab
       
     4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
       
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
       
     7 """
       
     8 __docformat__ = "restructuredtext en"
       
     9 
       
    10 from cubicweb.selectors import entity_implements
       
    11 from cubicweb.server import hook
       
    12 
       
    13 
       
    14 class AutoDeleteBookmarkOp(hook.Operation):
       
    15     bookmark = None # make pylint happy
       
    16     def precommit_event(self):
       
    17         if not self.session.deleted_in_transaction(self.bookmark.eid):
       
    18             if not self.bookmark.bookmarked_by:
       
    19                 self.bookmark.delete()
       
    20 
       
    21 
       
    22 class DelBookmarkedByHook(hook.Hook):
       
    23     """ensure user logins are stripped"""
       
    24     __id__ = 'autodelbookmark'
       
    25     __select__ = hook.Hook.__select__ & entity_implements('bookmarked_by',)
       
    26     category = 'bookmark'
       
    27     events = ('after_delete_relation',)
       
    28 
       
    29     def __call__(self):
       
    30         AutoDeleteBookmarkOp(self.cw_req,
       
    31                              bookmark=self.cw_req.entity_from_eid(self.eidfrom))