|
|
|
|
@ -3,6 +3,25 @@ from .models import Club, TeamScore, Tournament, CustomUser, Event, Round, Group |
|
|
|
|
from django.db.models import Q |
|
|
|
|
from django.utils.translation import gettext_lazy as _ |
|
|
|
|
import uuid |
|
|
|
|
from enum import Enum |
|
|
|
|
|
|
|
|
|
class SimpleTournamentListFilter(admin.SimpleListFilter): |
|
|
|
|
# Human-readable title which will be displayed in the |
|
|
|
|
# right admin sidebar just above the filter options. |
|
|
|
|
title = _("tournoi") |
|
|
|
|
|
|
|
|
|
# Parameter for the filter that will be used in the URL query. |
|
|
|
|
parameter_name = "tournament" |
|
|
|
|
|
|
|
|
|
def lookups(self, request, model_admin): |
|
|
|
|
tournaments = Tournament.objects.order_by('-start_date') |
|
|
|
|
return [(t.id, t.filter_name()) for t in tournaments] |
|
|
|
|
|
|
|
|
|
def queryset(self, request, queryset): |
|
|
|
|
if self.value(): |
|
|
|
|
return queryset.filter(tournament__id=self.value()) |
|
|
|
|
else: |
|
|
|
|
return queryset |
|
|
|
|
|
|
|
|
|
class TeamScoreTournamentListFilter(admin.SimpleListFilter): |
|
|
|
|
# Human-readable title which will be displayed in the |
|
|
|
|
@ -41,3 +60,44 @@ class MatchTournamentListFilter(admin.SimpleListFilter): |
|
|
|
|
return queryset.filter(query_round | query_group_stage) |
|
|
|
|
else: |
|
|
|
|
return queryset |
|
|
|
|
|
|
|
|
|
class MatchType(Enum): |
|
|
|
|
GROUP_STAGE = 'Poule' |
|
|
|
|
BRACKET = 'Tableau' |
|
|
|
|
|
|
|
|
|
class MatchTypeListFilter(admin.SimpleListFilter): |
|
|
|
|
# Human-readable title which will be displayed in the |
|
|
|
|
# right admin sidebar just above the filter options. |
|
|
|
|
title = _("Type") |
|
|
|
|
|
|
|
|
|
# Parameter for the filter that will be used in the URL query. |
|
|
|
|
parameter_name = "name" |
|
|
|
|
|
|
|
|
|
def lookups(self, request, model_admin): |
|
|
|
|
return [(tag.name, tag.value) for tag in MatchType] |
|
|
|
|
|
|
|
|
|
def queryset(self, request, queryset): |
|
|
|
|
if self.value() == MatchType.GROUP_STAGE.name: |
|
|
|
|
return queryset.filter(group_stage__isnull=False) |
|
|
|
|
elif self.value() == MatchType.BRACKET.name: |
|
|
|
|
return queryset.filter(round__isnull=False) |
|
|
|
|
else: |
|
|
|
|
return queryset |
|
|
|
|
|
|
|
|
|
class SimpleIndexListFilter(admin.SimpleListFilter): |
|
|
|
|
# Human-readable title which will be displayed in the |
|
|
|
|
# right admin sidebar just above the filter options. |
|
|
|
|
title = _("Index") |
|
|
|
|
|
|
|
|
|
# Parameter for the filter that will be used in the URL query. |
|
|
|
|
parameter_name = "index" |
|
|
|
|
|
|
|
|
|
def lookups(self, request, model_admin): |
|
|
|
|
indexes = Match.objects.values_list('index', flat=True).distinct() |
|
|
|
|
return [(i, i) for i in sorted(indexes)] |
|
|
|
|
|
|
|
|
|
def queryset(self, request, queryset): |
|
|
|
|
if self.value(): |
|
|
|
|
return queryset.filter(index=self.value()) |
|
|
|
|
else: |
|
|
|
|
return queryset |
|
|
|
|
|