def tasks(request, contest_id):
contest = get_object_or_404(models.TaskBasedContest, pk=contest_id)
if not contest.is_visible_in_list and not request.user.is_staff:
return HttpResponseNotFound()
if not contest.is_started() and not request.user.is_staff:
messages.error(request, '%s is not started yet' % contest.name)
return redirect(contest)
solved_tasks_ids = {}
if request.user.is_authenticated():
participant = contest.get_participant_for_user(request.user)
solved_tasks_ids = contest.get_tasks_solved_by_participant(participant)
else:
participant = None
# Iterate all policies, collect opened tasks
opened_tasks_ids = set(
itertools.chain.from_iterable(
policy.get_open_tasks(participant) for policy in contest.tasks_opening_policies.all()
)
)
if contest.tasks_grouping == models.TasksGroping.OneByOne:
tasks = contest.tasks
return render(request, 'contests/tasks_one_by_one.html', {
'current_contest': contest,
'contest': contest,
'tasks': tasks,
'solved_tasks_ids': solved_tasks_ids,
'opened_tasks_ids': opened_tasks_ids,
})
if contest.tasks_grouping == models.TasksGroping.ByCategories:
categories = contest.categories
return render(request, 'contests/tasks_by_categories.html', {
'current_contest': contest,
'contest': contest,
'categories': categories,
'solved_tasks_ids': solved_tasks_ids,
'opened_tasks_ids': opened_tasks_ids,
})
评论列表
文章目录