Commits

Anonymous committed 9f1533c

moderation fix

Comments (0)

Files changed (1)

djangobb_forum/views.py

 from django.utils import translation
 from django.utils.encoding import smart_str
 from django.views.decorators.http import require_POST
-
+from django.contrib import messages
+from django.utils.translation import ugettext, ugettext_lazy as _
 from djangobb_forum.util import render_to, paged, build_form, paginate, set_language
 from djangobb_forum.models import Category, Forum, Topic, Post, Profile, Reputation,\
     Report, PrivateMessage, Attachment, PostTracking
 def moderate(request, forum_id):
     forum = get_object_or_404(Forum, pk=forum_id)
     topics = forum.topics.order_by('-sticky', '-updated').select_related()
+
     if request.user.is_superuser or request.user in forum.moderators.all():
-        topic_ids = request.POST.getlist('topic_id')
-        if 'move_topics' in request.POST:
-            return {
-                'categories': Category.objects.all(),
-                'topic_ids': topic_ids,
-                'exclude_forum': forum,
-                'TEMPLATE': 'forum/move_topic.html'
-            }
-        elif 'delete_topics' in request.POST:
-            for topic_id in topic_ids:
-                topic = get_object_or_404(Topic, pk=topic_id)
-                topic.delete()
-            return HttpResponseRedirect(reverse('djangobb:index'))
-        elif 'open_topics' in request.POST:
-            for topic_id in topic_ids:
-                open_close_topic(request, topic_id)
-            return HttpResponseRedirect(reverse('djangobb:index'))
-        elif 'close_topics' in request.POST:
-            for topic_id in topic_ids:
-                open_close_topic(request, topic_id)
-            return HttpResponseRedirect(reverse('djangobb:index'))
-
+        if request.method == "POST":
+            topic_ids = request.POST.getlist('topic_id')
+            if topic_ids:
+                if 'move_topics' in request.POST:
+                    return {
+                        'categories': Category.objects.all(),
+                        'topic_ids': topic_ids,
+                        'exclude_forum': forum,
+                        'TEMPLATE': 'forum/move_topic.html'
+                    }
+                elif 'delete_topics' in request.POST:
+                    for topic_id in topic_ids:
+                        topic = get_object_or_404(Topic, pk=topic_id)
+                        topic.delete()
+                    return HttpResponseRedirect(reverse('djangobb:index'))
+                elif 'open_topics' in request.POST:
+                    for topic_id in topic_ids:
+                        open_close_topic(request, topic_id)
+                    return HttpResponseRedirect(reverse('djangobb:index'))
+                elif 'close_topics' in request.POST:
+                    for topic_id in topic_ids:
+                        open_close_topic(request, topic_id)
+                    return HttpResponseRedirect(reverse('djangobb:index'))
+            else:
+                messages.error(request, _("You have to select at least one topic"))
+                
         return {'forum': forum,
                 'topics': topics,
                 #'sticky_topics': forum.topics.filter(sticky=True),