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

Better "home pages" #108

Merged
merged 6 commits into from
Jul 8, 2023
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
6 changes: 3 additions & 3 deletions core/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
{% block head %}
{% block meta %}
<title>{% block title %}{% if title %}{{ title }} | {% endif %}Archery Tournaments{% endblock %}</title>
<meta property="og:title" content="{% if title %}{{ title }}{% else %}Archery Tournaments{% endif %}" />
<title>{% block title %}{% if title %}{{ title }} | {% endif %}Archery Competitions{% endblock %}</title>
<meta property="og:title" content="{% if title %}{{ title }}{% else %}Archery Competitions{% endif %}" />
<meta property="og:site_name" content="TamlynScore" />
{% if meta_description %}
<meta property="og:description" content="{{ meta_description }}" />
Expand All @@ -29,7 +29,7 @@
</div>
<div class="nav-links">
{% block nav_links %}
<a href="{% url 'tournaments_list' %}" class="nav-link">Tournaments</a>
<a href="{% url 'tournaments_list' %}" class="nav-link">Competitions</a>
<a href="{% url 'club_list' %}" class="nav-link">Clubs</a>
{% endblock nav_links %}
</div>
Expand Down
45 changes: 41 additions & 4 deletions core/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,52 @@ <h1>TamlynScore</h1>
<p>TamlynScore is an online platform for running archery competitions.<br>If you'd like to use TamlynScore for your event, please <a href="mailto:hello@tamlynscore.co.uk?subject=TamlynScore" class="link">contact us</a>.</p>
</div>

<h2>Competitions</h2>
<div class="row">
{% if current_competitions %}
<div class="col3">
<h3>In progress and coming soon</h3>
<ul class="link-list">
{% for competition in current_competitions %}
<li>
<a href="{% url 'competition_detail' slug=competition.slug %}">
{{ competition }}
<small>{{ competition.date|date:"jS F" }}</small>
</a>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% if recent_competitions %}
<div class="col3">
<h3>Recently Finished</h3>
<ul class="link-list">
{% for competition in recent_competitions %}
<li>
<a href="{% url 'competition_detail' slug=competition.slug %}">
{{ competition }}
<small>{{ competition.date|date:"jS F" }}</small>
</a>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
</div>

{% if seasons %}
<h2>Leagues</h2>
<div class="leagues">
{% for league in leagues %}
<a href="{% firstof league.get_current_season.get_absolute_url league.get_absolute_url %}">
{% for season in seasons %}
<a href="{% firstof season.league.get_current_season.get_absolute_url league.get_absolute_url %}">
<div class="leagues__block">
<img class="leagues__img" src="{% static 'leagues/logos/'|add:league.slug|add:'.png' %}">
<h3>{{ league }}</h3>
<img class="leagues__img" src="{% static 'leagues/logos/'|add:season.league.slug|add:'.png' %}">
<h3>{{ season.league }}</h3>
</div>
</a>
{% endfor %}
</div>
{% endif %}

{% endblock %}
22 changes: 20 additions & 2 deletions core/views.py
Original file line number Diff line number Diff line change
@@ -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,
)
Expand All @@ -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
Expand Down Expand Up @@ -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


Expand Down
28 changes: 28 additions & 0 deletions entries/migrations/0034_competition_name_override_and_more.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
14 changes: 12 additions & 2 deletions entries/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
118 changes: 101 additions & 17 deletions entries/templates/entries/competition_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
{% block precontent %}
<header class="banner competition-banner">
<a href="{% url 'competition_detail' slug=competition.slug %}" class="main">
<h1>{{ competition.tournament }}</h1>
<p>{{ competition.date }}{% if competition.end_date > competition.date %} to {{ competition.end_date }}{% endif %}</p>
<h1>{{ competition.short_name }}</h1>
<p>{{ competition.date|date:"jS F Y" }}{% if competition.end_date > competition.date %} to {{ competition.end_date }}{% endif %}</p>
</a>

