Skip to content

Commit

Permalink
display teams on club details page
Browse files Browse the repository at this point in the history
  • Loading branch information
djbrown authored Mar 29, 2024
1 parent 7c41239 commit 48cf95d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
19 changes: 15 additions & 4 deletions src/clubs/jinja2/clubs/detail.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,22 @@
</li>
<li class="breadcrumb-item active"><a>{{ club.name }}</a></li>
</ol>
<h1>{{ club.name }}&nbsp;<a href="{{ club.source_url }}"><span class="fas fa-link" title="Datenquelle"></span></a></h1>
<h2>Teams</h2>
<h1>{{ club.name }}&nbsp;<a href="{{ club.source_url() }}"><span class="fas fa-link" title="Datenquelle"></span></a></h1>

{% for season, teams in teams_by_season.items() %}
<h2>{{ season }}/{{ season + 1 }}</h2>
<ul>
{% for team in club.team_set.order_by('league__name') %}
<li><a href="{{ team.get_absolute_url() }}">{{ team.name }}</a> (<a href="{{ team.league.get_absolute_url() }}">{{ team.league.abbreviation }}</a>)</li>
{% for team in teams %}
<li>
<a href="{{ team.get_absolute_url() }}">{{ team.name }}</a>
{% if team.league.abbreviation.upper().startswith("M") %}
♂️
{% elif team.league.abbreviation.upper().startswith("F") %}
♀️
{% endif %}
(<a href="{{ team.league.get_absolute_url() }}">{{ team.league.abbreviation }}</a>)
</li>
{% endfor %}
</ul>
{% endfor %}
{% endblock %}
9 changes: 8 additions & 1 deletion src/clubs/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
from collections import defaultdict

from django.shortcuts import get_object_or_404, render

from clubs.models import Club
from teams.models import Team


def detail(request, bhv_id):
club = get_object_or_404(Club, bhv_id=bhv_id)
return render(request, 'clubs/detail.j2', {'club': club})
teams_by_season = defaultdict(list)
team: Team
for team in club.team_set.order_by('-league__season__start_year', 'name', 'league__abbreviation'):
teams_by_season[team.league.season.start_year].append(team)
return render(request, 'clubs/detail.j2', {'club': club, 'teams_by_season': teams_by_season})
16 changes: 8 additions & 8 deletions src/districts/jinja2/districts/detail.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
<li class="breadcrumb-item active"><a>{{ district.name }}</a></li>
</ol>
<h1>{{ district.name }}&nbsp;<a href="{{ district.source_url() }}"><span class="fas fa-link" title="Datenquelle"></span></a></h1>
{% for start_year, leagues in leagues.items() %}
{% for start_year, leagues in leagues.items() %}
<h2>{{ start_year }}/{{ start_year + 1 }}</h2>
<ul>
{% for league in leagues %}
{% for league in leagues %}
<li>
<a href="{{ league.get_absolute_url() }}">
<a href="{{ league.get_absolute_url() }}">{{ league.abbreviation }}</a>
{% if league.abbreviation.upper().startswith("M") %}
<span class="fas fa-male"></span>
♂️
{% elif league.abbreviation.upper().startswith("F") %}
<span class="fas fa-female"></span>
{% endif %}
{{ league.name }}</a>
♀️
{% endif %})
{{ league.name }}
</li>
{% endfor %}
{% endfor %}
</ul>
{% endfor %}
{% endblock %}
2 changes: 1 addition & 1 deletion src/districts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ def detail(request, bhv_id):
grouped[league.season.start_year].append(league)
sorted_groups = collections.OrderedDict(sorted(grouped.items(), key=lambda t: t[0], reverse=True))
for leagues in sorted_groups.values():
leagues.sort(key=lambda league: league.name)
leagues.sort(key=lambda league: league.abbreviation)
return render(request, 'districts/detail.j2', {'district': district, 'leagues': sorted_groups})

0 comments on commit 48cf95d

Please sign in to comment.