Beispiel #1
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()
    return HttpResponseRedirect(topic.get_absolute_url())
Beispiel #2
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 render(
        request,
        "djangobb_forum/move_topic.html",
        {"categories": Category.objects.all(), "topic_ids": topic_ids, "exclude_forum": from_forum},
    )
Beispiel #3
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()
        messages.success(request, _("Topic moved."))
        return HttpResponseRedirect(to_forum.get_absolute_url())

    return render(request, 'djangobb_forum/move_topic.html', {'categories': Category.objects.all(),
            'topic_ids': topic_ids,
            'exclude_forum': from_forum,
            })
Beispiel #4
0
def make_heresy(request, topic_id):

    topic = get_object_or_404(Topic, pk=topic_id)
    if forum_moderated_by(topic, request.user):
        topic.heresy = not topic.heresy
        topic.save()
    return HttpResponseRedirect(topic.get_absolute_url())
Beispiel #5
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,
            }
Beispiel #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()
    return HttpResponseRedirect(topic.get_absolute_url())
Beispiel #7
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())
Beispiel #8
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())
Beispiel #9
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())
Beispiel #10
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())
Beispiel #11
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
            messages.success(request, _("Topic marked as sticky."))
        elif action == 'u':
            messages.success(request, _("Sticky flag removed from topic."))
            topic.sticky = False
        topic.save()
    return HttpResponseRedirect(topic.get_absolute_url())
Beispiel #12
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) or can_close_topic(request.user, topic):
        if action == 'c':
            topic.closed = True
            messages.success(request, _("Topic closed."))
        elif action == 'o':
            topic.closed = False
            messages.success(request, _("Topic opened."))
        topic.save()
    return HttpResponseRedirect(topic.get_absolute_url())
Beispiel #13
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
            messages.success(request, _("Topic marked as sticky."))
        elif action == 'u':
            messages.success(request, _("Sticky flag removed from topic."))
            topic.sticky = False
        topic.save()
    return HttpResponseRedirect(topic.get_absolute_url())
Beispiel #14
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) or can_close_topic(
            request.user, topic):
        if action == 'c':
            topic.closed = True
            messages.success(request, _("Topic closed."))
        elif action == 'o':
            topic.closed = False
            messages.success(request, _("Topic opened."))
        topic.save()
    return HttpResponseRedirect(topic.get_absolute_url())
Beispiel #15
0
def delete_posts(request, topic_id):

    topic = Topic.objects.select_related().get(pk=topic_id)

    if forum_moderated_by(topic, request.user):
        deleted = False
        post_list = request.POST.getlist('post')
        for post_id in post_list:
            if not deleted:
                deleted = True
            delete_post(request, post_id)
        if deleted:
            return HttpResponseRedirect(topic.get_absolute_url())

    last_post = topic.posts.latest()

    if request.user.is_authenticated():
        topic.update_read(request.user)

    posts = topic.posts.all().select_related()

    profiles = Profile.objects.filter(user__pk__in=set(x.user.id
                                                       for x in posts))
    profiles = dict((x.user_id, x) for x in profiles)

    for post in posts:
        post.user.forum_profile = profiles[post.user.id]

    initial = {}
    if request.user.is_authenticated():
        initial = {'markup': request.user.forum_profile.markup}
    form = AddPostForm(topic=topic, initial=initial)

    moderator = request.user.is_superuser or\
        request.user in topic.forum.moderators.all()
    if request.user.is_authenticated(
    ) and request.user in topic.subscribers.all():
        subscribed = True
    else:
        subscribed = False
    return {
        'topic': topic,
        'last_post': last_post,
        'form': form,
        'moderator': moderator,
        'subscribed': subscribed,
        'paged_qs': posts,
    }
