From 94d138ff8c476d3d997de7572bf65f4047d79c5e Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Thu, 26 Jan 2017 20:51:22 +0100 Subject: [PATCH] Added option to set contest deadline Logging is also restricted after deadline has passed --- TODO | 2 +- contest/forms.py | 16 ++++++++++++++- contest/migrations/0014_contest_deadline.py | 22 +++++++++++++++++++++ contest/models.py | 1 + 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 contest/migrations/0014_contest_deadline.py diff --git a/TODO b/TODO index ee30a0d..989a5c2 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,6 @@ - rearrange login index: contest content rüberziehen; exchange registration nach rechts in der nav - ensure QSOs are logged in UTC (they currently are, but why?) - register users still has "reference" labels, make form better - - contest log add deadline - cbr parser zum hochladen (Partially) Done @@ -23,6 +22,7 @@ - align log button with log - contest teilnahme klassen - "Please register with your (uppercase) Callsign as Usernames. For DN-Calls, /[A-Z] is allowed." gibt es wohl noch wo + - contest log add deadline Glaube nich, dass ich das mache - call dupe validation könnte ins model wandern diff --git a/contest/forms.py b/contest/forms.py index 9c0ab5f..75f9e27 100644 --- a/contest/forms.py +++ b/contest/forms.py @@ -1,11 +1,12 @@ from django import forms from django.contrib.auth.forms import UserCreationForm +from django.utils import timezone from crispy_forms.helper import FormHelper from crispy_forms.layout import Submit, Layout from django.urls import reverse -from .models import User, Reference, QSO, ShadowCall, EntryCategory +from .models import User, Reference, QSO, ShadowCall, EntryCategory, Contest from .validators import CallUsernameValidator, CallLogValidator class CustomUserCreationForm(UserCreationForm): @@ -50,6 +51,12 @@ class UpdateCategoryForm(forms.Form): self.helper.add_input(Submit('submit', 'Set category')) self.helper.layout = Layout('entry') + def clean(self): + contest = Contest.objects.get(id=1) + + if contest.deadline < timezone.now(): + raise forms.ValidationError("The deadline for setting your contest category has passed") + class QSOForm(forms.ModelForm): class Meta: model = QSO @@ -110,6 +117,13 @@ class QSOForm(forms.ModelForm): def clean_refStr(self): return self.cleaned_data["refStr"].upper() + def clean(self): + cleaned_data = super(QSOForm, self).clean() + band = cleaned_data.get("band") + + if band.contest.deadline < timezone.now(): + raise forms.ValidationError("The deadline for logging and editing QSOs has passed") + class QSOFormWithTime(QSOForm): class Meta: model = QSO diff --git a/contest/migrations/0014_contest_deadline.py b/contest/migrations/0014_contest_deadline.py new file mode 100644 index 0000000..25b0650 --- /dev/null +++ b/contest/migrations/0014_contest_deadline.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-01-26 19:40 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('contest', '0013_auto_20170126_1909'), + ] + + operations = [ + migrations.AddField( + model_name='contest', + name='deadline', + field=models.DateTimeField(default=django.utils.timezone.now), + preserve_default=False, + ), + ] diff --git a/contest/models.py b/contest/models.py index 476a7e9..d8192cc 100644 --- a/contest/models.py +++ b/contest/models.py @@ -13,6 +13,7 @@ class Contest(models.Model): name = models.CharField(max_length=20) shortName = models.CharField(max_length=20, unique=True) callQrg = models.ForeignKey("Frequency", models.SET_NULL, null=True, blank=True) + deadline = models.DateTimeField() def __str__(self): return self.name