Skip to content

Commit

Permalink
remove submit button from submission page if contest is archived (#428)
Browse files Browse the repository at this point in the history
* remove submit button from submission page if contest is archived

* fix for problems without contests

* more elegant code
  • Loading branch information
Atanazyy authored Nov 25, 2024
1 parent c0e91eb commit 26d5da5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
12 changes: 7 additions & 5 deletions oioioi/contests/templates/contests/submission_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@
{% endif %}
{% block controls_buttons %}
{% if contest %}
<a role="button"
class="btn btn-sm btn-outline-secondary"
href= "{% url 'submit' contest_id=contest.id problem_instance_id=submission.submission.problem_instance.id %}">
<i class="fa-regular fa-circle-up"></i>
{% trans "Submit another" %}
{% if not is_contest_archived %}
<a role="button"
class="btn btn-sm btn-outline-secondary"
href= "{% url 'submit' contest_id=contest.id problem_instance_id=submission.submission.problem_instance.id %}">
<i class="fa-regular fa-circle-up"></i>
{% trans "Submit another" %}
{% endif %}
</a>
{% else %}
{% if submission.submission.problem_instance.problem.problemsite %}
Expand Down
15 changes: 15 additions & 0 deletions oioioi/contests/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4166,6 +4166,21 @@ def test_dashboard_view(self):
self.assertContains(response, "This contest is archived.")
self.assertNotContains(response, "Submit")

def test_submissions_view(self):
self.assertTrue(self.client.login(username='test_user'))
url = reverse('my_submissions', kwargs={'contest_id': 'c'})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertNotContains(response, "Submit")

def test_submission_view(self):
contest = Contest.objects.get()
submission = Submission.objects.get(pk=1)
self.assertTrue(self.client.login(username='test_user'))
kwargs = {'contest_id': contest.id, 'submission_id': submission.id}
response = self.client.get(reverse('submission', kwargs=kwargs))
self.assertNotContains(response, "Submit")

def test_submission_list_visibility(self):
self.assertTrue(self.client.login(username='test_user'))
url = reverse('my_submissions', kwargs={'contest_id': 'c'})
Expand Down
1 change: 1 addition & 0 deletions oioioi/contests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ def get_submission_message(request):
def is_contest_archived(request):
return (
hasattr(request, 'contest')
and (request.contest is not None)
and request.contest.is_archived
)

Expand Down
2 changes: 2 additions & 0 deletions oioioi/programs/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
is_contest_admin,
is_contest_basicadmin,
is_contest_observer,
is_contest_archived,
get_submission_message,
)
from oioioi.evalmgr.tasks import (
Expand Down Expand Up @@ -703,6 +704,7 @@ def render_submission(self, request, submission):
submission
),
'can_admin': can_admin,
'is_contest_archived': is_contest_archived(request),
'message': get_submission_message(request),
},
)
Expand Down

0 comments on commit 26d5da5

Please sign in to comment.