# HG changeset patch # User Brian Neal # Date 1253988237 0 # Node ID 07be3e39e63990905ba296728d97f16eea1c2513 # Parent 80ab249d1adc1f3cd755a3ccc5fcc40a2e19b09c Forums: implemented topic level moderator controls. diff -r 80ab249d1adc -r 07be3e39e639 gpp/forums/urls.py --- a/gpp/forums/urls.py Sat Sep 26 03:55:50 2009 +0000 +++ b/gpp/forums/urls.py Sat Sep 26 18:03:57 2009 +0000 @@ -12,6 +12,9 @@ url(r'^flag-post/$', 'flag_post', name='forums-flag_post'), url(r'^forum/(?P[\w\d-]+)/$', 'forum_index', name='forums-forum_index'), url(r'^forum/(?P[\w\d-]+)/new-topic/$', 'new_topic', name='forums-new_topic'), + url(r'^mod/topic/lock/(\d+)/$', 'mod_topic_lock', name='forums-mod_topic_lock'), + url(r'^mod/topic/stick/(\d+)/$', 'mod_topic_stick', name='forums-mod_topic_stick'), + url(r'^mod/topic/delete/(\d+)/$', 'mod_topic_delete', name='forums-mod_topic_delete'), url(r'^post/(\d+)/$', 'goto_post', name='forums-goto_post'), url(r'^post/new/(?P\d+)/$', 'new_post', name='forums-new_post'), url(r'^quick-reply/$', 'quick_reply_ajax', name='forums-quick_reply'), diff -r 80ab249d1adc -r 07be3e39e639 gpp/forums/views.py --- a/gpp/forums/views.py Sat Sep 26 03:55:50 2009 +0000 +++ b/gpp/forums/views.py Sat Sep 26 18:03:57 2009 +0000 @@ -112,9 +112,7 @@ # we do this for the template since it is rendered twice page_nav = render_to_string('forums/pagination.html', {'page': page}) - can_moderate = request.user.is_authenticated() and ( - request.user.is_superuser or \ - request.user in topic.forum.moderators.all()) + can_moderate = _can_moderate(topic.forum, request.user) can_reply = request.user.is_authenticated() and ( not topic.locked or can_moderate) @@ -248,9 +246,7 @@ """ post = get_object_or_404(Post.objects.select_related(), pk=id) - can_moderate = request.user.is_superuser or \ - request.user in post.topic.forum.moderators.all() - + can_moderate = _can_moderate(post.topic.forum, request.user) can_edit = can_moderate or request.user == post.user if not can_edit: @@ -391,6 +387,56 @@ context_instance=RequestContext(request)) +@login_required +def mod_topic_stick(request, id): + """ + This view function is for moderators to toggle the sticky status of a topic. + """ + topic = get_object_or_404(Topic.objects.select_related(), pk=id) + if _can_moderate(topic.forum, request.user): + topic.sticky = not topic.sticky + topic.save() + return HttpResponseRedirect(topic.get_absolute_url()) + + return HttpResponseForbidden() + + +@login_required +def mod_topic_lock(request, id): + """ + This view function is for moderators to toggle the locked status of a topic. + """ + topic = get_object_or_404(Topic.objects.select_related(), pk=id) + if _can_moderate(topic.forum, request.user): + topic.locked = not topic.locked + topic.save() + return HttpResponseRedirect(topic.get_absolute_url()) + + return HttpResponseForbidden() + + +@login_required +def mod_topic_delete(request, id): + """ + This view function is for moderators to delete an entire topic. + """ + topic = get_object_or_404(Topic.objects.select_related(), pk=id) + if _can_moderate(topic.forum, request.user): + forum_url = topic.forum.get_absolute_url() + _delete_topic(topic) + return HttpResponseRedirect(forum_url) + + return HttpResponseForbidden() + + +def _can_moderate(forum, user): + """ + Determines if a user has permission to moderate a given forum. + """ + return user.is_authenticated() and ( + user.is_superuser or user in forum.moderators.all()) + + def _can_post_in_topic(topic, user): """ This function returns true if the given user can post in the given topic diff -r 80ab249d1adc -r 07be3e39e639 gpp/templates/forums/topic.html --- a/gpp/templates/forums/topic.html Sat Sep 26 03:55:50 2009 +0000 +++ b/gpp/templates/forums/topic.html Sat Sep 26 18:03:57 2009 +0000 @@ -34,6 +34,19 @@ {% endfor %} {{ page_nav }} +{% if can_moderate %} +
+
+ +
+
+ +
+
+ +
+
+{% endif %} {% if last_page and can_reply %} diff -r 80ab249d1adc -r 07be3e39e639 media/css/base.css --- a/media/css/base.css Sat Sep 26 03:55:50 2009 +0000 +++ b/media/css/base.css Sat Sep 26 18:03:57 2009 +0000 @@ -242,3 +242,6 @@ float: left; margin-right: 3px; } +div.forum-mod-controls form { + display:inline; +} diff -r 80ab249d1adc -r 07be3e39e639 media/js/forums.js --- a/media/js/forums.js Sat Sep 26 03:55:50 2009 +0000 +++ b/media/js/forums.js Sat Sep 26 18:03:57 2009 +0000 @@ -78,5 +78,9 @@ } return false; }); + $('#forum-mod-del-topic').click(function () { + return confirm('Are you sure you want to delete this topic?\n' + + 'WARNING: all posts will be lost.'); + }); $('#id_body').markItUp(mySettings); });