<span class="byline">Malcolm Rees</span>
Expand Down Expand Up @@ -61,25 +61,109 @@ <h1>{{ competition.tournament }}</h1>

{% block content %}
{% block competition_content %}
<h1>{{ competition.full_name }}</h1>
<div class="row">
{% if is_future %}
<div class="col6">
<h3>About this competition</h3>
<dl>
<dt>Tournament date(s)</dt>
<dd>{{ competition.date }}{% if not competition.end_date == competition.date %} to {{ competition.end_date }}{% endif %}</dd>
<dt>Hosted by</dt>
<dd>{{ competition.tournament.host_club.name }}</dd>
<dt>Options</dt>
<dd>
<ul>
<li>{% if competition.has_novices %}Has a novice category{% else %}Does not have a novice category{% endif %}</li>
{% if competition.has_novices %}
<li>{% if competition.novices_in_experienced_teams %}Novices can be in experienced teams{% else %}Novices cannot be in experienced teams{% endif %}</li>
<h2>Tournament information</h2>
</div>

<div class="col3">
<h3>Entry stats</h3>
<ul class="bullets">
{% for round in rounds %}
<li>{{ round }}</li>
{% endfor %}
</ul>
<p>Total entries</p>
<p>{{ entry_count }}</p>

<!--p><b>TODO!</b> Copy the entry stats section from Manage Entries here?</p-->
</div>

<div class="col3">
<h3>Target List</h3>
{% if target_list_set %}
<p><a class="btn" href="{% url 'target_list' slug=competition.slug %}">View online</a></p>
<!--p><b>TODO!</b> Add link to download, make this look less shit</p-->
{% else %}
<p>Target list coming soon.</p>
{% endif %}
</div>

{% else %}
{% if by_round %}
<div class="col3">
<h2>Results by round</h2>
<table class="table">
{% for round, categories in by_round.items %}
{% for category, scores in categories.items %}
<tr><th colspan="100%">{{ round }} - {{ category }}</th></tr>
{% for score in scores|slice:":3" %}
<tr>
<td>{% if score.placing %}{{ score.placing }}{% endif %}</td>
<td>{{ score.target.session_entry.competition_entry.archer }}</td>
<td>{{ score.details.0 }}</td>
</tr>
{% endfor %}
{% endfor %}
{% endfor %}
</table>
<p><a class="btn" href="{% url 'results' slug=competition.slug mode='by-round' format='html' %}">Full results by round</a></p>
</div>
{% endif %}
{% endif %}

{% if legs %}
<div class="col3">
{% if legs %}
{% for leg in legs %}

<h2>{{ leg.season.league }}</h2>
<p>This event is part of {{ leg }}.</p>
<p><a class="btn" href="{{ leg.season.get_absolute_url }}">View season</a></p>

{% if leg.competitions.count > 1 %}
<p>The other events in this leg are:</p>
<p>
<ul class="link-list">
{% for event in leg.competitions.all %}
{% if event.id != competition.id %}
<li><a href="{% url 'competition_detail' slug=event.slug %}">{{ event.tournament }}</a></li>
{% endif %}
</ul>
</dd>
</dl>
{% endfor %}
</ul>
{% endif %}

{% if leg.result_modes.all %}
<p>Combined results can be viewed at:</p>
<ul class="link-list">
{% for mode in leg.result_modes.all %}
<li><a href="{{ mode.get_absolute_url }}">{{ mode }}</a></li>
{% endfor %}
</ul>
{% endif %}

{% endfor %}
{% endif %}
</div>
{% endif %}

{% if related_events %}
<div class="col3">
<h2>Other editions</h2>
<ul class="link-list">
{% for event in related_events %}
<li>
<a href="{% url 'competition_detail' slug=event.slug %}">
{{ event }}
<small>{{ event.date|date:"jS F Y" }}</small>
</a>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
</div>
{% endblock %}
{% endblock %}
Expand Down
Loading