sobjects/hooks.py
branchtls-sprint
changeset 1802 d628defebc17
parent 1398 5fe84a5f7035
child 1977 606923dff11b
equal deleted inserted replaced
1801:672acc730ce5 1802:d628defebc17
    13 
    13 
    14 class AddUpdateCWUserHook(Hook):
    14 class AddUpdateCWUserHook(Hook):
    15     """ensure user logins are stripped"""
    15     """ensure user logins are stripped"""
    16     events = ('before_add_entity', 'before_update_entity',)
    16     events = ('before_add_entity', 'before_update_entity',)
    17     accepts = ('CWUser',)
    17     accepts = ('CWUser',)
    18     
    18 
    19     def call(self, session, entity):
    19     def call(self, session, entity):
    20         if 'login' in entity and entity['login']:
    20         if 'login' in entity and entity['login']:
    21             entity['login'] = entity['login'].strip()
    21             entity['login'] = entity['login'].strip()
    22 
    22 
    23 
    23 
    28         if not self.beid in session.query_data('pendingeids', ()):
    28         if not self.beid in session.query_data('pendingeids', ()):
    29             if not session.unsafe_execute('Any X WHERE X bookmarked_by U, X eid %(x)s',
    29             if not session.unsafe_execute('Any X WHERE X bookmarked_by U, X eid %(x)s',
    30                                           {'x': self.beid}, 'x'):
    30                                           {'x': self.beid}, 'x'):
    31                 session.unsafe_execute('DELETE Bookmark X WHERE X eid %(x)s',
    31                 session.unsafe_execute('DELETE Bookmark X WHERE X eid %(x)s',
    32                                        {'x': self.beid}, 'x')
    32                                        {'x': self.beid}, 'x')
    33         
    33 
    34 class DelBookmarkedByHook(Hook):
    34 class DelBookmarkedByHook(Hook):
    35     """ensure user logins are stripped"""
    35     """ensure user logins are stripped"""
    36     events = ('after_delete_relation',)
    36     events = ('after_delete_relation',)
    37     accepts = ('bookmarked_by',)
    37     accepts = ('bookmarked_by',)
    38     
    38 
    39     def call(self, session, subj, rtype, obj):
    39     def call(self, session, subj, rtype, obj):
    40         AutoDeleteBookmark(session, beid=subj)
    40         AutoDeleteBookmark(session, beid=subj)
    41 
    41 
    42 
    42 
    43 class TidyHtmlFields(Hook):
    43 class TidyHtmlFields(Hook):
    58                         fmt = entity.get(metaattr)
    58                         fmt = entity.get(metaattr)
    59                     else:
    59                     else:
    60                         fmt = entity.get_value(metaattr)
    60                         fmt = entity.get_value(metaattr)
    61                     if fmt == 'text/html':
    61                     if fmt == 'text/html':
    62                         entity[attr] = soup2xhtml(value, session.encoding)
    62                         entity[attr] = soup2xhtml(value, session.encoding)
    63