Beispiel #16
0
def delete_posts(request, topic_id):

    topic = Topic.objects.select_related().get(pk=topic_id)

    if forum_moderated_by(topic, request.user):
        deleted = False
        post_list = request.POST.getlist('post')
        for post_id in post_list:
            if not deleted:
                deleted = True
            delete_post(request, post_id)
        if deleted:
            return HttpResponseRedirect(topic.get_absolute_url())

    last_post = topic.posts.latest()

    if request.user.is_authenticated():
        topic.update_read(request.user)

    posts = topic.posts.all().select_related()

    profiles = Profile.objects.filter(user__pk__in=set(x.user.id for x in posts))
    profiles = dict((x.user_id, x) for x in profiles)

    for post in posts:
        post.user.forum_profile = profiles[post.user.id]

    initial = {}
    if request.user.is_authenticated():
        initial = {'markup': request.user.forum_profile.markup}
    form = AddPostForm(topic=topic, initial=initial)

    moderator = request.user.is_superuser or\
        request.user in topic.forum.moderators.all()
    if request.user.is_authenticated() and request.user in topic.subscribers.all():
        subscribed = True
    else:
        subscribed = False
    return {
            'topic': topic,
            'last_post': last_post,
            'form': form,
            'moderator': moderator,
            'subscribed': subscribed,
            'paged_qs': posts,
            }
Beispiel #17
0
def delete_posts(request, topic_id):

    topic = Topic.objects.select_related().get(pk=topic_id)

    if forum_moderated_by(topic, request.user):
        deleted = False
        post_list = request.POST.getlist('post')
        for post_id in post_list:
            if not deleted:
                deleted = True
            delete_post(request, post_id)
        if deleted:
            messages.success(request, _("Post deleted."))
            return HttpResponseRedirect(topic.get_absolute_url())

    last_post = topic.posts.latest()

    if request.user.is_authenticated():
        topic.update_read(request.user)

    posts = topic.posts.all().select_related()

    initial = {}
    if request.user.is_authenticated():
        initial = {'markup': request.user.forum_profile.markup}
    form = AddPostForm(topic=topic,
                       initial=initial,
                       is_ip_banned=request.is_ip_banned)

    moderator = request.user.is_superuser or\
        request.user in topic.forum.moderators.all()
    if request.user.is_authenticated(
    ) and request.user in topic.subscribers.all():
        subscribed = True
    else:
        subscribed = False
    return render(
        request, 'djangobb_forum/delete_posts.html', {
            'topic': topic,
            'last_post': last_post,
            'form': form,
            'moderator': moderator,
            'subscribed': subscribed,
            'posts': posts,
        })
Beispiel #18
0
def delete_posts(request, topic_id):

    topic = Topic.objects.select_related().get(pk=topic_id)

    if forum_moderated_by(topic, request.user):
        deleted = False
        post_list = request.POST.getlist("post")
        for post_id in post_list:
            if not deleted:
                deleted = True
            delete_post(request, post_id)
        if deleted:
            messages.success(request, _("Post deleted."))
            return HttpResponseRedirect(topic.get_absolute_url())

    last_post = topic.posts.latest()

    if request.user.is_authenticated():
        topic.update_read(request.user)

    posts = topic.posts.all().select_related()

    initial = {}
    if request.user.is_authenticated():
        initial = {"markup": request.user.forum_profile.markup}
    form = AddPostForm(topic=topic, initial=initial)

    moderator = request.user.is_superuser or request.user in topic.forum.moderators.all()
    if request.user.is_authenticated() and request.user in topic.subscribers.all():
        subscribed = True
    else:
        subscribed = False
    return render(
        request,
        "djangobb_forum/delete_posts.html",
        {
            "topic": topic,
            "last_post": last_post,
            "form": form,
            "moderator": moderator,
            "subscribed": subscribed,
            "posts": posts,
        },
    )
Beispiel #19
0
def delete_posts(request, topic_id):

    topic = Topic.objects.select_related().get(pk=topic_id)
    topic = paginate(topic, request.GET.get("page", 1),
                     forum_settings.TOPIC_PAGE_SIZE, 10)

    if forum_moderated_by(topic, request.user):
        deleted = False
        post_list = request.POST.getlist('post')
        for post_id in post_list:
            if not deleted:
                deleted = True
            delete_post(request, post_id)
        if deleted:
            messages.success(request, _("Post deleted."))
            return HttpResponseRedirect(topic.get_absolute_url())

    last_post = topic.posts.latest()

    if request.user.is_authenticated():
        topic.update_read(request.user)

    posts = topic.posts.all().select_related()

    initial = {}
    if request.user.is_authenticated():
        initial = {'markup': request.user.forum_profile.markup}
    form = AddPostForm(topic=topic, initial=initial)

    moderator = request.user.is_superuser or\
        request.user in topic.forum.moderators.all()
    if request.user.is_authenticated() and request.user in topic.subscribers.all():
        subscribed = True
    else:
        subscribed = False
    return render(request, 'djangobb_forum/delete_posts.html', {
            'topic': topic,
            'last_post': last_post,
            'form': form,
            'moderator': moderator,
            'subscribed': subscribed,
            'posts': posts,
            })
