incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [05/12] git commit: [#2502] ticket:300 Use template for mass report
Date Mon, 22 Apr 2013 19:41:21 GMT
[#2502] ticket:300 Use template for mass report


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/92f0595f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/92f0595f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/92f0595f

Branch: refs/heads/master
Commit: 92f0595ff4261856773cf4b4e6390bdcfd3ad998
Parents: be38319
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Apr 16 10:55:03 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Mon Apr 22 19:40:27 2013 +0000

----------------------------------------------------------------------
 ForgeTracker/forgetracker/data/mass_report         |    6 +++
 .../forgetracker/tests/functional/test_root.py     |   28 +++++++--------
 ForgeTracker/forgetracker/tracker_main.py          |   26 ++++++++------
 3 files changed, 34 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/92f0595f/ForgeTracker/forgetracker/data/mass_report
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/data/mass_report b/ForgeTracker/forgetracker/data/mass_report
new file mode 100644
index 0000000..629a1e2
--- /dev/null
+++ b/ForgeTracker/forgetracker/data/mass_report
@@ -0,0 +1,6 @@
+{{ data.header }}
+
+{% for t_num, change_text in data.changes %}
+ticket: [{{ context.app.config.options.mount_point }}:#{{ t_num }}]
+{{ change_text }}
+{% endfor %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/92f0595f/ForgeTracker/forgetracker/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py b/ForgeTracker/forgetracker/tests/functional/test_root.py
index fe58a00..760f740 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -1141,30 +1141,28 @@ class TestFunctionalController(TrackerTestController):
 
         # Expected data
         email_header = '''Mass edit changing:
-- **status**: accepted
-- **Milestone: 2.0
+- **Status**: accepted
+- **Milestone**: 2.0
+
 '''
         first_ticket_changes = '''ticket: [bugs:#1]
-- **status**: open --> accepted
-- **Milestone: 2.0 --> 2.0
+- **Status**: open --> accepted
 '''
         second_ticket_changes = '''ticket: [bugs:#2]
-- **status**: accepted --> accepted
-- **Milestone: 1.0 --> 2.0
+- **Milestone**: 1.0 --> 2.0
 '''
         third_ticket_changes = '''ticket: [bugs:#3]
-- **status**: unread --> accepted
-- **Milestone: --> 2.0
+- **Status**: unread --> accepted
+- **Milestone**: 1.0 --> 2.0
 '''
-        email = '\n'.join([email_header, first_ticket_changes])
+        email = u'\n'.join([email_header, first_ticket_changes, ''])
         assert_equal(email, first_user_email.kwargs.text)
-        email = '\n'.join([email_header, second_ticket_changes])
+        email = u'\n'.join([email_header, second_ticket_changes, ''])
         assert_equal(email, second_user_email.kwargs.text)
-        email = '\n'.join([email_header,
-                           first_ticket_changes,
-                           second_ticket_changes,
-                           third_ticket_changes])
-        assert_equal(email, admin_email.kwargs.text)
+        assert_in(email_header, admin_email.kwargs.text)
+        assert_in(first_ticket_changes, admin_email.kwargs.text)
+        assert_in(second_ticket_changes, admin_email.kwargs.text)
+        assert_in(third_ticket_changes, admin_email.kwargs.text)
 
     def test_filtered_by_subscription(self):
         self.new_ticket(summary='test first ticket', status='open')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/92f0595f/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index dc2df43..132f9ec 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -24,6 +24,7 @@ from urllib2 import urlopen
 from webob import exc
 import json
 from itertools import ifilter, imap
+import jinja2
 
 # Non-stdlib imports
 import pkg_resources
@@ -37,6 +38,7 @@ from bson import ObjectId
 from bson.son import SON
 from bson.errors import InvalidId
 from webhelpers import feedgenerator as FG
+from paste.deploy.converters import asbool
 
 from ming import schema
 from ming.orm.ormsession import ThreadLocalORMSession
@@ -847,26 +849,28 @@ class RootController(BaseController):
                 ticket.commit()
         filtered_changes = filtered_by_subscription(changed_tickets)
         users = M.User.query.find({'_id': {'$in': filtered_changes.keys()}}).all()
+        def changes_iter(user):
+            for t_id in filtered_changes.get(user._id, []):
+                yield (changed_tickets[t_id].ticket_num, changes[t_id])
         mail = dict(
             fromaddr = str(c.user._id),
             reply_to = str(c.user._id),
-            message_id = h.gen_message_id(),
             subject = '[%s:%s] Mass edit changes by %s' % (c.project.shortname,
                                                            c.app.config.options.mount_point,
                                                            c.user.display_name),
         )
-        head = ['Mass edit changing:']
-        # TODO: add list with new values here
-        head = '\n'.join(head)
+        tmpl = jinja2.Environment(
+                loader=jinja2.PackageLoader('forgetracker', 'data'),
+                auto_reload=asbool(config.get('auto_reload_templates', True)),
+        ).get_template('mass_report')
+        head = ['- **%s**: %s' % (get_label(f), v) for f, v in values.iteritems()]
+        head += ['- **%s**: %s' % (get_label(f), v) for f, v in custom_values.iteritems()]
+        tmpl_context = {'context': c, 'data': {'header': '\n'.join(['Mass edit changing:']
+ head)}}
         for user in users:
-            text = []
-            for t_id in filtered_changes.get(user._id, []):
-                text.append('ticket: [%s:#%d]' % (c.app.config.options.mount_point,
-                                                  changed_tickets[t_id].ticket_num))
-                text.append(changes[t_id])
-                text.append('')
+            tmpl_context['data'].update({'changes': changes_iter(user)})
             mail.update(dict(
-                text = head + '\n\n' +  '\n'.join(text),
+                message_id = h.gen_message_id(),
+                text = tmpl.render(tmpl_context),
                 destinations = [str(user._id)]))
             mail_tasks.sendmail.post(**mail)
             # TODO: send summary on ticket's monitoring email


Mime
View raw message