# HG changeset patch # User Brian Neal # Date 1253996385 0 # Node ID c329bfaed4a766f427f07cf4ce167257ee2c6e8d # Parent 07be3e39e63990905ba296728d97f16eea1c2513 Forums: implemented the move topic feature. diff -r 07be3e39e639 -r c329bfaed4a7 gpp/forums/forms.py --- a/gpp/forums/forms.py Sat Sep 26 18:03:57 2009 +0000 +++ b/gpp/forums/forms.py Sat Sep 26 20:19:45 2009 +0000 @@ -4,6 +4,7 @@ from django import forms from django.conf import settings +from forums.models import Forum from forums.models import Topic from forums.models import Post @@ -105,3 +106,17 @@ } js = settings.GPP_THIRD_PARTY_JS['markitup'] + \ ('js/forums.js', ) + + +class MoveTopicForm(forms.Form): + """ + Form for a moderator to move a topic to a forum. + """ + forums = forms.ModelChoiceField(label='Move to forum', + queryset=Forum.objects.none()) + + def __init__(self, user, *args, **kwargs): + super(MoveTopicForm, self).__init__(*args, **kwargs) + self.fields['forums'].queryset = \ + Forum.objects.forums_for_user(user).order_by('name') + diff -r 07be3e39e639 -r c329bfaed4a7 gpp/forums/urls.py --- a/gpp/forums/urls.py Sat Sep 26 18:03:57 2009 +0000 +++ b/gpp/forums/urls.py Sat Sep 26 20:19:45 2009 +0000 @@ -12,9 +12,10 @@ 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/delete/(\d+)/$', 'mod_topic_delete', name='forums-mod_topic_delete'), url(r'^mod/topic/lock/(\d+)/$', 'mod_topic_lock', name='forums-mod_topic_lock'), + url(r'^mod/topic/move/(\d+)/$', 'mod_topic_move', name='forums-mod_topic_move'), 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 07be3e39e639 -r c329bfaed4a7 gpp/forums/views.py --- a/gpp/forums/views.py Sat Sep 26 18:03:57 2009 +0000 +++ b/gpp/forums/views.py Sat Sep 26 20:19:45 2009 +0000 @@ -22,7 +22,7 @@ from forums.models import Topic from forums.models import Post from forums.models import FlaggedPost -from forums.forms import NewTopicForm, NewPostForm, PostForm +from forums.forms import NewTopicForm, NewPostForm, PostForm, MoveTopicForm ####################################################################### @@ -398,7 +398,7 @@ topic.save() return HttpResponseRedirect(topic.get_absolute_url()) - return HttpResponseForbidden() + return HttpResponseForbidden() @login_required @@ -412,7 +412,7 @@ topic.save() return HttpResponseRedirect(topic.get_absolute_url()) - return HttpResponseForbidden() + return HttpResponseForbidden() @login_required @@ -426,7 +426,44 @@ _delete_topic(topic) return HttpResponseRedirect(forum_url) - return HttpResponseForbidden() + return HttpResponseForbidden() + + +@login_required +def mod_topic_move(request, id): + """ + This view function is for moderators to move a topic to a different forum. + """ + topic = get_object_or_404(Topic.objects.select_related(), pk=id) + if not _can_moderate(topic.forum, request.user): + return HttpResponseForbidden() + + if request.method == 'POST': + form = MoveTopicForm(request.user, request.POST) + if form.is_valid(): + new_forum = form.cleaned_data['forums'] + old_forum = topic.forum + if new_forum != old_forum: + topic.forum = new_forum + topic.save() + # Have to adjust foreign keys to last_post, denormalized counts, etc.: + old_forum.topic_count_update() + old_forum.post_count_update() + old_forum.save() + new_forum.topic_count_update() + new_forum.post_count_update() + new_forum.save() + + return HttpResponseRedirect(topic.get_absolute_url()) + else: + form = MoveTopicForm(request.user) + + return render_to_response('forums/move_topic.html', { + 'forum': topic.forum, + 'topic': topic, + 'form': form, + }, + context_instance=RequestContext(request)) def _can_moderate(forum, user): diff -r 07be3e39e639 -r c329bfaed4a7 gpp/templates/forums/move_topic.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/forums/move_topic.html Sat Sep 26 20:19:45 2009 +0000 @@ -0,0 +1,21 @@ +{% extends 'base.html' %} +{% block title %}Forums: Move Topic{% endblock %} +{% block content %} +

Forums: Move Topic

+ +

+ SurfGuitar101 Forum Index » + {{ forum.name }} » + {{ topic.name }} +

+ +
+
+
+Move Topic: {{ topic.name }} + {{ form.as_p }} + +
+
+
+{% endblock %} diff -r 07be3e39e639 -r c329bfaed4a7 gpp/templates/forums/topic.html --- a/gpp/templates/forums/topic.html Sat Sep 26 18:03:57 2009 +0000 +++ b/gpp/templates/forums/topic.html Sat Sep 26 20:19:45 2009 +0000 @@ -45,6 +45,8 @@
+ Move Topic + Move this topic {% endif %} diff -r 07be3e39e639 -r c329bfaed4a7 media/icons/application_go.png Binary file media/icons/application_go.png has changed