diff --git a/core/templates/base.html b/core/templates/base.html index a205077..0558848 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -3,8 +3,8 @@ {% block head %} {% block meta %} - {% block title %}{% if title %}{{ title }} | {% endif %}Archery Tournaments{% endblock %} - + {% block title %}{% if title %}{{ title }} | {% endif %}Archery Competitions{% endblock %} + {% if meta_description %} @@ -29,7 +29,7 @@ diff --git a/core/templates/index.html b/core/templates/index.html index eb4cd9a..81e7540 100644 --- a/core/templates/index.html +++ b/core/templates/index.html @@ -9,15 +9,52 @@

TamlynScore

TamlynScore is an online platform for running archery competitions.
If you'd like to use TamlynScore for your event, please contact us.

+

Competitions

+
+ {% if current_competitions %} +
+

In progress and coming soon

+ +
+ {% endif %} + {% if recent_competitions %} +
+

Recently Finished

+ +
+ {% endif %} +
+ +{% if seasons %}

Leagues

-{% for league in leagues %} - +{% for season in seasons %} +
- -

{{ league }}

+ +

{{ season.league }}

{% endfor %}
+{% endif %} + {% endblock %} diff --git a/core/views.py b/core/views.py index a2833c8..8f10c72 100644 --- a/core/views.py +++ b/core/views.py @@ -1,9 +1,11 @@ import copy +import datetime from django.core.cache import cache from django.db.models import Prefetch from django.shortcuts import get_object_or_404 from django.urls import reverse +from django.utils import timezone from django.views.generic import ( CreateView, DetailView, ListView, TemplateView, UpdateView, ) @@ -12,7 +14,7 @@ from entries.models import Competition, CompetitionEntry from entries.views import BatchEntryMixin -from leagues.models import League +from leagues.models import Season from scores.models import Score from .forms import ArcherForm, ClubArcherForm @@ -41,7 +43,23 @@ class Index(TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context['leagues'] = League.objects.order_by('?') + today = timezone.now().date() + + context['seasons'] = Season.objects.filter(start_date__lte=today, end_date__gt=today) + + competitions = Competition.objects.select_related('tournament').order_by('date') + context['current_competitions'] = competitions.filter( + date__lte=today + datetime.timedelta(days=7), + end_date__gte=today, + ) + context['recent_competitions'] = competitions.filter( + date__gte=today - datetime.timedelta(days=14), + end_date__lt=today, + ) + if len(context['recent_competitions']) < 5: + context['recent_competitions'] = competitions.order_by('-date').filter( + end_date__lt=today, + )[:5] return context diff --git a/entries/migrations/0034_competition_name_override_and_more.py b/entries/migrations/0034_competition_name_override_and_more.py new file mode 100644 index 0000000..6ce573f --- /dev/null +++ b/entries/migrations/0034_competition_name_override_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 4.1.10 on 2023-07-08 10:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('entries', '0033_competition_split_categories_on_agb_age'), + ] + + operations = [ + migrations.AddField( + model_name='competition', + name='name_override', + field=models.CharField(blank=True, default='', help_text='Override the recurring tournament name', max_length=200), + ), + migrations.AddField( + model_name='competition', + name='short_name_override', + field=models.CharField(blank=True, default='', max_length=20), + ), + migrations.AlterField( + model_name='competition', + name='slug', + field=models.SlugField(unique=True), + ), + ] diff --git a/entries/models.py b/entries/models.py index fbea350..4efad68 100644 --- a/entries/models.py +++ b/entries/models.py @@ -70,12 +70,14 @@ class Meta: class Competition(ResultsFormatFields, models.Model): tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE) + name_override = models.CharField(max_length=200, blank=True, default='', help_text='Override the recurring tournament name') + short_name_override = models.CharField(max_length=20, blank=True, default='') admins = models.ManyToManyField('core.User', blank=True) date = models.DateField() end_date = models.DateField(blank=True, null=True) - slug = models.SlugField(editable=False, unique=True) + slug = models.SlugField(unique=True) created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) @@ -89,7 +91,15 @@ def get_absolute_url(self): return reverse('competition_detail', kwargs={'slug': self.slug}) def __str__(self): - return u'{0} {1}'.format(self.tournament, self.date.year) + return u'{0} {1}'.format(self.short_name, self.date.year) + + @property + def full_name(self): + return self.name_override or self.tournament.full_name + + @property + def short_name(self): + return self.short_name_override or self.tournament.short_name def clean(self, *args, **kwargs): if self.end_date is None: diff --git a/entries/templates/entries/competition_detail.html b/entries/templates/entries/competition_detail.html index d60bc07..b1dc38c 100644 --- a/entries/templates/entries/competition_detail.html +++ b/entries/templates/entries/competition_detail.html @@ -3,8 +3,8 @@ {% block precontent %}