]> git.openstreetmap.org Git - osqa.git/commitdiff
OSQA-719, implements a new feature that allows administrators and moderators to manag...
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 5 Jul 2011 16:48:22 +0000 (16:48 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 5 Jul 2011 16:48:22 +0000 (16:48 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1102 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/models/user.py
forum/settings/moderation.py
forum/skins/default/media/js/osqa.main.js
forum/skins/default/templates/node/canned_comments.html [new file with mode: 0644]
forum/skins/default/templates/node/comments.html
forum/urls.py
forum/views/commands.py

index e73244dc4a943b2050e58aeb343025ec2e0ff951..6ee7f663918b84674ad10ae7e7d46ad860adb261 100644 (file)
@@ -259,6 +259,14 @@ class User(BaseModel, DjangoUser):
         
         return votes_today
     
+    def can_use_canned_comments(self):
+        # The canned comments feature is available only for admins and moderators,
+        # and only if the "Use canned comments" setting is activated in the administration.
+        if (self.is_superuser or self.is_staff) and settings.USE_CANNED_COMMENTS:
+            return True
+        else:
+            return False
+
     @true_if_is_super_or_staff
     def can_view_deleted_post(self, post):
         return post.author == self
index 6af54017c07dcba355f0a77e7b87e868314488e4..19763b40cd27a914c5866f44c12268bdef507768 100644 (file)
@@ -1,11 +1,26 @@
 from base import Setting, SettingSet
 from forms import StringListWidget
 
+from django.utils.encoding import smart_unicode
 from django.utils.translation import ugettext_lazy as _
 from django.forms.widgets import Textarea
 
 MODERATION_SET = SettingSet('moderation', _('Moderation settings'), _("Define the moderation workflow of your site"), 100)
 
+USE_CANNED_COMMENTS = Setting('USE_CANNED_COMMENTS', True, MODERATION_SET, dict(
+label = _("Use canned comments"),
+help_text = _("If you check, the canned comments feature will be activated, allowing moderators to use canned patterns for their comments."),
+required=False))
+
+CANNED_COMMENTS = Setting('CANNED_COMMENTS',
+[
+"We require all postings to have a clear, specific QUESTION in the title field. Please edit this right away to rephrase the title as a proper question.",
+],
+MODERATION_SET, dict(
+label = _("Canned comments"),
+help_text = _("Create some canned comments to be used for easier moderation."),
+widget=StringListWidget))
+
 FLAG_TYPES = Setting('FLAG_TYPES',
 ["Spam", "Advertising", "Offensive, Abusive, or Inappropriate", "Content violates terms of use", "Copyright Violation",
  "Misleading", "Someone is not being nice", "Not relevant/off-topic", "Other"],
index 993407b769e1feda0502122e3cee42f213a29910..8a3dbf9a44b227e90cd333e4404fd95a0ded063b 100644 (file)
@@ -123,6 +123,10 @@ var response_commands = {
         $('#comment-' + comment_id).slideDown('slow');\r
     },\r
 \r
+    canned_comment: function(post_id, comment) {\r
+        $('#comment-' + post_id + '-form textarea').val(comment);\r
+    },\r
+\r
     update_comment: function(comment_id, comment_text) {\r
         var $comment = $('#comment-' + comment_id);\r
         $comment.find('.comment-text').html(comment_text);\r
diff --git a/forum/skins/default/templates/node/canned_comments.html b/forum/skins/default/templates/node/canned_comments.html
new file mode 100644 (file)
index 0000000..87296fc
--- /dev/null
@@ -0,0 +1,26 @@
+{% load i18n %}
+<style type="text/css">
+    table.canned_comments {
+        font-size: 13px;
+    }
+    table.canned_comments td {
+        vertical-align: top;
+        padding: 0 0 5px 3px;
+    }
+</style>
+
+<p>{% trans "Choose from the canned comments." %}</p>
+
+<p>
+<input type="hidden" name="comment" id="hidden_comment_wrapper" value="" />
+<table class="canned_comments" cellpadding="0" cellspacing="0">
+    {% for comment in canned_comments %}
+    <tr>
+        <td><input type="radio" name="comment_radio" onchange="document.getElementById('hidden_comment_wrapper').value=this.value" id="canned_comment_{{ forloop.counter }}" value="{{ comment }}" /></td>
+        <td>
+            <label for="canned_comment_{{ forloop.counter }}">{{ comment }}</label>
+        </td>
+    </tr>
+    {% endfor %}
+</table>
+</p>
\ No newline at end of file
index 25f04b699fa56db900527e939cced436f222c63b..f67e079e93512639c901f6dfae3be1379b8cebc5 100644 (file)
@@ -52,7 +52,7 @@
     <form id="comment-{{ post.id }}-form" method="post" action="{% url comment id=post.id %}" accept-charset="utf-8">\r
         {% csrf_token %}\r
         <div class="comment-form-widgets-container">\r
-            <textarea name="comment" class="commentBox"></textarea>\r
+            <textarea name="comment" class="commentBox" id="comment"></textarea>\r
             <div class="comment-form-buttons">\r
                 <span id="comment-{{ post.id }}-chars-left" class="comment-chars-left">\r
                     <span class="comments-char-left-count">{{ min_length }}|{{ max_length }}</span>\r
                 <input type="submit" class="comment-submit" value="{% trans " comment" %}" />\r
                 <input type="submit" class="comment-cancel" value="{% trans " cancel" %}" />\r
             </div>\r
+            <div class="clear"></div>\r
+            {% if user.can_use_canned_comments %}\r
+            <div class="canned_comment">\r
+                <a href="{% url canned_comments post.id %}" class="ajax-command withprompt">{% trans "Use canned comment" %}</a>\r
+            </div>\r
+            {% endif %}\r
         </div>\r
         <script type="text/html" class="new-comment-skeleton" id="new-comment-skeleton-{{ post.id }}">\r
             <div class="comment{% if not comment.top_scorer %} not_top_scorer{% endif %}" id="comment-%ID%">\r
index 5485379f1cb0d8008066421fa81a97e354a3ec30..0168b8efb114309fdad957edd0c805f9f25b9a58 100644 (file)
@@ -46,8 +46,9 @@ core_urls = (
     url(r'^%s(?P<id>\d+)/$' % _('revisions/'), app.readers.revisions, name='revisions'),
     url(r'^%s$' % _('questions/'), app.readers.questions, name='questions'),
     url(r'^%s%s$' % (_('questions/'), _('ask/')), app.writers.ask, name='ask'),
+    url(r'^canned_comments/(?P<post_id>\d+)/$', app.commands.canned_comments, name='canned_comments'),
     url(r'^%s%s$' % (_('questions/'), _('related_questions/')), app.commands.related_questions, name='related_questions'),
-    
+
     url(r'^%s%s$' % (_('questions/'), _('unanswered/')), app.readers.unanswered, name='unanswered'),
     url(r'^%s(?P<mode>[\w\-]+)/(?P<user>\d+)/(?P<slug>.*)/$' % _('questions/'), app.readers.user_questions, name='user_questions'),
     
index 0e0108670a8cf016c17705509b3c910a197fd3e9..95895e382a92b072cc97520d1b6a893df57d4a4d 100644 (file)
@@ -493,6 +493,31 @@ def subscribe(request, id, user=None):
         }
     }
 
+@decorate.withfn(command)
+def canned_comments(request, post_id):
+    user = request.user
+
+    # Check whether the user has the required permissions to use the tool.
+    if not user.can_use_canned_comments:
+        raise CommandException(_("You cannot use the canned comments tool."))
+
+    if not request.POST:
+        canned_comments = []
+        for comment in settings.CANNED_COMMENTS:
+            canned_comments.append(smart_unicode(comment))
+
+        return render_to_response('node/canned_comments.html', {
+            'canned_comments' : canned_comments,
+        }, RequestContext(request))
+
+    comment = request.POST.get('comment', '')
+
+    return {
+        'commands' : {
+            'canned_comment' : [post_id, comment],
+        }
+    }
+
 #internally grouped views - used by the tagging system
 @ajax_login_required
 def mark_tag(request, tag=None, **kwargs):#tagging system