author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 30 Sep 2009 18:57:42 +0200 | |
changeset 3536 | f6c9a5df80fb |
parent 3418 | 7b49fa7e942d |
parent 3525 | 2dc3908f667f |
child 3589 | a5432f99f2d9 |
permissions | -rw-r--r-- |
2841
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2818
diff
changeset
|
1 |
"""some views to handle notification on data changes |
0 | 2 |
|
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1723
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1723
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
2101
08003e0354a7
update transaction data api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
9 |
_ = unicode |
0 | 10 |
|
11 |
from itertools import repeat |
|
12 |
||
13 |
from logilab.common.textutils import normalize_text |
|
2879
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
14 |
from logilab.common.deprecation import class_renamed, deprecated |
0 | 15 |
|
2841
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2818
diff
changeset
|
16 |
from cubicweb.selectors import yes |
2879
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
17 |
from cubicweb.view import Component |
0 | 18 |
from cubicweb.common.mail import format_mail |
2880 | 19 |
from cubicweb.common.mail import NotificationView |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
20 |
from cubicweb.server.hook import SendMailOp |
0 | 21 |
|
3051 | 22 |
parse_message_id = deprecated('parse_message_id is now defined in cubicweb.common.mail')(parse_message_id) |
2879
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
23 |
|
0 | 24 |
|
25 |
class RecipientsFinder(Component): |
|
26 |
"""this component is responsible to find recipients of a notification |
|
27 |
||
28 |
by default user's with their email set are notified if any, else the default |
|
29 |
email addresses specified in the configuration are used |
|
30 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
31 |
__regid__ = 'recipients_finder' |
781
323656dd85a9
fix import, use non_final_entity instead of implements('Any')
sylvain.thenault@logilab.fr
parents:
761
diff
changeset
|
32 |
__select__ = yes() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
33 |
user_rql = ('Any X,E,A WHERE X is CWUser, X in_state S, S name "activated",' |
0 | 34 |
'X primary_email E, E address A') |
1477 | 35 |
|
0 | 36 |
def recipients(self): |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
37 |
mode = self._cw.vreg.config['default-recipients-mode'] |
0 | 38 |
if mode == 'users': |
39 |
# use unsafe execute else we may don't have the right to see users |
|
40 |
# to notify... |
|
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
41 |
execute = self._cw.unsafe_execute |
0 | 42 |
dests = [(u.get_email(), u.property_value('ui.language')) |
43 |
for u in execute(self.user_rql, build_descr=True, propagate=True).entities()] |
|
44 |
elif mode == 'default-dest-addrs': |
|
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
45 |
lang = self._cw.vreg.property_value('ui.language') |
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
46 |
dests = zip(self._cw.vreg.config['default-dest-addrs'], repeat(lang)) |
0 | 47 |
else: # mode == 'none' |
48 |
dests = [] |
|
49 |
return dests |
|
50 |
||
1477 | 51 |
|
0 | 52 |
# abstract or deactivated notification views and mixin ######################## |
53 |
||
2879
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
54 |
class NotificationView(NotificationView): |
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
55 |
"""overriden to delay actual sending of mails to a commit operation by |
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
56 |
default |
0 | 57 |
""" |
2879
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
58 |
def send_on_commit(self, recipients, msg): |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
59 |
SendMailOp(self._cw, recipients=recipients, msg=msg) |
2879
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
60 |
send = send_on_commit |
0 | 61 |
|
62 |
||
63 |
class StatusChangeMixIn(object): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
64 |
__regid__ = 'notif_status_change' |
0 | 65 |
msgid_timestamp = True |
66 |
message = _('status changed') |
|
67 |
content = _(""" |
|
68 |
%(user)s changed status from <%(previous_state)s> to <%(current_state)s> for entity |
|
69 |
'%(title)s' |
|
70 |
||
71 |
%(comment)s |
|
72 |
||
73 |
url: %(url)s |
|
74 |
""") |
|
75 |
||
76 |
||
738
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
77 |
############################################################################### |
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
78 |
# Actual notification views. # |
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
79 |
# # |
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
80 |
# disable them at the recipients_finder level if you don't want them # |
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
81 |
############################################################################### |
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
82 |
|
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
83 |
# XXX should be based on dc_title/dc_description, no? |
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
84 |
|
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
85 |
class ContentAddedView(NotificationView): |
2879
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
86 |
"""abstract class for notification on entity/relation |
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
87 |
|
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
88 |
all you have to do by default is : |
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
89 |
* set id and __select__ attributes to match desired events and entity types |
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
90 |
* set a content attribute to define the content of the email (unless you |
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
91 |
override call) |
ae26a80c0635
move base NotificationView to cw.common.mail, we may want to use it to send notification from the web ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
92 |
""" |
738
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
93 |
__abstract__ = True |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
94 |
__regid__ = 'notif_after_add_entity' |
0 | 95 |
msgid_timestamp = False |
96 |
message = _('new') |
|
97 |
content = """ |
|
98 |
%(title)s |
|
99 |
||
100 |
%(content)s |
|
101 |
||
102 |
url: %(url)s |
|
103 |
""" |
|
104 |
||
105 |
def context(self, **kwargs): |
|
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
106 |
entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
0 | 107 |
content = entity.printable_value(self.content_attr, format='text/plain') |
108 |
if content: |
|
3004
09ab5e93a02c
[notification] fix #103822, don't try to wrap text/rest to 80 characters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2879
diff
changeset
|
109 |
contentformat = getattr(entity, self.content_attr + '_format', |
09ab5e93a02c
[notification] fix #103822, don't try to wrap text/rest to 80 characters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2879
diff
changeset
|
110 |
'text/rest') |
09ab5e93a02c
[notification] fix #103822, don't try to wrap text/rest to 80 characters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2879
diff
changeset
|
111 |
# XXX don't try to wrap rest until we've a proper transformation (see |
09ab5e93a02c
[notification] fix #103822, don't try to wrap text/rest to 80 characters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2879
diff
changeset
|
112 |
# #103822) |
09ab5e93a02c
[notification] fix #103822, don't try to wrap text/rest to 80 characters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2879
diff
changeset
|
113 |
if contentformat != 'text/rest': |
09ab5e93a02c
[notification] fix #103822, don't try to wrap text/rest to 80 characters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2879
diff
changeset
|
114 |
content = normalize_text(content, 80) |
761 | 115 |
return super(ContentAddedView, self).context(content=content, **kwargs) |
1477 | 116 |
|
0 | 117 |
def subject(self): |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
118 |
entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
119 |
return u'%s #%s (%s)' % (self._cw.__('New %s' % entity.e_schema), |
3110
757d36162235
enhance notification mecanism: recipients may return user entities, which will be used to create a fake session so one can check security during notification if necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3051
diff
changeset
|
120 |
entity.eid, self.user_data['login']) |
0 | 121 |
|
3525
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
122 |
|
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
123 |
def format_value(value): |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
124 |
if isinstance(value, unicode): |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
125 |
return u'"%s"' % value |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
126 |
return value |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
127 |
|
3536 | 128 |
|
3525
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
129 |
class EntityUpdatedNotificationView(NotificationView): |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
130 |
"""abstract class for notification on entity/relation |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
131 |
|
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
132 |
all you have to do by default is : |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
133 |
* set id and __select__ attributes to match desired events and entity types |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
134 |
* set a content attribute to define the content of the email (unless you |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
135 |
override call) |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
136 |
""" |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
137 |
__abstract__ = True |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
138 |
id = 'notif_entity_updated' |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
139 |
msgid_timestamp = False |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
140 |
message = _('updated') |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
141 |
no_detailed_change_attrs = () |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
142 |
content = """ |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
143 |
Properties have been updated by %(user)s: |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
144 |
|
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
145 |
%(changes)s |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
146 |
|
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
147 |
url: %(url)s |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
148 |
""" |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
149 |
|
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
150 |
def context(self, **kwargs): |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
151 |
context = super(EntityUpdatedNotificationView, self).context(**kwargs) |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
152 |
changes = self.req.transaction_data['changes'][self.rset[0][0]] |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
153 |
_ = self.req._ |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
154 |
formatted_changes = [] |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
155 |
for attr, oldvalue, newvalue in sorted(changes): |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
156 |
# check current user has permission to see the attribute |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
157 |
rschema = self.vreg.schema[attr] |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
158 |
if rschema.is_final(): |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
159 |
if not rschema.has_perm(self.req, 'read', eid=self.rset[0][0]): |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
160 |
continue |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
161 |
# XXX suppose it's a subject relation... |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
162 |
elif not rschema.has_perm(self.req, 'read', fromeid=self.rset[0][0]): |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
163 |
continue |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
164 |
if attr in self.no_detailed_change_attrs: |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
165 |
msg = _('%s updated') % _(attr) |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
166 |
elif oldvalue not in (None, ''): |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
167 |
msg = _('%(attr)s updated from %(oldvalue)s to %(newvalue)s') % { |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
168 |
'attr': _(attr), |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
169 |
'oldvalue': format_value(oldvalue), |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
170 |
'newvalue': format_value(newvalue)} |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
171 |
else: |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
172 |
msg = _('%(attr)s set to %(newvalue)s') % { |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
173 |
'attr': _(attr), 'newvalue': format_value(newvalue)} |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
174 |
formatted_changes.append('* ' + msg) |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
175 |
if not formatted_changes: |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
176 |
# current user isn't allowed to see changes, skip this notification |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
177 |
raise SkipEmail() |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
178 |
context['changes'] = '\n'.join(formatted_changes) |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
179 |
return context |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
180 |
|
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
181 |
def subject(self): |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
182 |
entity = self.entity(self.row or 0, self.col or 0) |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
183 |
return u'%s #%s (%s)' % (self.req.__('Updated %s' % entity.e_schema), |
2dc3908f667f
[notification] add operation responsible for sending email notification when an entity is updated
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3110
diff
changeset
|
184 |
entity.eid, self.user_data['login']) |
3536 | 185 |
|
186 |
||
2880 | 187 |
from logilab.common.deprecation import class_renamed, class_moved, deprecated |
188 |
from cubicweb.hooks.notification import RenderAndSendNotificationView |
|
189 |
from cubicweb.common.mail import parse_message_id |
|
190 |
||
738
9b8cb1976992
better name for NormalizedTextView, drop ContentAddedMixIn
sylvain.thenault@logilab.fr
parents:
730
diff
changeset
|
191 |
NormalizedTextView = class_renamed('NormalizedTextView', ContentAddedView) |
2841
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2818
diff
changeset
|
192 |
RenderAndSendNotificationView = class_moved(RenderAndSendNotificationView) |
3083
3084bc9ccc64
wrong merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3072
diff
changeset
|
193 |
parse_message_id = deprecated('parse_message_id is now defined in cubicweb.common.mail')(parse_message_id) |
3084bc9ccc64
wrong merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3072
diff
changeset
|
194 |