Commits

David Chambers committed 47843bd

comments: generate dictionary of moderation URLs in a more intelligible manner

  • Participants
  • Parent commits 9e310f8

Comments (0)

Files changed (1)

         request.session['comment'] = comment
 
         # send e-mail notification
-        post_url = request.build_absolute_uri(reverse(post, args=(path_,)))
         params = {
             'api_key': disqus.api_key,
             'post_id': comment.id,
             'thread_id': thread.id,
-            'url': post_url,
+            'url': request.build_absolute_uri(reverse(post, args=(path_,))),
         }
-        links = {
+        actions = {
             'approve':  ('api_key', 'post_id', 'url'),
             'close':    ('api_key', 'thread_id'),
             'delete':   ('api_key', 'post_id'),
             'spam':     ('api_key', 'post_id'),
         }
-        author = u'%s <%s>' % (author_name, author_email)
-        subject = u'[%s] Comment: "%s"' % (mango.settings.SITE_TITLE, document.title_text)
-        context = {
-            'comment': message,
-            'commenter': author,
-            'urls': dict([('post', post_url)] + [(action, u'%s?%s' % (
-                    request.build_absolute_uri(reverse('mango.handlers.moderate', args=(action,))),
-                    urlencode([(k, params[k]) for k in keys])))
-                    for action, keys in links.items()]),
-        }
+        urls = {'post': params['url']}
+        for action, keys in actions.items():
+            urls[action] = u'%s?%s' % (
+                request.build_absolute_uri(reverse('mango.handlers.moderate', args=(action,))),
+                urlencode(((key, params[key]) for key in keys)),
+            )
+
         try:
             recipient = primary_author_email()
         except EmptySettingError, error:
             logger.error(error.message)
             return HttpResponseServerError(error.html())
 
+        author = u'%s <%s>' % (author_name, author_email)
+        context = {'comment': message, 'commenter': author, 'urls': urls}
+        subject = u'[%s] Comment: "%s"' % (mango.settings.SITE_TITLE, document.title_text)
         msg = EmailMultiAlternatives(subject, render_to_string('email/moderator.text', context),
                 to=[recipient], headers={'Reply-To': author})
         msg.attach_alternative(render_to_string('email/moderator.html', context), 'text/html')