hooks/notification.py
author Rémi Cardona <remi.cardona@logilab.fr>
Fri, 26 Jun 2015 16:29:28 +0200
changeset 10467 73ea636a5562
parent 10351 91e63306e277
child 11084 ffd615e626f9
permissions -rw-r--r--
[entity] sort fetchattrs when generating rql Try to generate a predictable rql query, to help testing with PYTHONHASHSEED=random.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10351
91e63306e277 [connection] replace .running_dbapi_query with .hooks_in_progress
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9632
diff changeset
     1
# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4993
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4993
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4993
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4993
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4993
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4993
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4993
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4993
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4993
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4993
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4993
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4993
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4993
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4993
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4993
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
7068
90ddf608fe2b backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6760
diff changeset
    18
"""some hooks to handle notification on entity's changes"""
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
__docformat__ = "restructuredtext en"
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
from logilab.common.textutils import normalize_text
8898
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    23
from logilab.common.deprecation import deprecated
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
6760
2c1fc68ac258 handle the fact that there might be no views registered in some configurations (#1382716)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6466
diff changeset
    25
from cubicweb import RegistryNotFound
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7879
diff changeset
    26
from cubicweb.predicates import is_instance
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
from cubicweb.server import hook
3427
78dfef45ee48 [notification] add missing import, fix dummy AttributeError in RenderAndSendNotificationView
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3422
diff changeset
    28
from cubicweb.sobjects.supervising import SupervisionMailOp
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
8898
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    30
8928
f5b40b66d36e [notification] introduce an official `notify_on_commit` function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8900
diff changeset
    31
@deprecated('[3.17] use notify_on_commit instead')
9618
1b8552265f3b [hooks/notification] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents: 9267
diff changeset
    32
def RenderAndSendNotificationView(cnx, view, viewargs=None):
1b8552265f3b [hooks/notification] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents: 9267
diff changeset
    33
    notify_on_commit(cnx, view, viewargs)
8928
f5b40b66d36e [notification] introduce an official `notify_on_commit` function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8900
diff changeset
    34
f5b40b66d36e [notification] introduce an official `notify_on_commit` function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8900
diff changeset
    35
9618
1b8552265f3b [hooks/notification] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents: 9267
diff changeset
    36
def notify_on_commit(cnx, view, viewargs=None):
8928
f5b40b66d36e [notification] introduce an official `notify_on_commit` function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8900
diff changeset
    37
    """register a notification view (see
f5b40b66d36e [notification] introduce an official `notify_on_commit` function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8900
diff changeset
    38
    :class:`~cubicweb.sobjects.notification.NotificationView`) to be sent at
f5b40b66d36e [notification] introduce an official `notify_on_commit` function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8900
diff changeset
    39
    post-commit time, ie only if the transaction has succeeded.
f5b40b66d36e [notification] introduce an official `notify_on_commit` function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8900
diff changeset
    40
f5b40b66d36e [notification] introduce an official `notify_on_commit` function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8900
diff changeset
    41
    `viewargs` is an optional dictionary containing extra argument to be given
f5b40b66d36e [notification] introduce an official `notify_on_commit` function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8900
diff changeset
    42
    to :meth:`~cubicweb.sobjects.notification.NotificationView.render_and_send`
f5b40b66d36e [notification] introduce an official `notify_on_commit` function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8900
diff changeset
    43
    """
8898
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    44
    if viewargs is None:
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    45
        viewargs = {}
9618
1b8552265f3b [hooks/notification] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents: 9267
diff changeset
    46
    notif_op = _RenderAndSendNotificationOp.get_instance(cnx)
8898
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    47
    notif_op.add_data((view, viewargs))
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    48
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    49
8928
f5b40b66d36e [notification] introduce an official `notify_on_commit` function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8900
diff changeset
    50
class _RenderAndSendNotificationOp(hook.DataOperationMixIn, hook.Operation):
8898
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    51
    """End of the notification chain. Do render and send views after commit
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    52
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    53
    All others Operations end up adding data to this Operation.
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    54
    The notification are done on ``postcommit_event`` to make sure to prevent
9267
24d9b86dfa54 spelling: rollbacked -> rolled back
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9006
diff changeset
    55
    sending notification about rolled back data.
8898
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    56
    """
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    57
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    58
    containercls = list
7879
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7815
diff changeset
    59
8227
884405bf3621 [email notifications] send notification at post-commit time (closes #2119248)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents: 7879
diff changeset
    60
    def postcommit_event(self):
9618
1b8552265f3b [hooks/notification] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents: 9267
diff changeset
    61
        deleted = self.cnx.deleted_in_transaction
8898
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    62
        for view, viewargs in self.get_data():
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    63
            if view.cw_rset is not None:
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    64
                if not view.cw_rset:
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    65
                    # entity added and deleted in the same transaction
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    66
                    # (cache effect)
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    67
                    continue
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    68
                elif deleted(view.cw_rset[view.cw_row or 0][view.cw_col or 0]):
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    69
                    # entity added and deleted in the same transaction
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    70
                    continue
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    71
            try:
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    72
                view.render_and_send(**viewargs)
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    73
            except Exception:
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    74
                # error in post commit are not propagated
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    75
                # We keep this logic here to prevent a small notification error
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    76
                # to prevent them all.
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
    77
                self.exception('Notification failed')
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    78
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    79
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    80
class NotificationHook(hook.Hook):
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    81
    __abstract__ = True
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    82
    category = 'notification'
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    83
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    84
    def select_view(self, vid, rset, row=0, col=0):
6760
2c1fc68ac258 handle the fact that there might be no views registered in some configurations (#1382716)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6466
diff changeset
    85
        try:
2c1fc68ac258 handle the fact that there might be no views registered in some configurations (#1382716)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6466
diff changeset
    86
            return self._cw.vreg['views'].select_or_none(vid, self._cw, rset=rset,
2c1fc68ac258 handle the fact that there might be no views registered in some configurations (#1382716)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6466
diff changeset
    87
                                                         row=row, col=col)
2c1fc68ac258 handle the fact that there might be no views registered in some configurations (#1382716)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6466
diff changeset
    88
        except RegistryNotFound: # can happen in some config
2c1fc68ac258 handle the fact that there might be no views registered in some configurations (#1382716)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6466
diff changeset
    89
                                 # (e.g. repo only config with no
2c1fc68ac258 handle the fact that there might be no views registered in some configurations (#1382716)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6466
diff changeset
    90
                                 # notification views registered by
2c1fc68ac258 handle the fact that there might be no views registered in some configurations (#1382716)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6466
diff changeset
    91
                                 # the instance's cubes)
2c1fc68ac258 handle the fact that there might be no views registered in some configurations (#1382716)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6466
diff changeset
    92
            return None
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    93
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    94
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    95
class StatusChangeHook(NotificationHook):
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    96
    """notify when a workflowable entity has its state modified"""
3376
f5c69485381f [appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3163
diff changeset
    97
    __regid__ = 'notifystatuschange'
5877
0c7b7b76a84f [selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5693
diff changeset
    98
    __select__ = NotificationHook.__select__ & is_instance('TrInfo')
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    99
    events = ('after_add_entity',)
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   100
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   101
    def __call__(self):
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   102
        entity = self.entity
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   103
        if not entity.from_state: # not a transition
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   104
            return
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   105
        rset = entity.related('wf_info_for')
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   106
        view = self.select_view('notif_status_change', rset=rset, row=0)
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   107
        if view is None:
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   108
            return
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   109
        comment = entity.printable_value('comment', format='text/plain')
3023
7864fee8b4ec backport 3.5 step 1, remaining wf changes in hooks to merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2900
diff changeset
   110
        # XXX don't try to wrap rest until we've a proper transformation (see
7864fee8b4ec backport 3.5 step 1, remaining wf changes in hooks to merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2900
diff changeset
   111
        # #103822)
7864fee8b4ec backport 3.5 step 1, remaining wf changes in hooks to merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2900
diff changeset
   112
        if comment and entity.comment_format != 'text/rest':
7864fee8b4ec backport 3.5 step 1, remaining wf changes in hooks to merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2900
diff changeset
   113
            comment = normalize_text(comment, 80)
8898
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
   114
        viewargs = {'comment': comment,
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
   115
                    'previous_state': entity.previous_state.name,
c570d15dce7b [notification] use new style operation for notification
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8896
diff changeset
   116
                    'current_state': entity.new_state.name}
8957
bf4003760e02 [notification] ensure official API is test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8956
diff changeset
   117
        notify_on_commit(self._cw, view, viewargs=viewargs)
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   118
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   119
class RelationChangeHook(NotificationHook):
3376
f5c69485381f [appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3163
diff changeset
   120
    __regid__ = 'notifyrelationchange'
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   121
    events = ('before_add_relation', 'after_add_relation',
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   122
              'before_delete_relation', 'after_delete_relation')
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   123
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   124
    def __call__(self):
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   125
        """if a notification view is defined for the event, send notification
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   126
        email defined by the view
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   127
        """
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2841
diff changeset
   128
        rset = self._cw.eid_rset(self.eidfrom)
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   129
        view = self.select_view('notif_%s_%s' % (self.event,  self.rtype),
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   130
                                rset=rset, row=0)
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   131
        if view is None:
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   132
            return
8957
bf4003760e02 [notification] ensure official API is test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8956
diff changeset
   133
        notify_on_commit(self._cw, view)
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   134
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   135
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   136
class EntityChangeHook(NotificationHook):
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   137
    """if a notification view is defined for the event, send notification
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   138
    email defined by the view
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   139
    """
3376
f5c69485381f [appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3163
diff changeset
   140
    __regid__ = 'notifyentitychange'
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   141
    events = ('after_add_entity', 'after_update_entity')
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   142
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   143
    def __call__(self):
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   144
        rset = self.entity.as_rset()
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   145
        view = self.select_view('notif_%s' % self.event, rset=rset, row=0)
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   146
        if view is None:
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   147
            return
8957
bf4003760e02 [notification] ensure official API is test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8956
diff changeset
   148
        notify_on_commit(self._cw, view)
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   149
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   150
3536
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   151
class EntityUpdatedNotificationOp(hook.SingleLastOperation):
8896
3e414a53e794 [notification] fix documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8236
diff changeset
   152
    """scrap all changed entity to prepare a Notification Operation for them"""
3536
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   153
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   154
    def precommit_event(self):
8896
3e414a53e794 [notification] fix documentation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8236
diff changeset
   155
        # precommit event that creates postcommit operation
9618
1b8552265f3b [hooks/notification] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents: 9267
diff changeset
   156
        cnx = self.cnx
1b8552265f3b [hooks/notification] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents: 9267
diff changeset
   157
        for eid in cnx.transaction_data['changes']:
1b8552265f3b [hooks/notification] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents: 9267
diff changeset
   158
            view = cnx.vreg['views'].select('notif_entity_updated', cnx,
9632
c60c8dec0e0e [hooks/notification] Fix indentation
Julien Cristau <julien.cristau@logilab.fr>
parents: 9618
diff changeset
   159
                                            rset=cnx.eid_rset(eid),
c60c8dec0e0e [hooks/notification] Fix indentation
Julien Cristau <julien.cristau@logilab.fr>
parents: 9618
diff changeset
   160
                                            row=0)
9618
1b8552265f3b [hooks/notification] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents: 9267
diff changeset
   161
            notify_on_commit(self.cnx, view,
1b8552265f3b [hooks/notification] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents: 9267
diff changeset
   162
                    viewargs={'changes': cnx.transaction_data['changes'][eid]})
3536
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   163
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   164
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   165
class EntityUpdateHook(NotificationHook):
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   166
    __regid__ = 'notifentityupdated'
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   167
    __abstract__ = True # do not register by default
10351
91e63306e277 [connection] replace .running_dbapi_query with .hooks_in_progress
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9632
diff changeset
   168
    __select__ = NotificationHook.__select__ & hook.issued_from_user_query()
3536
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   169
    events = ('before_update_entity',)
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   170
    skip_attrs = set()
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   171
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   172
    def __call__(self):
9618
1b8552265f3b [hooks/notification] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents: 9267
diff changeset
   173
        cnx = self._cw
1b8552265f3b [hooks/notification] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents: 9267
diff changeset
   174
        if cnx.added_in_transaction(self.entity.eid):
3536
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   175
            return # entity is being created
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   176
        # then compute changes
6142
8bc6eac1fac1 [session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   177
        attrs = [k for k in self.entity.cw_edited
4843
5f7363416765 fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4835
diff changeset
   178
                 if not k in self.skip_attrs]
3536
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   179
        if not attrs:
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   180
            return
9618
1b8552265f3b [hooks/notification] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents: 9267
diff changeset
   181
        changes = cnx.transaction_data.setdefault('changes', {})
4993
c9229f185690 [notification] don't create 'changes' in transaction data until actually needed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   182
        thisentitychanges = changes.setdefault(self.entity.eid, set())
3536
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   183
        rqlsel, rqlrestr = [], ['X eid %(x)s']
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   184
        for i, attr in enumerate(attrs):
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   185
            var = chr(65+i)
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   186
            rqlsel.append(var)
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   187
            rqlrestr.append('X %s %s' % (attr, var))
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   188
        rql = 'Any %s WHERE %s' % (','.join(rqlsel), ','.join(rqlrestr))
9618
1b8552265f3b [hooks/notification] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents: 9267
diff changeset
   189
        rset = cnx.execute(rql, {'x': self.entity.eid})
3536
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   190
        for i, attr in enumerate(attrs):
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   191
            oldvalue = rset[0][i]
6466
43d71dd8a8ec cleanup and 3.10 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6142
diff changeset
   192
            newvalue = self.entity.cw_edited[attr]
3536
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   193
            if oldvalue != newvalue:
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   194
                thisentitychanges.add((attr, oldvalue, newvalue))
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   195
        if thisentitychanges:
9618
1b8552265f3b [hooks/notification] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents: 9267
diff changeset
   196
            EntityUpdatedNotificationOp(cnx)
3536
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   197
f6c9a5df80fb backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3427
diff changeset
   198
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   199
# supervising ##################################################################
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   200
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   201
class SomethingChangedHook(NotificationHook):
3376
f5c69485381f [appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3163
diff changeset
   202
    __regid__ = 'supervising'
10351
91e63306e277 [connection] replace .running_dbapi_query with .hooks_in_progress
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9632
diff changeset
   203
    __select__ = NotificationHook.__select__ & hook.issued_from_user_query()
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   204
    events = ('before_add_relation', 'before_delete_relation',
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   205
              'after_add_entity', 'before_update_entity')
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   206
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   207
    def __call__(self):
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2841
diff changeset
   208
        dest = self._cw.vreg.config['supervising-addrs']
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   209
        if not dest: # no supervisors, don't do this for nothing...
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   210
            return
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   211
        if self._call():
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2841
diff changeset
   212
            SupervisionMailOp(self._cw)
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   213
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   214
    def _call(self):
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   215
        event = self.event.split('_', 1)[1]
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   216
        if event == 'update_entity':
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2841
diff changeset
   217
            if self._cw.added_in_transaction(self.entity.eid):
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   218
                return False
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   219
            if self.entity.e_schema == 'CWUser':
6142
8bc6eac1fac1 [session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   220
                if not (frozenset(self.entity.cw_edited)
8bc6eac1fac1 [session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   221
                        - frozenset(('eid', 'modification_date',
8bc6eac1fac1 [session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   222
                                     'last_login_time'))):
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   223
                    # don't record last_login_time update which are done
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   224
                    # automatically at login time
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   225
                    return False
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2841
diff changeset
   226
        self._cw.transaction_data.setdefault('pendingchanges', []).append(
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   227
            (event, self))
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   228
        return True
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   229
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   230
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   231
class EntityDeleteHook(SomethingChangedHook):
3376
f5c69485381f [appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3163
diff changeset
   232
    __regid__ = 'supervisingentitydel'
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   233
    events = ('before_delete_entity',)
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   234
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   235
    def _call(self):
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   236
        try:
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   237
            title = self.entity.dc_title()
7815
2a164a9cf81c [exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7068
diff changeset
   238
        except Exception:
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   239
            # may raise an error during deletion process, for instance due to
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   240
            # missing required relation
5693
8af6623f3d4e [pylint] fix detected name errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   241
            title = '#%s' % self.entity.eid
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2841
diff changeset
   242
        self._cw.transaction_data.setdefault('pendingchanges', []).append(
8900
010a59e12d89 use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8898
diff changeset
   243
            ('delete_entity', (self.entity.eid, self.entity.cw_etype, title)))
2841
107ba1c45227 rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   244
        return True