Skip to content

Commit

Permalink
Disable addition, deletion of test cases and problem after contest st…
Browse files Browse the repository at this point in the history
…art (#55)
  • Loading branch information
prateekkumarweb authored and vishwakftw committed Apr 30, 2019
1 parent c188846 commit 41a80d9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
3 changes: 2 additions & 1 deletion judge/templates/judge/contest_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ <h2 class="d-inline">{{ contest.name }}</h2>
<div class="row">
<div class="col-12">
{% if type == 'Poster' %}
<a class="btn btn-primary" href="{% url 'judge:new_problem' contest.pk %}">Add Problem</a>
{% if now < contest.start_datetime %}<a class="btn btn-primary"
href="{% url 'judge:new_problem' contest.pk %}">Add Problem</a>{% endif %}
<a class="btn btn-primary" href="{% url 'judge:contest_scores_csv' contest.pk %}">Download Scores</a>
{% endif %}
<a class="btn btn-primary" href="{% url 'judge:get_posters' contest.pk %}">See posters</a>
Expand Down
9 changes: 7 additions & 2 deletions judge/templates/judge/problem_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ <h4 class="d-inline mx-2">{{ problem.name }}</h4>
<a href="{% url 'judge:edit_problem' problem.pk %}" class="btn btn-primary">
<i class="fas fa-edit"></i>
</a>
{% if now < problem.contest.start_datetime %}
<form class="d-inline" action="{% url 'judge:delete_problem' problem.pk %}" method="POST">
{% csrf_token %}
<button type="submit" class="btn btn-danger"><i class="fas fa-trash"></i></button>
</form>
{% endif %}
</div>
{% endif %}
</div>
Expand Down Expand Up @@ -167,7 +169,7 @@ <h4>Output Format</h4>
<h4>Public test cases</h4>
{% for test in public_tests %}
<h5 class="d-inline">Test Case {{ forloop.counter }}</h5>
{% if type == 'Poster' %}
{% if type == 'Poster' and now < problem.contest.start_datetime %}
<div class="d-inline">
<form class="d-inline" action="{% url 'judge:delete_testcase' problem.pk test.2 %}" method="POST">
{% csrf_token %}
Expand Down Expand Up @@ -198,12 +200,14 @@ <h6>Output</h6>
<h4>Private test cases</h4>
{% for test in private_tests %}
<h5 class="d-inline">Test Case {{ forloop.counter }}</h5>
{% if now < problem.contest.start_datetime %}
<div class="d-inline">
<form class="d-inline" action="{% url 'judge:delete_testcase' problem.pk test.2 %}" method="POST">
{% csrf_token %}
<button type="submit" class="btn btn-danger"><i class="fas fa-trash"></i></button>
</form>
</div>
{% endif %}
<div class="col-12">
<h6>Input</h6>
<div class="zero-clipboard">
Expand Down Expand Up @@ -298,9 +302,9 @@ <h3>Submit Solution</h3>
</div>
{% endif %}

<!-- TODO Restrict to poster only (check views) -->
{% if type == 'Poster' %}
<div class="row">
{% if now < problem.contest.start_datetime %}
<div class="col-12 my-4">
<div class="card">
<div class="card-header">
Expand Down Expand Up @@ -336,6 +340,7 @@ <h3>Add Test Case</h3>
</div>
</div>
</div>
{% endif %}
<div class="col-12">
<a href="{% url 'judge:problem_submissions' problem.pk %}" class="btn btn-default">See all solutions</a>
</div>
Expand Down
47 changes: 28 additions & 19 deletions judge/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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'] = []
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -420,29 +429,29 @@ 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)
return handler404(request)
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)
Expand Down

0 comments on commit 41a80d9

Please sign in to comment.