예제 #1
0
def base_move_thread(request, forum, thread, template):
    """
    Does the work to move a thread
    """

    # find all forums in which this user is allowed to start threads
    postable = Forum.objects.active().exclude(pk=forum.id)
    postable = postable.filter(is_category=False)
    valid = []
    error = None
    for f in postable:
        perms = get_user_permissions(request.user, f)
        if perms["start_threads"]:
            valid.append(f)

    if request.method == "POST":
        forum_id = int(request.POST.get("move_to_forum", 0))
        f = Forum.objects.get(pk=forum_id)
        if f in postable:
            # reduce counts
            for p in thread.forum.hierarchy:
                p.thread_count -= 1
                p.post_count -= thread.posts.count() - 1
                p.save()

                # TODO: look into updating the last post if the moving thread
                # was the last post in this forum

            # move the thread
            thread.forum = f
            thread.save()

            # update counts again
            for n in thread.forum.hierarchy:
                n.thread_count += 1
                n.post_count += thread.posts.count() + 1

                if not n.last_post or n.last_post.date_created < thread.date_created:
                    n.last_post = thread

                n.save()

            return HttpResponseRedirect(thread.get_absolute_url())
        else:
            error = _("Invalid forum!")

    data = {"forum": forum, "thread": thread, "valid_forums": valid, "error": error}

    return render(request, template, data)
예제 #2
0
 def render(self, context):
     forum = self.forum.resolve(context)
     user = context.get('user', None)
     if user:
         context[self.variable] = get_user_permissions(user, forum)
     return ''