Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-- Resolved issue #409 with a new method registration_status and a new template. -- Fixed a minor bug in models.py. #458

Merged
merged 4 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion oioioi/contests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from oioioi.contests.fields import ScoreField
from oioioi.contests.problem_instance_controller import ProblemInstanceController
from oioioi.filetracker.fields import FileField
from enum import Enum


def make_contest_filename(instance, filename):
Expand Down Expand Up @@ -357,6 +358,10 @@ class Meta(object):
registration_availability_options.register('NO', _("Closed"))
registration_availability_options.register('CONFIG', _("Configuration"))

class RegistrationStatus(Enum):
OPEN = 1
CLOSED = 2
NOT_OPEN_YET = 3

@date_registry.register(
'registration_available_from', name_generator=(lambda obj: _("Make registration available"))
Expand Down Expand Up @@ -405,12 +410,25 @@ def is_registration_open(self, timestamp):
return self.registration_available_from <= timestamp <= self.registration_available_to
return False


def registration_status(self, timestamp):
if self.enabled == 'YES':
return RegistrationStatus.OPEN
if self.enabled == 'CONFIG':
if self.registration_available_from <= timestamp <= self.registration_available_to:
return RegistrationStatus.OPEN
elif self.registration_available_to < timestamp:
return RegistrationStatus.CLOSED
elif timestamp < self.registration_available_to:
return RegistrationStatus.NOT_OPEN_YET
return RegistrationStatus.CLOSED

def clean(self):
if self.enabled == 'CONFIG':
if self.registration_available_from is None or self.registration_available_to is None:
raise ValidationError(_("If registration availability is set to Configuration, then "
"'Available from' and 'Available to' must be set."))
if self.available_from > self.registration_available_to:
if self.registration_available_from > self.registration_available_to:
raise ValidationError(_("'Available from' must be before 'available to'."))


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "base-with-menu.html" %}
{% load i18n %}

{% block title %}{% trans "Registration Form" %}{% endblock %}

{% block main-content %}
<h1>{% trans "Registration not open yet" %}</h1>
<p>{% trans "Please check back later" %}</p>
{% endblock %}
6 changes: 4 additions & 2 deletions oioioi/contests/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3760,7 +3760,7 @@ def set_registration_availability(rvc, enabled, available_from=None, available_t
rvc.save()


def check_registration(self, expected_status_code, availability, available_from=None, available_to=None):
def check_registration(self, expected_status_code, availability, available_from=None, available_to=None, expected_template=None):
contest = Contest.objects.get()
contest.controller_name = 'oioioi.oi.controllers.OIContestController'
contest.save()
Expand All @@ -3773,6 +3773,8 @@ def check_registration(self, expected_status_code, availability, available_from=
set_registration_availability(rvc, availability, available_from, available_to)
response = self.client.get(url)
self.assertEqual(expected_status_code, response.status_code)
if expected_template == 'registration_not_open_yet':
self.assertTemplateUsed(response, 'contests/registration_not_open_yet.html')


class TestOpenRegistration(TestCase):
Expand All @@ -3797,7 +3799,7 @@ def test_configured_registration_closed_before(self):
now = datetime.utcnow()
available_from = now + timedelta(hours=1)
available_to = now + timedelta(days=1)
check_registration(self, 403, 'CONFIG', available_from, available_to)
check_registration(self, 200, 'CONFIG', available_from, available_to, 'registration_not_open_yet')

def test_configured_registration_closed_after(self):
now = datetime.utcnow()
Expand Down
9 changes: 9 additions & 0 deletions oioioi/mp/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from oioioi.participants.utils import is_participant
from oioioi.programs.controllers import ProgrammingContestController
from oioioi.rankings.controllers import DefaultRankingController
from oioioi.contests.models import RegistrationStatus

CONTEST_RANKING_KEY = 'c'

Expand Down Expand Up @@ -49,7 +50,15 @@ def visible_contests_query(self, request):
def can_register(self, request):
return super().is_registration_open(request)

def get_registration_status(self, request):
return super().registration_status(request)

def registration_view(self, request):

registration_status = self.get_registration_status(request)
if registration_status == RegistrationStatus.NOT_OPEN_YET:
return TemplateResponse(request, 'contests/registration_not_open_yet.html')

participant = self._get_participant_for_form(request)

if 'mp_mpregistrationformdata' in request.session:
Expand Down
9 changes: 9 additions & 0 deletions oioioi/oi/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from oioioi.participants.utils import is_participant
from oioioi.programs.controllers import ProgrammingContestController
from oioioi.scoresreveal.utils import is_revealed
from oioioi.contests.models import RegistrationStatus

auditLogger = logging.getLogger(__name__ + ".audit")

Expand Down Expand Up @@ -59,10 +60,18 @@ def visible_contests_query(self, request):
def can_register(self, request):
return super().is_registration_open(request)

def get_registration_status(self, request):
return super().registration_status(request)

def can_unregister(self, request, participant):
return False

def registration_view(self, request):

registration_status = self.get_registration_status(request)
if registration_status == RegistrationStatus.NOT_OPEN_YET:
return TemplateResponse(request, 'contests/registration_not_open_yet.html')

participant = self._get_participant_for_form(request)

if 'oi_oiregistrationformdata' in request.session:
Expand Down
10 changes: 10 additions & 0 deletions oioioi/pa/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from oioioi.participants.utils import is_participant
from oioioi.programs.controllers import ProgrammingContestController
from oioioi.rankings.controllers import CONTEST_RANKING_KEY, DefaultRankingController
from oioioi.contests.models import RegistrationStatus


auditLogger = logging.getLogger(__name__ + ".audit")

Expand Down Expand Up @@ -61,10 +63,18 @@ def visible_contests_query(self, request):
def can_register(self, request):
return super().is_registration_open(request)

def get_registration_status(self, request):
return super().registration_status(request)

def can_unregister(self, request, participant):
return False

def registration_view(self, request):

registration_status = self.get_registration_status(request)
if registration_status == RegistrationStatus.NOT_OPEN_YET:
return TemplateResponse(request, 'contests/registration_not_open_yet.html')

participant = self._get_participant_for_form(request)

if 'pa_paregistrationformdata' in request.session:
Expand Down
11 changes: 11 additions & 0 deletions oioioi/participants/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
RegistrationModel,
TermsAcceptedPhrase,
)
from oioioi.contests.models import RegistrationStatus

auditLogger = logging.getLogger(__name__ + ".audit")

Expand Down Expand Up @@ -209,6 +210,16 @@ def is_registration_open(self, request):
auditLogger.warning("RegistrationAvailabilityConfig does not exist for contest %s", request.contest)
return True

def registration_status(self, request):
if is_contest_archived(request):
return RegistrationStatus.CLOSED
try:
rvc = RegistrationAvailabilityConfig.objects.get(contest=request.contest)
return rvc.registration_status(request.timestamp)
except RegistrationAvailabilityConfig.DoesNotExist:
auditLogger.warning("RegistrationAvailabilityConfig does not exist for contest %s", request.contest)
return RegistrationStatus.OPEN


class OpenParticipantsController(ParticipantsController):
@property
Expand Down
Loading