Beispiel #1
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})
Beispiel #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})
Beispiel #3
0
def forum_view(request):
    msgs = get_msgs(request)
    category_set = request.contest.forum.category_set \
        .prefetch_related('thread_set', 'thread_set__post_set') \
        .all()
    return TemplateResponse(request, 'forum/forum.html', {
        'forum': request.contest.forum, 'msgs': msgs,
        'is_locked': forum_is_locked(request), 'category_set': category_set
    })
Beispiel #4
0
def forum_view(request):
    msgs = get_msgs(request)
    category_set = request.contest.forum.category_set \
        .prefetch_related('thread_set', 'thread_set__post_set') \
        .all()
    return TemplateResponse(request, 'forum/forum.html', {
        'forum': request.contest.forum, 'msgs': msgs,
        'is_locked': forum_is_locked(request), 'category_set': category_set
    })
Beispiel #5
0
def category_view(request, category_id):
    category = get_object_or_404(Category, id=category_id)
    msgs = get_msgs(request)
    threads = category.thread_set \
        .prefetch_related('post_set') \
        .select_related('last_post', 'last_post__author') \
        .all()
    return TemplateResponse(request, 'forum/category.html',
        {'forum': request.contest.forum, 'category': category,
         'threads': threads, 'msgs': msgs,
         'is_locked': forum_is_locked(request)})
Beispiel #6
0
def category_view(request, category_id):
    category = get_object_or_404(Category, id=category_id)
    msgs = get_msgs(request)
    threads = category.thread_set \
        .prefetch_related('post_set') \
        .select_related('last_post', 'last_post__author') \
        .all()
    return TemplateResponse(request, 'forum/category.html',
        {'forum': request.contest.forum, 'category': category,
         'threads': threads, 'msgs': msgs,
         'is_locked': forum_is_locked(request)})