From 3ba9e8fa774dcb586990f71986d8618631f3e5b1 Mon Sep 17 00:00:00 2001
From: jordan
Date: Tue, 5 Jul 2011 16:48:22 +0000
Subject: [PATCH] OSQA-719, implements a new feature that allows administrators
and moderators to manage and use canned comments. This tool can be
deactivated in the administration on the Moderation Settings page (the canned
comments are also managed there)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1102 0cfe37f9-358a-4d5e-be75-b63607b5c754
---
forum/models/user.py | 8 ++++++
forum/settings/moderation.py | 15 +++++++++++
forum/skins/default/media/js/osqa.main.js | 4 +++
.../templates/node/canned_comments.html | 26 +++++++++++++++++++
.../default/templates/node/comments.html | 8 +++++-
forum/urls.py | 3 ++-
forum/views/commands.py | 25 ++++++++++++++++++
7 files changed, 87 insertions(+), 2 deletions(-)
create mode 100644 forum/skins/default/templates/node/canned_comments.html
diff --git a/forum/models/user.py b/forum/models/user.py
index e73244d..6ee7f66 100644
--- a/forum/models/user.py
+++ b/forum/models/user.py
@@ -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
diff --git a/forum/settings/moderation.py b/forum/settings/moderation.py
index 6af5401..19763b4 100644
--- a/forum/settings/moderation.py
+++ b/forum/settings/moderation.py
@@ -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"],
diff --git a/forum/skins/default/media/js/osqa.main.js b/forum/skins/default/media/js/osqa.main.js
index 993407b..8a3dbf9 100644
--- a/forum/skins/default/media/js/osqa.main.js
+++ b/forum/skins/default/media/js/osqa.main.js
@@ -123,6 +123,10 @@ var response_commands = {
$('#comment-' + comment_id).slideDown('slow');
},
+ canned_comment: function(post_id, comment) {
+ $('#comment-' + post_id + '-form textarea').val(comment);
+ },
+
update_comment: function(comment_id, comment_text) {
var $comment = $('#comment-' + comment_id);
$comment.find('.comment-text').html(comment_text);
diff --git a/forum/skins/default/templates/node/canned_comments.html b/forum/skins/default/templates/node/canned_comments.html
new file mode 100644
index 0000000..87296fc
--- /dev/null
+++ b/forum/skins/default/templates/node/canned_comments.html
@@ -0,0 +1,26 @@
+{% load i18n %}
+
+
+{% trans "Choose from the canned comments." %}
+
+
+
+
+
\ No newline at end of file
diff --git a/forum/skins/default/templates/node/comments.html b/forum/skins/default/templates/node/comments.html
index 25f04b6..f67e079 100644
--- a/forum/skins/default/templates/node/comments.html
+++ b/forum/skins/default/templates/node/comments.html
@@ -52,7 +52,7 @@