Mercurial > kallithea
changeset 7376:6bd262eaa058
notification: don't repeat common actions for each email recipient
The emails sent upon PR creation or comments are identical for all
recipients, except for the 'To:' header added by the send_email method.
Calculation of subject, body, etc. can thus be moved outside of the
loop.
Move the manipulation of the recipient list down to where it is used, for
clarity.
author | Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> |
---|---|
date | Tue, 18 Sep 2018 20:57:32 +0200 |
parents | 3d39e68ff5bc |
children | 0e33880b2897 |
files | kallithea/model/notification.py |
diffstat | 1 files changed, 27 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/model/notification.py Mon Sep 17 22:34:09 2018 +0200 +++ b/kallithea/model/notification.py Tue Sep 18 20:57:32 2018 +0200 @@ -98,40 +98,40 @@ if not with_email: return notif - # don't send email to person who created this comment - rec_objs = set(recipients_objs).difference(set([created_by_obj])) - headers = {} headers['X-Kallithea-Notification-Type'] = type_ if 'threading' in email_kwargs: headers['References'] = ' '.join('<%s>' % x for x in email_kwargs['threading']) + # this is passed into template + html_kwargs = { + 'subject': subject, + 'body': h.render_w_mentions(body, repo_name), + 'when': h.fmt_date(notif.created_on), + 'user': notif.created_by_user.username, + } + + txt_kwargs = { + 'subject': subject, + 'body': body, + 'when': h.fmt_date(notif.created_on), + 'user': notif.created_by_user.username, + } + + html_kwargs.update(email_kwargs) + txt_kwargs.update(email_kwargs) + email_subject = EmailNotificationModel() \ + .get_email_description(type_, **txt_kwargs) + email_txt_body = EmailNotificationModel() \ + .get_email_tmpl(type_, 'txt', **txt_kwargs) + email_html_body = EmailNotificationModel() \ + .get_email_tmpl(type_, 'html', **html_kwargs) + + # don't send email to person who created this comment + rec_objs = set(recipients_objs).difference(set([created_by_obj])) + # send email with notification to all other participants for rec in rec_objs: - # this is passed into template - html_kwargs = { - 'subject': subject, - 'body': h.render_w_mentions(body, repo_name), - 'when': h.fmt_date(notif.created_on), - 'user': notif.created_by_user.username, - } - - txt_kwargs = { - 'subject': subject, - 'body': body, - 'when': h.fmt_date(notif.created_on), - 'user': notif.created_by_user.username, - } - - html_kwargs.update(email_kwargs) - txt_kwargs.update(email_kwargs) - email_subject = EmailNotificationModel() \ - .get_email_description(type_, **txt_kwargs) - email_txt_body = EmailNotificationModel() \ - .get_email_tmpl(type_, 'txt', **txt_kwargs) - email_html_body = EmailNotificationModel() \ - .get_email_tmpl(type_, 'html', **html_kwargs) - tasks.send_email([rec.email], email_subject, email_txt_body, email_html_body, headers, author=created_by_obj)