Ejemplo n.º 1
0
def hide_post_view(request, category_id, thread_id, post_id):
    (category, thread, post) = get_forum_ctp(category_id, thread_id, post_id)
    post.hidden = True
    post.reported = False
    post.save()
    return redirect('forum_thread', contest_id=request.contest.id,
                    category_id=category.id, thread_id=thread.id)
Ejemplo n.º 2
0
def show_post_view(request, category_id, thread_id, post_id):
    # Admin shows reported/hidden post again
    (category, thread, post) = get_forum_ctp(category_id, thread_id, post_id)
    post.hidden = False
    post.save()
    return redirect('forum_thread', contest_id=request.contest.id,
                    category_id=category.id, thread_id=thread.id)
Ejemplo n.º 3
0
def delete_post_view(request, category_id, thread_id, post_id):
    (category, thread, post) = get_forum_ctp(category_id, thread_id, post_id)
    is_admin = is_contest_admin(request)
    if not is_admin and \
       (post.author != request.user or
       (post.author == request.user and
       (thread.post_set.filter(add_date__gt=post.add_date).exists() or
           not post.can_be_removed()))):
        # author: if there are other posts added later or timedelta is gt 15min
        # if user is not the author of the post or forum admin
        raise PermissionDenied
    else:
        choice = confirmation_view(request, 'forum/confirm_delete.html',
                {'elem': post})
        if not isinstance(choice, bool):
            return choice
        if choice:
            post.delete()

            if not thread.post_set.exists():
                thread.delete()
                return redirect('forum_category',
                                contest_id=request.contest.id,
                                category_id=category.id)
    return redirect('forum_thread', contest_id=request.contest.id,
                    category_id=category.id, thread_id=thread.id)
Ejemplo n.º 4
0
def delete_post_view(request, category_id, thread_id, post_id):
    (category, thread, post) = get_forum_ctp(category_id, thread_id, post_id)
    is_admin = is_contest_admin(request)
    if not (  # we assert following:
        is_admin
        or (
            post.author == request.user
            # you can remove a post only if there is no post added after yours
            and not thread.post_set.filter(add_date__gt=post.add_date).exists()
            and post.can_be_removed()
        )
    ):
        raise PermissionDenied
    else:
        choice = confirmation_view(request, 'forum/confirm_delete.html',
                {'elem': post})
        if not isinstance(choice, bool):
            return choice
        if choice:
            post.delete()

            if not thread.post_set.exists():
                thread.delete()
                return redirect('forum_category',
                                contest_id=request.contest.id,
                                category_id=category.id)

    return redirect('forum_thread', contest_id=request.contest.id,
                    category_id=category.id, thread_id=thread.id)
Ejemplo n.º 5
0
def edit_post_view(request, category_id, thread_id, post_id):
    (category, thread, post) = get_forum_ctp(category_id, thread_id, post_id)
    is_admin = is_contest_admin(request)

    if not (post.author == request.user or is_admin):
        raise PermissionDenied

    if request.method == 'POST':
        form = PostForm(request, request.POST, instance=post)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.approved = False
            instance.last_edit_date = request.timestamp
            instance.save()
            return redirect('forum_thread', contest_id=request.contest.id,
                            category_id=category.id,
                            thread_id=thread.id)
    else:
        form = PostForm(request, instance=post)

    return TemplateResponse(request, 'forum/edit_post.html', {
        'forum': request.contest.forum, 'category': category,
        'thread': thread, 'form': form, 'post': post,
        'msgs': get_msgs(request)
    })
Ejemplo n.º 6
0
def report_post_view(request, category_id, thread_id, post_id):
    (category, thread, post) = get_forum_ctp(category_id, thread_id, post_id)
    if not post.reported:
        post.reported = True
        post.reported_by = request.user
        post.save()
    return redirect('forum_thread', contest_id=request.contest.id,
                    category_id=category.id, thread_id=thread.id)
Ejemplo n.º 7
0
def revoke_approval_post_view(request, category_id, thread_id, post_id):
    (category, thread, post) = get_forum_ctp(category_id, thread_id, post_id)
    post.approved = False
    post.save()
    return redirect('forum_thread', contest_id=request.contest.id,
                    category_id=category.id, thread_id=thread.id)