diff --git a/contest/context_processors.py b/contest/context_processors.py new file mode 100644 index 0000000..86b18b1 --- /dev/null +++ b/contest/context_processors.py @@ -0,0 +1,7 @@ +from .models import Contest + + +def current_contest(self): + return { + 'current_contest': Contest.get_current_contest(), + } diff --git a/contest/migrations/0022_contest_contestno.py b/contest/migrations/0022_contest_contestno.py new file mode 100644 index 0000000..04f65a4 --- /dev/null +++ b/contest/migrations/0022_contest_contestno.py @@ -0,0 +1,20 @@ +# Generated by Django 4.0.1 on 2022-01-22 17:52 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('contest', '0021_alter_qso_otherno_alter_qso_ownno_alter_user_dncall_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='contest', + name='contestNo', + field=models.IntegerField(default=1, help_text='Running number of contest (for vanity reasons)', validators=[django.core.validators.MinValueValidator(1)]), + preserve_default=False, + ), + ] diff --git a/contest/migrations/0023_contest_rulesetlink.py b/contest/migrations/0023_contest_rulesetlink.py new file mode 100644 index 0000000..4cbdca7 --- /dev/null +++ b/contest/migrations/0023_contest_rulesetlink.py @@ -0,0 +1,19 @@ +# Generated by Django 4.0.1 on 2022-01-22 17:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('contest', '0022_contest_contestno'), + ] + + operations = [ + migrations.AddField( + model_name='contest', + name='rulesetLink', + field=models.TextField(default='', help_text='URL to the ruleset pdf for this contest'), + preserve_default=False, + ), + ] diff --git a/contest/models.py b/contest/models.py index b7bc648..e746fbb 100644 --- a/contest/models.py +++ b/contest/models.py @@ -12,6 +12,9 @@ from .validators import CallUsernameValidator class Contest(models.Model): name = models.CharField(max_length=20) shortName = models.CharField(max_length=20, unique=True) + contestNo = models.IntegerField(validators=[MinValueValidator(1)], + help_text="Running number of contest (for vanity reasons)") + rulesetLink = models.TextField(help_text="URL to the ruleset pdf for this contest") callQrg = models.ForeignKey("Frequency", on_delete=models.SET_NULL, null=True, blank=True) deadline = models.DateTimeField() @@ -23,7 +26,12 @@ class Contest(models.Model): @classmethod def get_current_contest(cls): - return cls.objects.get(id=1) + # Currently the contest with the latest deadline is the active one + # This definitely has potential for improvement, but it's better than a hardcoded contest + contests = cls.objects.order_by("-deadline") + if len(contests) > 0: + return contests[0] + return None class Reference(models.Model): diff --git a/cqtu/settings.py b/cqtu/settings.py index 9573812..f4b008f 100644 --- a/cqtu/settings.py +++ b/cqtu/settings.py @@ -40,6 +40,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'django.contrib.humanize', 'crispy_forms', 'rest_framework', 'django_filters', @@ -72,6 +73,7 @@ TEMPLATES = [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + 'contest.context_processors.current_contest', ], }, }, diff --git a/cqtu/urls.py b/cqtu/urls.py index 72501c0..c0fb3fc 100644 --- a/cqtu/urls.py +++ b/cqtu/urls.py @@ -7,7 +7,7 @@ from contest.views import index, register, profile urlpatterns = [ path('', index, name="index"), - path('cqtufm2019/', include('contest.urls', namespace='contest')), + path('contest/', include('contest.urls', namespace='contest')), path('admin/', admin.site.urls), path('login/', auth_views.LoginView.as_view(), name='login'), diff --git a/templates/base.html b/templates/base.html index 3cdcdca..0b20c2e 100644 --- a/templates/base.html +++ b/templates/base.html @@ -10,7 +10,7 @@ {% load static %} -