annotate rhodecode/model/notification.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl

Imported some of the GPLv3'd changes from RhodeCode v2.2.5. This imports changes between changesets 21af6c4eab3d and 6177597791c2 in RhodeCode's original repository, including only changes to Python files and HTML. RhodeCode clearly licensed its changes to these files under GPLv3 in their /LICENSE file, which states the following: The Python code and integrated HTML are licensed under the GPLv3 license. (See: https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE or http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE for an online copy of that LICENSE file) Conservancy reviewed these changes and confirmed that they can be licensed as a whole to the Kallithea project under GPLv3-only. While some of the contents committed herein are clearly licensed GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the statement above from RhodeCode indicates that they intend GPLv3-only as their license, per GPLv3ยง14 and other relevant sections of GPLv3.
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 02 Jul 2014 19:03:13 -0400
parents 40d50bb7cf2f
children 7e5f8c12a3fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 # This program is free software: you can redistribute it and/or modify
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 # it under the terms of the GNU General Public License as published by
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 # the Free Software Foundation, either version 3 of the License, or
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 # (at your option) any later version.
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 #
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 # This program is distributed in the hope that it will be useful,
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 # GNU General Public License for more details.
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 #
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 # You should have received a copy of the GNU General Public License
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
14 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
15 rhodecode.model.notification
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
17
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
18 Model for notifications
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
19
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
20
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
21 :created_on: Nov 20, 2011
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
22 :author: marcink
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
23 :copyright: (c) 2013 RhodeCode GmbH.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
24 :license: GPLv3, see LICENSE for more details.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
25 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
26
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
28 import os
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 import logging
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 import traceback
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31
3423
043d3827cd88 added template context into Notification templates
Marcin Kuzminski <marcin@python-works.com>
parents: 3270
diff changeset
32 from pylons import tmpl_context as c
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 from pylons.i18n.translation import _
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34
1723
64e91067b996 - refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
35 import rhodecode
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
36 from rhodecode.lib import helpers as h
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 from rhodecode.model import BaseModel
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 from rhodecode.model.db import Notification, User, UserNotification
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3423
diff changeset
39 from rhodecode.model.meta import Session
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
41 log = logging.getLogger(__name__)
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
43
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 class NotificationModel(BaseModel):
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45
2522
17893d61792a Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2503
diff changeset
46 cls = Notification
17893d61792a Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2503
diff changeset
47
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
48 def __get_notification(self, notification):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
49 if isinstance(notification, Notification):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
50 return notification
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
51 elif isinstance(notification, (int, long)):
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
52 return Notification.get(notification)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
53 else:
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
54 if notification:
2149
50aa7cb78cfe Mysql fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
55 raise Exception('notification must be int, long or Instance'
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
56 ' of Notification got %s' % type(notification))
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
57
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
58 def create(self, created_by, subject, body, recipients=None,
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
59 type_=Notification.TYPE_MESSAGE, with_email=True,
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3423
diff changeset
60 email_kwargs={}, email_subject=None):
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
61 """
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1791
diff changeset
62
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
63 Creates notification of given type
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1791
diff changeset
64
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
65 :param created_by: int, str or User instance. User who created this
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
66 notification
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
67 :param subject:
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
68 :param body:
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1800
diff changeset
69 :param recipients: list of int, str or User objects, when None
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
70 is given send to all admins
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
71 :param type_: type of notification
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
72 :param with_email: send email with this notification
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
73 :param email_kwargs: additional dict to pass as args to email template
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3423
diff changeset
74 :param email_subject: use given subject as email subject
1703
f23828b00b21 notification fixes and improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1702
diff changeset
75 """
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1717
diff changeset
76 from rhodecode.lib.celerylib import tasks, run_task
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
78 if recipients and not getattr(recipients, '__iter__', False):
3270
81397bd3e77f fix a couple of typos
Mads Kiilerich <madski@unity3d.com>
parents: 3255
diff changeset
79 raise Exception('recipients must be a list or iterable')
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80
2432
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2391
diff changeset
81 created_by_obj = self._get_user(created_by)
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
83 if recipients:
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
84 recipients_objs = []
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
85 for u in recipients:
2432
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2391
diff changeset
86 obj = self._get_user(u)
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
87 if obj:
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
88 recipients_objs.append(obj)
3781
40d50bb7cf2f emailing: log failing emailing as an error
Mads Kiilerich <madski@unity3d.com>
parents: 3654
diff changeset
89 else:
40d50bb7cf2f emailing: log failing emailing as an error
Mads Kiilerich <madski@unity3d.com>
parents: 3654
diff changeset
90 # TODO: inform user that requested operation couldn't be completed
40d50bb7cf2f emailing: log failing emailing as an error
Mads Kiilerich <madski@unity3d.com>
parents: 3654
diff changeset
91 log.error('cannot email unknown user %r', u)
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
92 recipients_objs = set(recipients_objs)
2077
179604334d98 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
93 log.debug('sending notifications %s to %s' % (
179604334d98 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
94 type_, recipients_objs)
179604334d98 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
95 )
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
96 else:
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
97 # empty recipients means to all admins
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
98 recipients_objs = User.query().filter(User.admin == True).all()
2077
179604334d98 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
99 log.debug('sending notifications %s to admins: %s' % (
179604334d98 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
100 type_, recipients_objs)
179604334d98 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
101 )
3781
40d50bb7cf2f emailing: log failing emailing as an error
Mads Kiilerich <madski@unity3d.com>
parents: 3654
diff changeset
102 # TODO: inform user who are notified
2077
179604334d98 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
103 notif = Notification.create(
179604334d98 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
104 created_by=created_by_obj, subject=subject,
179604334d98 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
105 body=body, recipients=recipients_objs, type_=type_
179604334d98 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
106 )
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
107
3625
260a7a01b054 follow Python conventions for boolean values
Mads Kiilerich <madski@unity3d.com>
parents: 3448
diff changeset
108 if not with_email:
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
109 return notif
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
110
2387
7d517a35b6c9 Don't send emails to person who comment on changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 2156
diff changeset
111 #don't send email to person who created this comment
7d517a35b6c9 Don't send emails to person who comment on changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 2156
diff changeset
112 rec_objs = set(recipients_objs).difference(set([created_by_obj]))
7d517a35b6c9 Don't send emails to person who comment on changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 2156
diff changeset
113
7d517a35b6c9 Don't send emails to person who comment on changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 2156
diff changeset
114 # send email with notification to all other participants
7d517a35b6c9 Don't send emails to person who comment on changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 2156
diff changeset
115 for rec in rec_objs:
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3423
diff changeset
116 if not email_subject:
3448
cf665eb84d4c notification model should only send html emails not generating multipart ones
Marcin Kuzminski <marcin@python-works.com>
parents: 3430
diff changeset
117 email_subject = NotificationModel()\
cf665eb84d4c notification model should only send html emails not generating multipart ones
Marcin Kuzminski <marcin@python-works.com>
parents: 3430
diff changeset
118 .make_description(notif, show_age=False)
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
119 type_ = type_
3448
cf665eb84d4c notification model should only send html emails not generating multipart ones
Marcin Kuzminski <marcin@python-works.com>
parents: 3430
diff changeset
120 email_body = None # we set body to none, we just send HTML emails
2296
e5c0f201ca0b Add changeset status change into emails
Marcin Kuzminski <marcin@python-works.com>
parents: 2217
diff changeset
121 ## this is passed into template
1800
6c86c987cf93 pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1791
diff changeset
122 kwargs = {'subject': subject, 'body': h.rst_w_mentions(body)}
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
123 kwargs.update(email_kwargs)
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
124 email_body_html = EmailNotificationModel()\
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
125 .get_email_tmpl(type_, **kwargs)
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
126
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1717
diff changeset
127 run_task(tasks.send_email, rec.email, email_subject, email_body,
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
128 email_body_html)
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
129
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
130 return notif
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
131
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
132 def delete(self, user, notification):
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
133 # we don't want to remove actual notification just the assignment
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
134 try:
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
135 notification = self.__get_notification(notification)
2432
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2391
diff changeset
136 user = self._get_user(user)
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
137 if notification and user:
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
138 obj = UserNotification.query()\
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
139 .filter(UserNotification.user == user)\
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
140 .filter(UserNotification.notification
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
141 == notification)\
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
142 .one()
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3423
diff changeset
143 Session().delete(obj)
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
144 return True
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
145 except Exception:
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
146 log.error(traceback.format_exc())
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
147 raise
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
148
2433
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
149 def get_for_user(self, user, filter_=None):
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
150 """
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
151 Get mentions for given user, filter them if filter dict is given
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
152
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
153 :param user:
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
154 :param filter:
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
155 """
2432
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2391
diff changeset
156 user = self._get_user(user)
2433
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
157
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
158 q = UserNotification.query()\
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
159 .filter(UserNotification.user == user)\
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
160 .join((Notification, UserNotification.notification_id ==
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
161 Notification.notification_id))
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
162
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
163 if filter_:
2503
d04243e932cc Added filtering on inbox by comments
Marcin Kuzminski <marcin@python-works.com>
parents: 2447
diff changeset
164 q = q.filter(Notification.type_.in_(filter_))
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
165
2433
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
166 return q.all()
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
167
2610
3fdf7c3be2c9 added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
168 def mark_read(self, user, notification):
3fdf7c3be2c9 added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
169 try:
3fdf7c3be2c9 added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
170 notification = self.__get_notification(notification)
3fdf7c3be2c9 added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
171 user = self._get_user(user)
3fdf7c3be2c9 added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
172 if notification and user:
3fdf7c3be2c9 added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
173 obj = UserNotification.query()\
3fdf7c3be2c9 added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
174 .filter(UserNotification.user == user)\
3fdf7c3be2c9 added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
175 .filter(UserNotification.notification
3fdf7c3be2c9 added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
176 == notification)\
3fdf7c3be2c9 added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
177 .one()
3fdf7c3be2c9 added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
178 obj.read = True
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3423
diff changeset
179 Session().add(obj)
2610
3fdf7c3be2c9 added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
180 return True
3fdf7c3be2c9 added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
181 except Exception:
3fdf7c3be2c9 added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
182 log.error(traceback.format_exc())
3fdf7c3be2c9 added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
183 raise
3fdf7c3be2c9 added mark as read for single notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
184
2433
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
185 def mark_all_read_for_user(self, user, filter_=None):
2432
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2391
diff changeset
186 user = self._get_user(user)
2433
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
187 q = UserNotification.query()\
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
188 .filter(UserNotification.user == user)\
2217
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2156
diff changeset
189 .filter(UserNotification.read == False)\
2433
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
190 .join((Notification, UserNotification.notification_id ==
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
191 Notification.notification_id))
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
192 if filter_:
2503
d04243e932cc Added filtering on inbox by comments
Marcin Kuzminski <marcin@python-works.com>
parents: 2447
diff changeset
193 q = q.filter(Notification.type_.in_(filter_))
2433
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
194
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
195 # this is a little inefficient but sqlalchemy doesn't support
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
196 # update on joined tables :(
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
197 for obj in q.all():
74f2910f7ad9 Added pull requests filter into notification inbox.
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
198 obj.read = True
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3423
diff changeset
199 Session().add(obj)
1791
2aee0dc1784e mark all read button for notifications
Marcin Kuzminski <marcin@python-works.com>
parents: 1769
diff changeset
200
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
201 def get_unread_cnt_for_user(self, user):
2432
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2391
diff changeset
202 user = self._get_user(user)
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
203 return UserNotification.query()\
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
204 .filter(UserNotification.read == False)\
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
205 .filter(UserNotification.user == user).count()
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
206
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
207 def get_unread_for_user(self, user):
2432
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2391
diff changeset
208 user = self._get_user(user)
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
209 return [x.notification for x in UserNotification.query()\
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
210 .filter(UserNotification.read == False)\
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1712
diff changeset
211 .filter(UserNotification.user == user).all()]
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
212
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
213 def get_user_notification(self, user, notification):
2432
d3ac7491a5c8 Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents: 2391
diff changeset
214 user = self._get_user(user)
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
215 notification = self.__get_notification(notification)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
216
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
217 return UserNotification.query()\
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
218 .filter(UserNotification.notification == notification)\
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
219 .filter(UserNotification.user == user).scalar()
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
220
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
221 def make_description(self, notification, show_age=True):
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
222 """
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
223 Creates a human readable description based on properties
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
224 of notification object
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1703
diff changeset
225 """
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
226 #alias
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
227 _n = notification
2082
0e27da019f84 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2077
diff changeset
228 _map = {
3654
ec6354949623 Fix a lot of casings - use standard casing in most places
Mads Kiilerich <madski@unity3d.com>
parents: 3625
diff changeset
229 _n.TYPE_CHANGESET_COMMENT: _('%(user)s commented on changeset at %(when)s'),
ec6354949623 Fix a lot of casings - use standard casing in most places
Mads Kiilerich <madski@unity3d.com>
parents: 3625
diff changeset
230 _n.TYPE_MESSAGE: _('%(user)s sent message at %(when)s'),
ec6354949623 Fix a lot of casings - use standard casing in most places
Mads Kiilerich <madski@unity3d.com>
parents: 3625
diff changeset
231 _n.TYPE_MENTION: _('%(user)s mentioned you at %(when)s'),
ec6354949623 Fix a lot of casings - use standard casing in most places
Mads Kiilerich <madski@unity3d.com>
parents: 3625
diff changeset
232 _n.TYPE_REGISTRATION: _('%(user)s registered in RhodeCode at %(when)s'),
ec6354949623 Fix a lot of casings - use standard casing in most places
Mads Kiilerich <madski@unity3d.com>
parents: 3625
diff changeset
233 _n.TYPE_PULL_REQUEST: _('%(user)s opened new pull request at %(when)s'),
ec6354949623 Fix a lot of casings - use standard casing in most places
Mads Kiilerich <madski@unity3d.com>
parents: 3625
diff changeset
234 _n.TYPE_PULL_REQUEST_COMMENT: _('%(user)s commented on pull request at %(when)s')
2082
0e27da019f84 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2077
diff changeset
235 }
3654
ec6354949623 Fix a lot of casings - use standard casing in most places
Mads Kiilerich <madski@unity3d.com>
parents: 3625
diff changeset
236 tmpl = _map[notification.type_]
1731
31e6eb2fb4b2 implements #222 registration feedback
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
237
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
238 if show_age:
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
239 when = h.age(notification.created_on)
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
240 else:
2445
9b623dcddb02 Format datetime in notifications according to unified function
Marcin Kuzminski <marcin@python-works.com>
parents: 2387
diff changeset
241 when = h.fmt_date(notification.created_on)
2156
a27e4d44237e Use __unicode__ instead of __repr__ in models.
Marcin Kuzminski <marcin@python-works.com>
parents: 2149
diff changeset
242
3654
ec6354949623 Fix a lot of casings - use standard casing in most places
Mads Kiilerich <madski@unity3d.com>
parents: 3625
diff changeset
243 return tmpl % dict(
2082
0e27da019f84 code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2077
diff changeset
244 user=notification.created_by_user.username,
3654
ec6354949623 Fix a lot of casings - use standard casing in most places
Mads Kiilerich <madski@unity3d.com>
parents: 3625
diff changeset
245 when=when,
ec6354949623 Fix a lot of casings - use standard casing in most places
Mads Kiilerich <madski@unity3d.com>
parents: 3625
diff changeset
246 )
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
247
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
248
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
249 class EmailNotificationModel(BaseModel):
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
250
1732
8321b3d19b1f test fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1731
diff changeset
251 TYPE_CHANGESET_COMMENT = Notification.TYPE_CHANGESET_COMMENT
3270
81397bd3e77f fix a couple of typos
Mads Kiilerich <madski@unity3d.com>
parents: 3255
diff changeset
252 TYPE_PASSWORD_RESET = 'password_link'
1732
8321b3d19b1f test fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1731
diff changeset
253 TYPE_REGISTRATION = Notification.TYPE_REGISTRATION
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2433
diff changeset
254 TYPE_PULL_REQUEST = Notification.TYPE_PULL_REQUEST
2802
0a623ec24b62 part2 of pull-request notification improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 2799
diff changeset
255 TYPE_PULL_REQUEST_COMMENT = Notification.TYPE_PULL_REQUEST_COMMENT
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
256 TYPE_DEFAULT = 'default'
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
257
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
258 def __init__(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
259 super(EmailNotificationModel, self).__init__()
1723
64e91067b996 - refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
260 self._template_root = rhodecode.CONFIG['pylons.paths']['templates'][0]
64e91067b996 - refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
261 self._tmpl_lookup = rhodecode.CONFIG['pylons.app_globals'].mako_lookup
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
262 self.email_types = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
263 self.TYPE_CHANGESET_COMMENT: 'email_templates/changeset_comment.html',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
264 self.TYPE_PASSWORD_RESET: 'email_templates/password_reset.html',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
265 self.TYPE_REGISTRATION: 'email_templates/registration.html',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
266 self.TYPE_DEFAULT: 'email_templates/default.html',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
267 self.TYPE_PULL_REQUEST: 'email_templates/pull_request.html',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
268 self.TYPE_PULL_REQUEST_COMMENT: 'email_templates/pull_request_comment.html',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3781
diff changeset
269 }
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
270
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
271
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
272 def get_email_tmpl(self, type_, **kwargs):
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
273 """
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
274 return generated template for email based on given type
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1800
diff changeset
275
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
276 :param type_:
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
277 """
1723
64e91067b996 - refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
278
1732
8321b3d19b1f test fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1731
diff changeset
279 base = self.email_types.get(type_, self.email_types[self.TYPE_DEFAULT])
1723
64e91067b996 - refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
280 email_template = self._tmpl_lookup.get_template(base)
3121
3274ba9f1489 fixes #691: Notifications for pull requests: move link to pull request to the top
Marcin Kuzminski <marcin@python-works.com>
parents: 2993
diff changeset
281 # translator and helpers inject
3274ba9f1489 fixes #691: Notifications for pull requests: move link to pull request to the top
Marcin Kuzminski <marcin@python-works.com>
parents: 2993
diff changeset
282 _kwargs = {'_': _,
3423
043d3827cd88 added template context into Notification templates
Marcin Kuzminski <marcin@python-works.com>
parents: 3270
diff changeset
283 'h': h,
043d3827cd88 added template context into Notification templates
Marcin Kuzminski <marcin@python-works.com>
parents: 3270
diff changeset
284 'c': c}
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
285 _kwargs.update(kwargs)
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
286 log.debug('rendering tmpl %s with kwargs %s' % (base, _kwargs))
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
287 return email_template.render(**_kwargs)