Skip to content

Commit e81613a

Browse files
committed
fix: submit before and after contest
1 parent d20784a commit e81613a

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

contest/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_func(self):
4343
or user.privilege in (Privilege.ROOT, Privilege.ADMIN)):
4444
return True
4545
else:
46-
self.permission_denied_message = "Did you forget to register the contest?"
46+
self.permission_denied_message = "Did you forget to register for the contest?"
4747
return False
4848

4949
def get_context_data(self, **kwargs):
@@ -140,6 +140,9 @@ def get_form_kwargs(self):
140140

141141
def form_valid(self, form):
142142
contest = get_object_or_404(Contest, pk=self.kwargs['cid'])
143+
if timezone.now() < contest.start_time or timezone.now() > contest.end_time:
144+
messages.error(self.request, 'You are currently not in the period of the contest.')
145+
return HttpResponseRedirect(self.request.path)
143146
with transaction.atomic():
144147
submission = form.save(commit=False)
145148
problem_identifier = form.cleaned_data['problem_identifier']

dispatcher/tasks.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,17 @@ def dispatch(self):
147147
timeout=3600).json()
148148
print(response)
149149
if response['status'] != 'received':
150+
with transaction.atomic():
151+
self.submission = Submission.objects.select_for_update().get(pk=self.submission_id)
152+
self.submission.status = SubmissionStatus.SYSTEM_ERROR
153+
self.submission.save()
150154
raise ConnectionError('Remote server rejected the request.')
151155

152156
self.update_submission_and_problem(response)
153157
return True
154158
except Exception as e:
155159
print('Something wrong during dispatch:')
156-
print(e)
160+
print(repr(e))
157161
return False
158162

159163

templates/contest/index.jinja2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{% for contest_problem in contest_problem_list %}
1919
<tr>
2020
<th scope="row" class="text-center">{{ contest_problem.identifier }}</th>
21-
<td style="text-align: center;"><a href="{{ url('contest:problem', contest.pk, contest_problem.identifier) }}">
21+
<td style="text-align: left;"><a href="{{ url('contest:problem', contest.pk, contest_problem.identifier) }}">
2222
{{ contest_problem.problem.title }}</a></td>
2323
<td align="center" class="{% if contest_problem.status %}table-{{ contest_problem.status }}{% endif %}">
2424
{{ contest_problem.total_accept_number }} / {{ contest_problem.total_submit_number }}</td>

templates/contest/submit.jinja2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{% extends 'contest/base.jinja2' %}
2+
23
{% block contest_content %}
34

4-
<div>
5-
<div class="content-header">
6-
<h2>Submit your code</h2>
7-
</div>
5+
<div class="content-header">
6+
<h2>Submit your code</h2>
87
</div>
8+
{% include 'components/message.jinja2' %}
99
<form class="form" action="{{ request.path }}" method="post">
1010
{% csrf_token %}
1111

0 commit comments

Comments
 (0)