def task_file(request, contest_id, file_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()
file = get_object_or_404(tasks_models.TaskFile, pk=file_id)
if not contest.has_task(file.task):
return HttpResponseNotFound()
if not contest.is_started() and not request.user.is_staff:
return HttpResponseForbidden('Contest is not started')
participant = contest.get_participant_for_user(request.user)
if not is_task_open(contest, file.task, participant) and not request.user.is_staff:
return HttpResponseForbidden('Task is closed')
if file.participant is not None and file.participant.id != request.user.id:
return HttpResponseForbidden()
file_path = file.get_path_abspath()
return respond_as_attachment(request, file_path, file.name, file.content_type)
评论列表
文章目录