]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/templatetags/node_tags.py
change the order in which comments are ordered
[osqa.git] / forum / templatetags / node_tags.py
index c7fcba03a47a2772efc4e0e38a8cdfd5de6c2322..6fc19cec56dd036d2740a4d60d4d83ca2fdd0f95 100644 (file)
@@ -2,10 +2,12 @@ from datetime import datetime, timedelta
 import re\r
 \r
 from forum.models import Question, Action\r
+from django.template import Template, Context\r
 from django.utils.translation import ungettext, ugettext as _\r
 from django.utils.html import strip_tags\r
 from django.utils.encoding import smart_unicode\r
 from django.utils.safestring import mark_safe\r
+from django.conf import settings as django_settings\r
 from django.core.urlresolvers import reverse\r
 from django import template\r
 from forum.actions import *\r
@@ -80,7 +82,13 @@ def post_control(text, url, command=False, withprompt=False, confirm=False, titl
         (copy and " copy" or " ")\r
     return {'text': text, 'url': url, 'classes': classes, 'title': title}\r
 \r
-@register.inclusion_tag('node/post_controls.html')\r
+\r
+moderation_enabled = False\r
+for m in django_settings.MODULE_LIST:\r
+    if m.__name__.endswith('moderation'):\r
+        moderation_enabled = True\r
+\r
+@register.inclusion_tag('node/post_controls.html' if not moderation_enabled else "modules/moderation/node/post_controls.html")\r
 def post_controls(post, user):\r
     controls = []\r
     menu = []\r
@@ -174,7 +182,7 @@ def post_controls(post, user):
 \r
 @register.inclusion_tag('node/comments.html')\r
 def comments(post, user):\r
-    all_comments = post.comments.filter_state(deleted=False).order_by('added_at')\r
+    all_comments = post.comments.filter_state(deleted=False).order_by('-added_at')\r
 \r
     if len(all_comments) <= 5:\r
         top_scorers = all_comments\r
@@ -203,8 +211,19 @@ def comments(post, user):
         context.update(dict(c.__dict__))\r
         comments.append(context)\r
 \r
+    # Generate canned comments\r
+    canned_comments = []\r
+    for comment in settings.CANNED_COMMENTS:\r
+        t = Template(smart_unicode(comment))\r
+        c = Context({\r
+            'post' : post,\r
+            'settings' : settings,\r
+        })\r
+        canned_comments.append(t.render(c))\r
+\r
     return {\r
         'comments': comments,\r
+        'canned_comments': canned_comments,\r
         'post': post,\r
         'can_comment': user.can_comment(post),\r
         'max_length': settings.FORM_MAX_COMMENT_BODY,\r