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)
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)
def forum_view(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': get_msgs(request), 'can_interact_with_users': can_interact_with_users(request), 'can_interact_with_admins': can_interact_with_admins(request), 'is_locked': request.contest.forum.is_locked(), 'category_set': category_set, })
def category_view(request, category_id): category = get_object_or_404(Category, id=category_id) 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': get_msgs(request), 'can_interact_with_users': can_interact_with_users(request), 'can_interact_with_admins': can_interact_with_admins(request) })
def latest_posts_forum_view(request): posts = (Post.objects.filter( thread__category__forum=request.contest.forum.pk, ).prefetch_related( 'thread').order_by('-add_date')) posts = annotate_posts_with_current_user_reactions(request, posts) context = { 'forum': request.contest.forum, 'msgs': get_msgs(request), 'post_set': posts, 'posts_per_page': settings.FORUM_PAGE_SIZE, 'can_interact_with_users': can_interact_with_users(request), 'can_interact_with_admins': can_interact_with_admins(request), } return TemplateResponse(request, 'forum/latest_posts.html', context)