Mercurial > public > sg101
changeset 109:07be3e39e639
Forums: implemented topic level moderator controls.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 26 Sep 2009 18:03:57 +0000 |
parents | 80ab249d1adc |
children | c329bfaed4a7 |
files | gpp/forums/urls.py gpp/forums/views.py gpp/templates/forums/topic.html media/css/base.css media/js/forums.js |
diffstat | 5 files changed, 75 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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<slug>[\w\d-]+)/$', 'forum_index', name='forums-forum_index'), url(r'^forum/(?P<slug>[\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<topic_id>\d+)/$', 'new_post', name='forums-new_post'), url(r'^quick-reply/$', 'quick_reply_ajax', name='forums-quick_reply'),
--- 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
--- 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 %} </table> {{ page_nav }} +{% if can_moderate %} +<div class="forum-mod-controls"> + <form action="{% url forums-mod_topic_stick topic.id %}" method="post"> + <input type="submit" value="{% if topic.sticky %}Unstick{% else %}Stick{% endif %} Topic" /> + </form> + <form action="{% url forums-mod_topic_lock topic.id %}" method="post"> + <input type="submit" value="{% if topic.locked %}Unlock{% else %}Lock{% endif %} Topic" /> + </form> + <form action="{% url forums-mod_topic_delete topic.id %}" method="post"> + <input type="submit" value="Delete Topic" id="forum-mod-del-topic" /> + </form> +</div> +{% endif %} {% if last_page and can_reply %} <a name="forum-reply-form"></a>
--- 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; +}
--- 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); });