From: jordan Date: Thu, 7 Jul 2011 15:28:31 +0000 (+0000) Subject: Improving the canned comments feature, now we can use Django style template syntax... X-Git-Tag: live~202 X-Git-Url: https://git.openstreetmap.org/osqa.git/commitdiff_plain/9a977e5ab9fbc074e28aeb85c90a8707ffd66158 Improving the canned comments feature, now we can use Django style template syntax when preparing the canned items. Access to the current post and site settings is provided. Also, the AJAX popup has been replaced with a menu list. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1111 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/settings/moderation.py b/forum/settings/moderation.py index 19763b4..d6f1b3d 100644 --- a/forum/settings/moderation.py +++ b/forum/settings/moderation.py @@ -18,7 +18,11 @@ CANNED_COMMENTS = Setting('CANNED_COMMENTS', ], MODERATION_SET, dict( label = _("Canned comments"), -help_text = _("Create some canned comments to be used for easier moderation."), +help_text = _(""" +

Create some canned comments to be used for easier moderation. You can access the {{ post }} and {{ settings }} variables.

+

If you want to access the current post author username you can use {{ post.author }}, for the question title use {{ post.title }}.

+

To get the application title use {{ settings.APP_TITLE }}. All settings are accessible through the settings object.

+"""), widget=StringListWidget)) FLAG_TYPES = Setting('FLAG_TYPES', diff --git a/forum/skins/default/media/js/osqa.main.js b/forum/skins/default/media/js/osqa.main.js index 8a3dbf9..0c532e3 100644 --- a/forum/skins/default/media/js/osqa.main.js +++ b/forum/skins/default/media/js/osqa.main.js @@ -2,6 +2,7 @@ * We do not want the CSRF protection enabled for the AJAX post requests, it causes only trouble. * Get the csrftoken cookie and pass it to the X-CSRFToken HTTP request property. */ + $('html').ajaxSend(function(event, xhr, settings) { function getCookie(name) { var cookieValue = null; @@ -24,6 +25,10 @@ $('html').ajaxSend(function(event, xhr, settings) { } }); +function canned_comment(post_id, comment) { + $('#comment-' + post_id + '-form textarea').val(comment); +} + var response_commands = { refresh_page: function() { window.location.reload(true) @@ -123,10 +128,6 @@ 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); @@ -732,7 +733,7 @@ function pickedTags(){ tag_link.attr('rel','tag'); tag_link.attr('href', scriptUrl + $.i18n._('tags/') + tagname + '/'); tag_link.html(tagname); - var del_link = $(''); + var del_link = $(''); del_link.addClass('delete-icon'); del_link.attr('src', mediaUrl('media/images/close-small-dark.png')); diff --git a/forum/skins/default/templates/node/canned_comments.html b/forum/skins/default/templates/node/canned_comments.html deleted file mode 100644 index 356f83f..0000000 --- a/forum/skins/default/templates/node/canned_comments.html +++ /dev/null @@ -1,26 +0,0 @@ -{% load i18n %} - - -

{% trans "Choose from the canned comments." %}

- -

- - - {% for comment in canned_comments %} - - - - - {% endfor %} -
- -
-

\ 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 f67e079..41a97aa 100644 --- a/forum/skins/default/templates/node/comments.html +++ b/forum/skins/default/templates/node/comments.html @@ -65,7 +65,16 @@
{% if user.can_use_canned_comments %}
- {% trans "Use canned comment" %} + + {% trans "Use canned comment" %} + +
{% endif %} diff --git a/forum/templatetags/node_tags.py b/forum/templatetags/node_tags.py index c7fcba0..4eebaf7 100644 --- a/forum/templatetags/node_tags.py +++ b/forum/templatetags/node_tags.py @@ -2,6 +2,7 @@ from datetime import datetime, timedelta import re from forum.models import Question, Action +from django.template import Template, Context from django.utils.translation import ungettext, ugettext as _ from django.utils.html import strip_tags from django.utils.encoding import smart_unicode @@ -203,8 +204,19 @@ def comments(post, user): context.update(dict(c.__dict__)) comments.append(context) + # Generate canned comments + canned_comments = [] + for comment in settings.CANNED_COMMENTS: + t = Template(smart_unicode(comment)) + c = Context({ + 'post' : post, + 'settings' : settings, + }) + canned_comments.append(t.render(c)) + return { 'comments': comments, + 'canned_comments': canned_comments, 'post': post, 'can_comment': user.can_comment(post), 'max_length': settings.FORM_MAX_COMMENT_BODY, diff --git a/forum/urls.py b/forum/urls.py index 0168b8e..a6c496d 100644 --- a/forum/urls.py +++ b/forum/urls.py @@ -46,7 +46,6 @@ core_urls = ( url(r'^%s(?P\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\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'), diff --git a/forum/views/commands.py b/forum/views/commands.py index 95895e3..0e01086 100644 --- a/forum/views/commands.py +++ b/forum/views/commands.py @@ -493,31 +493,6 @@ 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