[PATCH 2 of 7] notification: allow multiple body parts in templates

Jan Heylen heyleke at gmail.com
Tue Apr 14 12:03:40 EDT 2015


# HG changeset patch
# User Jan Heylen <heyleke at gmail.com>
# Date 1427469226 -3600
#      Fri Mar 27 16:13:46 2015 +0100
# Node ID 55ba8e68269da8fb0c33c65711a57b4fd9e1b675
# Parent  cb41b8211291b55bcd7c77919f714791927b8045
notification: allow multiple body parts in templates

diff -r cb41b8211291 -r 55ba8e68269d kallithea/model/notification.py
--- a/kallithea/model/notification.py	Fri Mar 27 13:58:04 2015 +0100
+++ b/kallithea/model/notification.py	Fri Mar 27 16:13:46 2015 +0100
@@ -59,7 +59,7 @@
 
     def create(self, created_by, subject, body, recipients=None,
                type_=Notification.TYPE_MESSAGE, with_email=True,
-               email_kwargs={}):
+               email_kwargs={}, bodies=None):
         """
 
         Creates notification of given type
@@ -103,10 +103,16 @@
         #else: silently skip notification mails?
 
         # TODO: inform user who are notified
-        notif = Notification.create(
-            created_by=created_by_obj, subject=subject,
-            body=body, recipients=recipients_objs, type_=type_
-        )
+        if not bodies:
+            bodies = [body]
+
+        bodies_html = []
+        for body in bodies:
+            notif = Notification.create(
+                created_by=created_by_obj, subject=subject,
+                body=body, recipients=recipients_objs, type_=type_
+            )
+            bodies_html.append(h.rst_w_mentions(body))
 
         if not with_email:
             return notif
@@ -123,14 +129,14 @@
             ## this is passed into template
             html_kwargs = {
                       'subject': subject,
-                      'body': h.rst_w_mentions(body),
+                      'bodies': bodies_html,
                       'when': h.fmt_date(notif.created_on),
                       'user': notif.created_by_user.username,
                       }
 
             txt_kwargs = {
                       'subject': subject,
-                      'body': body,
+                      'bodies': bodies,
                       'when': h.fmt_date(notif.created_on),
                       'user': notif.created_by_user.username,
                       }
diff -r cb41b8211291 -r 55ba8e68269d kallithea/templates/email_templates/changeset_comment.html
--- a/kallithea/templates/email_templates/changeset_comment.html	Fri Mar 27 13:58:04 2015 +0100
+++ b/kallithea/templates/email_templates/changeset_comment.html	Fri Mar 27 16:13:46 2015 +0100
@@ -6,8 +6,9 @@
 %else:
 <p>${_('Comment from %s on %s changeset %s') % (cs_comment_user, cs_target_repo, h.short_id(raw_id))}:</p>
 %endif
+%for body in bodies:
 <p>${body}</p>
-
+%endfor
 %if status_change:
     <p>${_('The changeset status was changed to')}: <b>${status_change}</b></p>
 %endif
diff -r cb41b8211291 -r 55ba8e68269d kallithea/templates/email_templates/changeset_comment.txt
--- a/kallithea/templates/email_templates/changeset_comment.txt	Fri Mar 27 13:58:04 2015 +0100
+++ b/kallithea/templates/email_templates/changeset_comment.txt	Fri Mar 27 16:13:46 2015 +0100
@@ -6,7 +6,9 @@
 %else:
 ${_('Comment from %s on %s changeset %s') % (cs_comment_user, cs_target_repo, h.short_id(raw_id))|n,unicode}:
 %endif
+%for body in bodies:
 ${body|n,unicode}
+%endfor
 
 %if status_change:
 ${_('The changeset status was changed to')|n,unicode}: ${status_change|n,unicode}
diff -r cb41b8211291 -r 55ba8e68269d kallithea/templates/email_templates/default.html
--- a/kallithea/templates/email_templates/default.html	Fri Mar 27 13:58:04 2015 +0100
+++ b/kallithea/templates/email_templates/default.html	Fri Mar 27 16:13:46 2015 +0100
@@ -1,4 +1,6 @@
 ## -*- coding: utf-8 -*-
 <%inherit file="main.html"/>
 
+%for body in bodies:
 ${body}
+%endfor
diff -r cb41b8211291 -r 55ba8e68269d kallithea/templates/email_templates/default.txt
--- a/kallithea/templates/email_templates/default.txt	Fri Mar 27 13:58:04 2015 +0100
+++ b/kallithea/templates/email_templates/default.txt	Fri Mar 27 16:13:46 2015 +0100
@@ -1,4 +1,6 @@
 ## -*- coding: utf-8 -*-
 <%inherit file="main.txt"/>
 
+%for body in bodies:
 ${body|n,unicode}
+%endfor
diff -r cb41b8211291 -r 55ba8e68269d kallithea/templates/email_templates/main.html
--- a/kallithea/templates/email_templates/main.html	Fri Mar 27 13:58:04 2015 +0100
+++ b/kallithea/templates/email_templates/main.html	Fri Mar 27 16:13:46 2015 +0100
@@ -1,4 +1,6 @@
+%for body in bodies:
 ${self.body()}
+%endfor
 
 <br/>
 <br/>
diff -r cb41b8211291 -r 55ba8e68269d kallithea/templates/email_templates/main.txt
--- a/kallithea/templates/email_templates/main.txt	Fri Mar 27 13:58:04 2015 +0100
+++ b/kallithea/templates/email_templates/main.txt	Fri Mar 27 16:13:46 2015 +0100
@@ -1,4 +1,6 @@
+%for body in bodies:
 ${self.body()|n,unicode}
+%endfor
 
 -- 
 ${_("This is an automatic notification. Don't reply to this mail.")|n,unicode}
diff -r cb41b8211291 -r 55ba8e68269d kallithea/templates/email_templates/pull_request.html
--- a/kallithea/templates/email_templates/pull_request.html	Fri Mar 27 13:58:04 2015 +0100
+++ b/kallithea/templates/email_templates/pull_request.html	Fri Mar 27 16:13:46 2015 +0100
@@ -10,7 +10,11 @@
 <p>${_('URL')}: <a href="${pr_url}">${pr_url}</a></p>
 
 <p>${_('Description')}:</p>
-<p style="white-space: pre-wrap;">${body}</p>
+%for body in bodies:
+<p style="white-space: pre-wrap;">
+${body}
+</p>
+%endfor
 
 <p>${_('Changesets')}:</p>
 <p style="white-space: pre-wrap;">
diff -r cb41b8211291 -r 55ba8e68269d kallithea/templates/email_templates/pull_request.txt
--- a/kallithea/templates/email_templates/pull_request.txt	Fri Mar 27 13:58:04 2015 +0100
+++ b/kallithea/templates/email_templates/pull_request.txt	Fri Mar 27 16:13:46 2015 +0100
@@ -10,7 +10,9 @@
 ${_('URL')|n,unicode}: ${pr_url|n,unicode}
 
 ${_('Description')|n,unicode}:
+%for body in bodies:
 ${body|n,unicode}
+%endfor
 
 ${_('Changesets')|n,unicode}:
 %for r,r_msg in pr_revisions:
diff -r cb41b8211291 -r 55ba8e68269d kallithea/templates/email_templates/pull_request_comment.html
--- a/kallithea/templates/email_templates/pull_request_comment.html	Fri Mar 27 13:58:04 2015 +0100
+++ b/kallithea/templates/email_templates/pull_request_comment.html	Fri Mar 27 16:13:46 2015 +0100
@@ -2,7 +2,9 @@
 <%inherit file="main.html"/>
 
 <p>${_('Comment from %s on %s pull request "%s"') % (pr_comment_user, repo_name, pr_title)}:</p>
+%for body in bodies:
 <p>${body}</p>
+%endfor
 
 %if status_change:
     %if closing_pr:
diff -r cb41b8211291 -r 55ba8e68269d kallithea/templates/email_templates/pull_request_comment.txt
--- a/kallithea/templates/email_templates/pull_request_comment.txt	Fri Mar 27 13:58:04 2015 +0100
+++ b/kallithea/templates/email_templates/pull_request_comment.txt	Fri Mar 27 16:13:46 2015 +0100
@@ -2,7 +2,9 @@
 <%inherit file="main.txt"/>
 
 ${_('Comment from %s on %s pull request "%s"') % (pr_comment_user, repo_name, pr_title)|n,unicode}:
+%for body in bodies:
 ${body|n,unicode}
+%endfor
 
 %if status_change:
     %if closing_pr:
diff -r cb41b8211291 -r 55ba8e68269d kallithea/templates/email_templates/registration.html
--- a/kallithea/templates/email_templates/registration.html	Fri Mar 27 13:58:04 2015 +0100
+++ b/kallithea/templates/email_templates/registration.html	Fri Mar 27 16:13:46 2015 +0100
@@ -1,6 +1,8 @@
 ## -*- coding: utf-8 -*-
 <%inherit file="main.html"/>
 
+%for body in bodies:
 ${body}
+%endfor
 
 ${_('View this user here')}: <a href="${registered_user_url}">${registered_user_url}</a>
diff -r cb41b8211291 -r 55ba8e68269d kallithea/templates/email_templates/registration.txt
--- a/kallithea/templates/email_templates/registration.txt	Fri Mar 27 13:58:04 2015 +0100
+++ b/kallithea/templates/email_templates/registration.txt	Fri Mar 27 16:13:46 2015 +0100
@@ -1,6 +1,8 @@
 ## -*- coding: utf-8 -*-
 <%inherit file="main.txt"/>
 
+%for body in bodies:
 ${body|n,unicode}
+%endfor
 
 ${_('View this user here')|n,unicode}: ${registered_user_url|n,unicode}


More information about the kallithea-general mailing list