示例#1
0
文件: views.py 项目: Kerram/oioioi
def thread_view(request, category_id, thread_id):
    category, thread = get_forum_ct(category_id, thread_id)
    forum = request.contest.forum

    context = {
        'forum': forum,
        'category': category,
        'thread': thread,
        'msgs': get_msgs(request),
        'post_set': thread.post_set.select_related('author').all(),
        'can_interact_with_users': can_interact_with_users(request),
        'can_interact_with_admins': can_interact_with_admins(request)
    }

    if can_interact_with_users(request):
        if request.method == "POST":
            form = PostForm(request, request.POST)
            if form.is_valid():
                instance = form.save(commit=False)
                instance.author = request.user
                instance.thread = thread
                instance.add_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)
        context['form'] = form

    return TemplateResponse(request, 'forum/thread.html', context)
示例#2
0
def thread_view(request, category_id, thread_id):
    category, thread = get_forum_ct(category_id, thread_id)
    forum, lock = request.contest.forum, forum_is_locked(request)
    msgs = get_msgs(request)
    post_set = thread.post_set.select_related('author').all()
    if (request.user.is_authenticated() and not lock) or \
       is_contest_admin(request):
        if request.method == "POST":
            form = PostForm(request, request.POST)
            if form.is_valid():
                instance = form.save(commit=False)
                instance.author = request.user
                instance.thread = thread
                instance.add_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)

        return TemplateResponse(request, 'forum/thread.html',
            {'forum': forum, 'category': category, 'thread': thread,
             'form': form, 'msgs': msgs, 'is_locked': lock,
             'post_set': post_set})
    else:
        return TemplateResponse(request, 'forum/thread.html',
            {'forum': forum, 'category': category, 'thread': thread,
             'msgs': msgs, 'is_locked': lock, 'post_set': post_set})
示例#3
0
文件: views.py 项目: marmistrz/oioioi
def thread_view(request, category_id, thread_id):
    category, thread = get_forum_ct(category_id, thread_id)
    forum, lock = request.contest.forum, forum_is_locked(request)
    msgs = get_msgs(request)
    post_set = thread.post_set.select_related('author').all()
    if (request.user.is_authenticated() and not lock) or \
       is_contest_admin(request):
        if request.method == "POST":
            form = PostForm(request, request.POST)
            if form.is_valid():
                instance = form.save(commit=False)
                instance.author = request.user
                instance.thread = thread
                instance.add_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)

        return TemplateResponse(request, 'forum/thread.html',
            {'forum': forum, 'category': category, 'thread': thread,
             'form': form, 'msgs': msgs, 'is_locked': lock,
             'post_set': post_set})
    else:
        return TemplateResponse(request, 'forum/thread.html',
            {'forum': forum, 'category': category, 'thread': thread,
             'msgs': msgs, 'is_locked': lock, 'post_set': post_set})
示例#4
0
def thread_view(request, category_id, thread_id):
    category, thread = get_forum_ct(category_id, thread_id)
    forum = request.contest.forum

    context = {'forum': forum,
               'category': category,
               'thread': thread,
               'msgs': get_msgs(request),
               'post_set': thread.post_set.select_related('author').all(),
               'can_interact_with_users': can_interact_with_users(request),
               'can_interact_with_admins': can_interact_with_admins(request)}

    if can_interact_with_users(request):
        if request.method == "POST":
            form = PostForm(request, request.POST)
            if form.is_valid():
                instance = form.save(commit=False)
                instance.author = request.user
                instance.thread = thread
                instance.add_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)
        context['form'] = form

    return TemplateResponse(request, 'forum/thread.html', context)
示例#5
0
def delete_thread_view(request, category_id, thread_id):
    category, thread = get_forum_ct(category_id, thread_id)
    choice = confirmation_view(request, 'forum/confirm_delete.html',
                               {'elem': thread})
    if not isinstance(choice, bool):
        return choice
    if choice:
        thread.delete()
    return redirect('forum_category', contest_id=request.contest.id,
                    category_id=category.id)
示例#6
0
def delete_thread_view(request, category_id, thread_id):
    category, thread = get_forum_ct(category_id, thread_id)
    choice = confirmation_view(request, 'forum/confirm_delete.html',
                               {'elem': thread})
    if not isinstance(choice, bool):
        return choice
    if choice:
        thread.delete()
    return redirect('forum_category', contest_id=request.contest.id,
                    category_id=category.id)