From 41a80d951f7a4f9eaf888ea04a11bcefc56a6947 Mon Sep 17 00:00:00 2001 From: Prateek Kumar Date: Wed, 1 May 2019 00:25:30 +0530 Subject: [PATCH] Disable addition, deletion of test cases and problem after contest start (#55) --- judge/templates/judge/contest_detail.html | 3 +- judge/templates/judge/problem_detail.html | 9 ++++- judge/views.py | 47 ++++++++++++++--------- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/judge/templates/judge/contest_detail.html b/judge/templates/judge/contest_detail.html index 348eb38..25ac45f 100644 --- a/judge/templates/judge/contest_detail.html +++ b/judge/templates/judge/contest_detail.html @@ -26,7 +26,8 @@

{{ contest.name }}

{% if type == 'Poster' %} - Add Problem + {% if now < contest.start_datetime %}Add Problem{% endif %} Download Scores {% endif %} See posters diff --git a/judge/templates/judge/problem_detail.html b/judge/templates/judge/problem_detail.html index eb843ad..8ec41f5 100644 --- a/judge/templates/judge/problem_detail.html +++ b/judge/templates/judge/problem_detail.html @@ -118,10 +118,12 @@

{{ problem.name }}

+ {% if now < problem.contest.start_datetime %}
{% csrf_token %}
+ {% endif %}
{% endif %}
@@ -167,7 +169,7 @@

Output Format

Public test cases

{% for test in public_tests %}
Test Case {{ forloop.counter }}
- {% if type == 'Poster' %} + {% if type == 'Poster' and now < problem.contest.start_datetime %}
{% csrf_token %} @@ -198,12 +200,14 @@
Output

Private test cases

{% for test in private_tests %}
Test Case {{ forloop.counter }}
+ {% if now < problem.contest.start_datetime %}
{% csrf_token %}
+ {% endif %}
Input
@@ -298,9 +302,9 @@

Submit Solution

{% endif %} - {% if type == 'Poster' %}
+ {% if now < problem.contest.start_datetime %}
@@ -336,6 +340,7 @@

Add Test Case

+ {% endif %} diff --git a/judge/views.py b/judge/views.py index 31edfe5..e0a641a 100644 --- a/judge/views.py +++ b/judge/views.py @@ -203,6 +203,8 @@ def delete_problem(request, problem_id): contest_id = problem.contest.pk perm = handler.get_personproblem_permission( None if user is None else user.email, problem_id) + if timezone.now() > problem.contest.start_datetime: + return handler404(request) if perm and request.method == 'POST': status, _ = handler.delete_problem(problem_id) if status: @@ -218,6 +220,8 @@ def delete_testcase(request, problem_id, testcase_id): perm = handler.get_personproblem_permission( None if user is None else user.email, problem_id) testcase = get_object_or_404(TestCase, pk=testcase_id) + if timezone.now() > testcase.problem.contest.start_datetime: + return handler404(request) if problem_id == testcase.problem.pk and perm and request.method == 'POST': status, _ = handler.delete_testcase(testcase_id) if status: @@ -259,20 +263,23 @@ def problem_detail(request, problem_id): form = NewSubmissionForm() context['form'] = form if perm is True: - if request.method == 'POST': - form = AddTestCaseForm(request.POST, request.FILES) - if form.is_valid(): - status, err = handler.process_testcase( - problem_id, - form.cleaned_data['test_type'] == 'public', - form.cleaned_data['input_file'], - form.cleaned_data['output_file']) - if status: - redirect(reverse('judge:problem_submissions', args=(problem_id,))) - else: - form.add_error(None, err) + if timezone.now() < problem.contest.start_datetime: + if request.method == 'POST': + form = AddTestCaseForm(request.POST, request.FILES) + if form.is_valid(): + status, err = handler.process_testcase( + problem_id, + form.cleaned_data['test_type'] == 'public', + form.cleaned_data['input_file'], + form.cleaned_data['output_file']) + if status: + redirect(reverse('judge:problem_submissions', args=(problem_id,))) + else: + form.add_error(None, err) + else: + form = AddTestCaseForm() else: - form = AddTestCaseForm() + form = None context['form'] = form context['public_tests'] = [] context['private_tests'] = [] @@ -340,6 +347,8 @@ def new_problem(request, contest_id): if not (perm is True): return handler404(request) context = {'contest': contest} + if timezone.now() > contest.start_datetime: + return handler404(request) if request.method == 'POST': form = NewProblemForm(request.POST, request.FILES) if form.is_valid(): @@ -420,9 +429,9 @@ def problem_submissions(request, problem_id: str): form = NewCommentForm() submissions = {} if perm: - status, msg = handler.get_submissions(problem_id, None) + status, all_subs = handler.get_submissions(problem_id, None) if status: - for email, subs in msg.items(): + for email, subs in all_subs.items(): status, comm = handler.get_comments(problem_id, email) if not status: logging.debug(comm) @@ -430,19 +439,19 @@ def problem_submissions(request, problem_id: str): submissions[email] = (subs, comm) context['submissions'] = submissions else: - logging.debug(msg) + logging.debug(all_subs) return handler404(request) elif user is not None: - status, msg = handler.get_submissions(problem_id, user.email) + status, subs = handler.get_submissions(problem_id, user.email) if status: context['participant'] = True status, comm = handler.get_comments(problem_id, user.email) if not status: logging.debug(comm) return handler404(request) - submissions[user.email] = (msg[user.email], comm) + submissions[user.email] = (subs[user.email], comm) else: - logging.debug(msg) + logging.debug(subs) return handler404(request) else: return handler404(request)