Beispiel #20
0
def delete_posts(request, topic_id):

    topic = Topic.objects.select_related().get(pk=topic_id)

    if forum_moderated_by(topic, request.user):
        deleted = False
        post_list = request.POST.getlist('post')
        for post_id in post_list:
            if not deleted:
                deleted = True
            delete_post(request, post_id)
        if deleted:
            return HttpResponseRedirect(topic.get_absolute_url())

    last_post = topic.posts.latest()

    if request.user.is_authenticated():
        topic.update_read(request.user)

    posts = topic.posts.all().select_related()

    initial = {}
    if request.user.is_authenticated():
        initial = {'markup': request.user.forum_profile.markup}
    form = AddPostForm(topic=topic, initial=initial)

    moderator = isa_forum_moderator(topic.forum, request.user)
    if request.user.is_authenticated() and request.user in topic.subscribers.all():
        subscribed = True
    else:
        subscribed = False
    return render(request, 'djangobb_forum/delete_posts.html', {
            'topic': topic,
            'last_post': last_post,
            'form': form,
            'moderator': moderator,
            'subscribed': subscribed,
            'posts': posts,
            })
Beispiel #21
0
def move_posts(request, topic_id):

    topic = Topic.objects.select_related().get(pk=topic_id)
    from_forum = topic.forum

    if forum_moderated_by(topic, request.user):
        moved = False
        post_list = request.POST.getlist('post')
        if 'to_topic' in request.POST:
            match = re.match(r'.*?(\d+)', request.POST['to_topic'])
            if match is None:
                messages.error(request, _("The topic ID must be an integer."))
            else:
                to_topic_id = int(match.group(1))
                try:
                    to_topic = Topic.objects.select_related().get(pk=to_topic_id)
                except Topic.DoesNotExist:
                    messages.error(request, _("That thread doesn't exist."))
                else:
                    if 'move_all' in request.POST:
                        Post.objects.filter(topic=topic).update(topic=to_topic)
                        topic.delete()
                        moved = True
                        deleted = True
                    else:
                        for post_id in post_list:
                            if not moved:
                                moved = True
                            post = get_object_or_404(Post, pk=post_id)
                            if post.topic != to_topic:
                                last = (topic.last_post == post)
                                if forum_moderated_by(to_topic, request.user):
                                    post.topic = to_topic
                                    post.save()
                        if Post.objects.filter(topic__id=topic.id).count() == 0:
                            topic.delete()
                            deleted = True
                        else:
                            deleted = False
                            try:
                                topic.last_post = Post.objects.filter(topic__id=topic.id).latest()
                            except Post.DoesNotExist:
                                topic.last_post = None
                            topic.post_count = Post.objects.filter(topic__id=topic.id).count()
                            topic.save()
                    try:
                        from_forum.last_post = Post.objects.filter(topic__forum__id=from_forum.id).latest()
                    except Post.DoesNotExist:
                        from_forum.last_post = None
                    from_forum.post_count = Post.objects.filter(topic__forum__id=from_forum.id).count()
                    from_forum.topic_count = Topic.objects.filter(forum__id=from_forum.id).count()
                    from_forum.save()

                    to_topic.post_count = Post.objects.filter(topic__id=to_topic.id).count()
                    to_topic.save()


                    if moved:
                        messages.success(request, _("Posts moved."))
                        if not deleted:
                            return HttpResponseRedirect(topic.get_absolute_url())
                        else:
                            return HttpResponseRedirect(from_forum.get_absolute_url())

    last_post = topic.posts.latest()

    if request.user.is_authenticated():
        topic.update_read(request.user)

    posts = topic.posts.all().select_related()

    initial = {}
    if request.user.is_authenticated():
        initial = {'markup': request.user.forum_profile.markup}
    form = AddPostForm(topic=topic, initial=initial, is_ip_banned=request.is_ip_banned)

    moderator = request.user.is_superuser or\
        request.user in topic.forum.moderators.all()
    if request.user.is_authenticated() and request.user in topic.subscribers.all():
        subscribed = True
    else:
        subscribed = False
    return render(request, 'djangobb_forum/move_posts.html', {'categories': Category.objects.all(),
            'exclude_topic': from_forum,
            'topic': topic,
            'last_post': last_post,
            'form': form,
            'moderator': moderator,
            'subscribed': subscribed,
            'posts': posts,
            })
