From 26d5da5ee188a89b850b50f9463c1835e474dd15 Mon Sep 17 00:00:00 2001 From: Atanazy Gawrysiak <58700221+Atanazyy@users.noreply.github.com> Date: Mon, 25 Nov 2024 18:58:48 +0100 Subject: [PATCH] remove submit button from submission page if contest is archived (#428) * remove submit button from submission page if contest is archived * fix for problems without contests * more elegant code --- .../templates/contests/submission_header.html | 12 +++++++----- oioioi/contests/tests/tests.py | 15 +++++++++++++++ oioioi/contests/utils.py | 1 + oioioi/programs/controllers.py | 2 ++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/oioioi/contests/templates/contests/submission_header.html b/oioioi/contests/templates/contests/submission_header.html index 89ff4c9c3..b92578d67 100644 --- a/oioioi/contests/templates/contests/submission_header.html +++ b/oioioi/contests/templates/contests/submission_header.html @@ -49,11 +49,13 @@ {% endif %} {% block controls_buttons %} {% if contest %} - - - {% trans "Submit another" %} + {% if not is_contest_archived %} + + + {% trans "Submit another" %} + {% endif %} {% else %} {% if submission.submission.problem_instance.problem.problemsite %} diff --git a/oioioi/contests/tests/tests.py b/oioioi/contests/tests/tests.py index 8410b3955..e12c5ac5d 100755 --- a/oioioi/contests/tests/tests.py +++ b/oioioi/contests/tests/tests.py @@ -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'}) diff --git a/oioioi/contests/utils.py b/oioioi/contests/utils.py index 646f34156..8495f8b0c 100755 --- a/oioioi/contests/utils.py +++ b/oioioi/contests/utils.py @@ -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 ) diff --git a/oioioi/programs/controllers.py b/oioioi/programs/controllers.py index 91b4039f7..401a22ee8 100644 --- a/oioioi/programs/controllers.py +++ b/oioioi/programs/controllers.py @@ -23,6 +23,7 @@ is_contest_admin, is_contest_basicadmin, is_contest_observer, + is_contest_archived, get_submission_message, ) from oioioi.evalmgr.tasks import ( @@ -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), }, )