Example #1
0
def move_topic(request):
    if 'topic_id' in request.GET:
        #if move only 1 topic
        topic_ids = [request.GET['topic_id']]
    else:
        topic_ids = request.POST.getlist('topic_id')
    first_topic = topic_ids[0]
    topic = get_object_or_404(Topic, pk=first_topic)
    from_forum = topic.forum
    if 'to_forum' in request.POST:
        to_forum_id = int(request.POST['to_forum'])
        to_forum = get_object_or_404(Forum, pk=to_forum_id)
        for topic_id in topic_ids:
            topic = get_object_or_404(Topic, pk=topic_id)
            if topic.forum != to_forum:
                if forum_moderated_by(topic, request.user):
                    topic.forum = to_forum
                    topic.save()

        #TODO: not DRY
        try:
            last_post = Post.objects.filter(topic__forum__id=from_forum.id).latest()
        except Post.DoesNotExist:
            last_post = None
        from_forum.last_post = last_post
        from_forum.topic_count = from_forum.topics.count()
        from_forum.post_count = from_forum.posts.count()
        from_forum.save()
        return HttpResponseRedirect(to_forum.get_absolute_url())

    return {'categories': Category.objects.all(),
            'topic_ids': topic_ids,
            'exclude_forum': from_forum,
            }
Example #2
0
def prepare_move_topic(request, topic_id):
    topic = get_object_or_404(Topic, pk=topic_id)
    if forum_moderated_by(topic, request.user):
        allforums = Forum.objects.all().exclude(id__in=[topic.forum_id])
        data = ['%i#%s' % (f.id, f.translation.title) for f in allforums]
        return JsonResponse({'stat' : 'OK', 'data' : data})
    else:
        return JsonResponse({'stat' : 'FAIL',
                             'msg' : ugettext('you are not moderator of this topic')})
Example #3
0
def open_close_topic(request, topic_id, action):

    topic = get_object_or_404(Topic, pk=topic_id)
    if forum_moderated_by(topic, request.user):
        if action == 'c':
            topic.closed = True
        elif action == 'o':
            topic.closed = False
        topic.save()
    return HttpResponseRedirect(topic.get_absolute_url())
Example #4
0
def stick_unstick_topic(request, topic_id, action):

    topic = get_object_or_404(Topic, pk=topic_id)
    if forum_moderated_by(topic, request.user):
        if action == 's':
            topic.sticky = True
        elif action == 'u':
            topic.sticky = False
        topic.save()
    return HttpResponseRedirect(topic.get_absolute_url())
Example #5
0
def open_close_topic(request, topic_id):
    topic = get_object_or_404(Topic, pk=topic_id)
    if forum_moderated_by(topic, request.user):
        topic.closed = not topic.closed
        topic.save()
        if topic.closed:
            return JsonResponse({'stat' : 'OK', 'msg' : ugettext('Open topic')})
        else:
            return JsonResponse({'stat' : 'OK', 'msg' : ugettext('Close topic')})
    else:
        return JsonResponse({'stat' : 'FAIL',
                             'msg' : ugettext('you are not moderator of this topic')})
Example #6
0
def stick_unstick_topic(request, topic_id):
    topic = get_object_or_404(Topic, pk=topic_id)
    if forum_moderated_by(topic, request.user):
        topic.sticky = not topic.sticky
        topic.save()
        if topic.sticky:
            return JsonResponse({'stat' : 'OK', 'msg' : ugettext('Unstick topic')})
        else:
            return JsonResponse({'stat' : 'OK', 'msg' : ugettext('Stick topic')})
    else:
        return JsonResponse({'stat' : 'FAIL',
                             'msg' : ugettext('you are not moderator of this topic')})
Example #7
0
def move_topic(request, topic_id):
    topic = get_object_or_404(Topic, pk=topic_id)
    if forum_moderated_by(topic, request.user):
        forum = get_object_or_404(Forum, pk=request.POST['forum_id'])
        topic.forum = forum
        topic.save()
        return JsonResponse({'stat' : 'OK',
                             'msg' : '%s %s' % (ugettext('Forum moved to'), forum),
                             'redir' : forum.get_absolute_url()})
    else:
        return JsonResponse({'stat' : 'FAIL',
                             'msg' : ugettext('you are not moderator of this topic')})
Example #8
0
def prepare_move_topic(request, topic_id):
    topic = get_object_or_404(Topic, pk=topic_id)
    if forum_moderated_by(topic, request.user):
        allforums = Forum.objects.all().exclude(id__in=[topic.forum_id])
        data = ['%i#%s' % (f.id, f.translation.title) for f in allforums]
        return JsonResponse({'stat': 'OK', 'data': data})
    else:
        return JsonResponse({
            'stat':
            'FAIL',
            'msg':
            ugettext('you are not moderator of this topic')
        })
Example #9
0
def open_close_topic(request, topic_id):
    topic = get_object_or_404(Topic, pk=topic_id)
    if forum_moderated_by(topic, request.user):
        topic.closed = not topic.closed
        topic.save()
        if topic.closed:
            return JsonResponse({'stat': 'OK', 'msg': ugettext('Open topic')})
        else:
            return JsonResponse({'stat': 'OK', 'msg': ugettext('Close topic')})
    else:
        return JsonResponse({
            'stat':
            'FAIL',
            'msg':
            ugettext('you are not moderator of this topic')
        })
Example #10
0
def stick_unstick_topic(request, topic_id):
    topic = get_object_or_404(Topic, pk=topic_id)
    if forum_moderated_by(topic, request.user):
        topic.sticky = not topic.sticky
        topic.save()
        if topic.sticky:
            return JsonResponse({
                'stat': 'OK',
                'msg': ugettext('Unstick topic')
            })
        else:
            return JsonResponse({'stat': 'OK', 'msg': ugettext('Stick topic')})
    else:
        return JsonResponse({
            'stat':
            'FAIL',
            'msg':
            ugettext('you are not moderator of this topic')
        })
Example #11
0
def move_topic(request, topic_id):
    topic = get_object_or_404(Topic, pk=topic_id)
    if forum_moderated_by(topic, request.user):
        forum = get_object_or_404(Forum, pk=request.POST['forum_id'])
        topic.forum = forum
        topic.save()
        return JsonResponse({
            'stat':
            'OK',
            'msg':
            '%s %s' % (ugettext('Forum moved to'), forum),
            'redir':
            forum.get_absolute_url()
        })
    else:
        return JsonResponse({
            'stat':
            'FAIL',
            'msg':
            ugettext('you are not moderator of this topic')
        })