]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/templatetags/node_tags.py
'show N more' comments rather than 'show all'
[osqa.git] / forum / templatetags / node_tags.py
index aab4d99ae350c142c2fcf142bb940ff7319ce639..5cdd3b05d46aa1ef3a59edc5fbd5f76f9b6be0ed 100644 (file)
@@ -2,9 +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
@@ -74,11 +77,18 @@ def post_classes(post):
 \r
     return " ".join(classes)\r
 \r
-def post_control(text, url, command=False, withprompt=False, confirm=False, title=""):\r
-    classes = (command and "ajax-command" or " ") + (withprompt and " withprompt" or " ") + (confirm and " confirm" or " ")\r
+def post_control(text, url, command=False, withprompt=False, confirm=False, title="", copy=False):\r
+    classes = (command and "ajax-command" or " ") + (withprompt and " withprompt" or " ") + (confirm and " confirm" or " ") + \\r
+        (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
@@ -87,16 +97,25 @@ def post_controls(post, user):
     # We show the link tool if the post is an Answer. It is visible to Guests too.\r
     if post_type == "answer":\r
         # Answer permanent link tool\r
-        controls.append(post_control(_('permanent link'), reverse('answer_permanent_link', kwargs={'id' : post.id}),\r
-                                     title=_("answer permanent link"), command=True, withprompt=True))\r
+        controls.append(post_control(_('permanent link'), reverse('answer_permanent_link', kwargs={'id' : post.id,}),\r
+                                     title=_("answer permanent link"), command=True, withprompt=True, copy=True))\r
+\r
+        # Users should be able to award points for an answer. Users cannot award their own answers\r
+        if user != post.author and user.is_authenticated():\r
+            controls.append(post_control(_("award points"), reverse('award_points', kwargs={'user_id' : post.author.id,\r
+                                         'answer_id' : post.id}), title=_("award points to %s") % smart_unicode(post.author.username),\r
+                                         command=True, withprompt=True))\r
 \r
     # The other controls are visible only to authenticated users.\r
     if user.is_authenticated():\r
-        edit_url = reverse('edit_' + post_type, kwargs={'id': post.id})\r
-        if user.can_edit_post(post):\r
-            controls.append(post_control(_('edit'), edit_url))\r
-        elif post_type == 'question' and user.can_retag_questions():\r
-            controls.append(post_control(_('retag'), edit_url))\r
+        try:\r
+            edit_url = reverse('edit_' + post_type, kwargs={'id': post.id})\r
+            if user.can_edit_post(post):\r
+                controls.append(post_control(_('edit'), edit_url))\r
+            elif post_type == 'question' and user.can_retag_questions():\r
+                controls.append(post_control(_('retag'), edit_url))\r
+        except:\r
+            pass\r
 \r
         if post_type == 'question':\r
             if post.nis.closed and user.can_reopen_question(post):\r
@@ -142,7 +161,7 @@ def post_controls(post, user):
         \r
         if post.node_type == "answer" and user.can_convert_to_question(post):\r
             menu.append(post_control(_('convert to question'), reverse('convert_to_question', kwargs={'id': post.id}),\r
-                        command=True, withprompt=True))\r
+                        command=False, confirm=True))\r
 \r
         if user.is_superuser or user.is_staff:\r
             plain_text = strip_tags(post.html)\r
@@ -163,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
@@ -192,24 +211,37 @@ 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
+    total = len(all_comments)\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
         'min_length': settings.FORM_MIN_COMMENT_BODY,\r
         'show_gravatar': settings.FORM_GRAVATAR_IN_COMMENTS,\r
         'showing': showing,\r
-        'total': len(all_comments),\r
+        'total': total,\r
+        'more_comments_count' : int(total - showing),\r
         'user': user,\r
     }\r
 \r
 \r
 @register.inclusion_tag("node/contributors_info.html")\r
-def contributors_info(node):\r
+def contributors_info(node, verb=None):\r
     return {\r
-        'node_verb': (node.node_type == "question") and _("asked") or (\r
-                    (node.node_type == "answer") and _("answered") or _("posted")),\r
+        'node_verb': verb and verb or ((node.node_type == "question") and _("asked") or (\r
+                    (node.node_type == "answer") and _("answered") or _("posted"))),\r
         'node': node,\r
     }\r
 \r