From 64161f9f98dce9eb28e809fb1f6170d716680408 Mon Sep 17 00:00:00 2001 From: Prateek Kumar Date: Wed, 1 May 2019 19:06:10 +0530 Subject: [PATCH] Add dates extension form to contest page (#57) * Add date extension forms * Fix when dates can be extended * Django template `now` can be used for printing only and comparison is buggy * Fix display of modal if invalid input is entered * De-duplicate code, add doc string and add entry in forms.rst * Fix lint --- docs/source/forms.rst | 3 + judge/forms.py | 46 +++++++-- judge/handler.py | 6 +- judge/templates/judge/base.html | 2 +- judge/templates/judge/contest_detail.html | 110 ++++++++++++++++++---- judge/templates/judge/new_contest.html | 2 +- judge/views.py | 33 ++++++- 7 files changed, 169 insertions(+), 33 deletions(-) diff --git a/docs/source/forms.rst b/docs/source/forms.rst index 5ff5882..1074641 100644 --- a/docs/source/forms.rst +++ b/docs/source/forms.rst @@ -21,6 +21,9 @@ Forms and input pre-processing .. autoclass:: AddTestCaseForm :members: + .. autoclass:: UpdateContestForm + :members: + .. autoclass:: EditProblemForm :members: diff --git a/judge/forms.py b/judge/forms.py index ad65a87..78e338b 100644 --- a/judge/forms.py +++ b/judge/forms.py @@ -2,6 +2,16 @@ from django.core.validators import RegexValidator, validate_email, EMPTY_VALUES +def _check_valid_date(cleaned_data): + cont_start = cleaned_data.get("contest_start") + cont_soft_end = cleaned_data.get("contest_soft_end") + cont_hard_end = cleaned_data.get("contest_hard_end") + if cont_start > cont_soft_end: + raise forms.ValidationError("Contest cannot end before it starts!") + if cont_soft_end > cont_hard_end: + raise forms.ValidationError("The final deadline cannot be before the soft deadline") + + class MultiEmailField(forms.Field): """ Subclass of forms.Field to support a list of email addresses. @@ -75,13 +85,35 @@ class NewContestForm(forms.Form): def clean(self): cleaned_data = super().clean() - cont_start = cleaned_data.get("contest_start") - cont_soft_end = cleaned_data.get("contest_soft_end") - cont_hard_end = cleaned_data.get("contest_hard_end") - if cont_start > cont_soft_end: - raise forms.ValidationError("Contest cannot end before it contest starts!") - if cont_soft_end > cont_hard_end: - raise forms.ValidationError("The final deadline cannot be before the soft deadline") + _check_valid_date(cleaned_data) + + +class UpdateContestForm(forms.Form): + """ + Form to update the timeline of the Contest + """ + + contest_start = forms.DateTimeField(label='Start Date', + widget=forms.DateTimeInput(attrs={'class': 'form-control'}), + help_text='Specify when the contest begins.') + """Contest Start Timestamp""" + + contest_soft_end = forms.DateTimeField(label='Soft End Date', + widget=forms.DateTimeInput( + attrs={'class': 'form-control'}), + help_text='Specify after when would you like to \ + penalize submissions.') + """Contest Soft End Timestamp""" + + contest_hard_end = forms.DateTimeField(label='Hard End Date', + widget=forms.DateTimeInput( + attrs={'class': 'form-control'}), + help_text='Specify when the contest completely ends.') + """Contest Hard End Timestamp""" + + def clean(self): + cleaned_data = super().clean() + _check_valid_date(cleaned_data) class AddPersonToContestForm(forms.Form): diff --git a/judge/handler.py b/judge/handler.py index 1c5bc25..e8790a5 100644 --- a/judge/handler.py +++ b/judge/handler.py @@ -764,9 +764,11 @@ def update_leaderboard(contest: int, person: str): Updates the leaderboard for the passed contest for the rank of the person Pass pk for contest and email for person Only call this function when some submission for some problem of the contest - has scored more than its previous submission. + has scored more than its previous submission. Remember to call this function whenever PersonProblemFinalScore is updated. - Returns True if update was successfull else returns False + + Returns: + True if update was successful, False otherwise """ os.makedirs(os.path.join('content', 'contests'), exist_ok=True) diff --git a/judge/templates/judge/base.html b/judge/templates/judge/base.html index 68a741a..a041c51 100644 --- a/judge/templates/judge/base.html +++ b/judge/templates/judge/base.html @@ -29,7 +29,7 @@ {% url 'judge:index' as homepage %}