Beispiel #22
0
def move_posts(request, topic_id):

    topic = Topic.objects.select_related().get(pk=topic_id)
    from_forum = topic.forum

    if forum_moderated_by(topic, request.user):
        moved = False
        post_list = request.POST.getlist('post')
        if 'to_topic' in request.POST:
            match = re.match(r'.*?(\d+)', request.POST['to_topic'])
            if match is None:
                messages.error(request, _("The topic ID must be an integer."))
            else:
                to_topic_id = int(match.group(1))
                try:
                    to_topic = Topic.objects.select_related().get(
                        pk=to_topic_id)
                except Topic.DoesNotExist:
                    messages.error(request, _("That thread doesn't exist."))
                else:
                    if 'move_all' in request.POST:
                        Post.objects.filter(topic=topic).update(topic=to_topic)
                        topic.delete()
                        moved = True
                        deleted = True
                    else:
                        for post_id in post_list:
                            if not moved:
                                moved = True
                            post = get_object_or_404(Post, pk=post_id)
                            if post.topic != to_topic:
                                last = (topic.last_post == post)
                                if forum_moderated_by(to_topic, request.user):
                                    post.topic = to_topic
                                    post.save()
                        if Post.objects.filter(
                                topic__id=topic.id).count() == 0:
                            topic.delete()
                            deleted = True
                        else:
                            deleted = False
                            try:
                                topic.last_post = Post.objects.filter(
                                    topic__id=topic.id).latest()
                            except Post.DoesNotExist:
                                topic.last_post = None
                            topic.post_count = Post.objects.filter(
                                topic__id=topic.id).count()
                            topic.save()
                    try:
                        from_forum.last_post = Post.objects.filter(
                            topic__forum__id=from_forum.id).latest()
                    except Post.DoesNotExist:
                        from_forum.last_post = None
                    from_forum.post_count = Post.objects.filter(
                        topic__forum__id=from_forum.id).count()
                    from_forum.topic_count = Topic.objects.filter(
                        forum__id=from_forum.id).count()
                    from_forum.save()

                    to_topic.post_count = Post.objects.filter(
                        topic__id=to_topic.id).count()
                    to_topic.save()

                    if moved:
                        messages.success(request, _("Posts moved."))
                        if not deleted:
                            return HttpResponseRedirect(
                                topic.get_absolute_url())
                        else:
                            return HttpResponseRedirect(
                                from_forum.get_absolute_url())

    last_post = topic.posts.latest()

    if request.user.is_authenticated():
        topic.update_read(request.user)

    posts = topic.posts.all().select_related()

    initial = {}
    if request.user.is_authenticated():
        initial = {'markup': request.user.forum_profile.markup}
    form = AddPostForm(topic=topic,
                       initial=initial,
                       is_ip_banned=request.is_ip_banned)

    moderator = request.user.is_superuser or\
        request.user in topic.forum.moderators.all()
    if request.user.is_authenticated(
    ) and request.user in topic.subscribers.all():
        subscribed = True
    else:
        subscribed = False
    return render(
        request, 'djangobb_forum/move_posts.html', {
            'categories': Category.objects.all(),
            'exclude_topic': from_forum,
            'topic': topic,
            'last_post': last_post,
            'form': form,
            'moderator': moderator,
            'subscribed': subscribed,
            'posts': posts,
        })