2023-04-03 16:10:52 +00:00
|
|
|
# Copyright (C) 2020 by Animath
|
2023-03-22 11:26:27 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2023-04-03 16:10:52 +00:00
|
|
|
|
|
|
|
from django.contrib import admin
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
2023-04-05 15:52:46 +00:00
|
|
|
from .models import Draw, Pool, Round, TeamDraw
|
2023-04-03 16:10:52 +00:00
|
|
|
|
|
|
|
|
2024-02-23 20:43:44 +00:00
|
|
|
class RoundInline(admin.TabularInline):
|
|
|
|
model = Round
|
|
|
|
extra = 0
|
|
|
|
autocomplete_fields = ('draw', 'current_pool',)
|
|
|
|
show_change_link = True
|
|
|
|
|
|
|
|
|
|
|
|
class PoolInline(admin.TabularInline):
|
|
|
|
model = Pool
|
|
|
|
extra = 0
|
|
|
|
autocomplete_fields = ('round', 'current_team', 'associated_pool',)
|
|
|
|
show_change_link = True
|
|
|
|
|
|
|
|
|
|
|
|
class TeamDrawInline(admin.TabularInline):
|
|
|
|
model = TeamDraw
|
|
|
|
extra = 0
|
|
|
|
autocomplete_fields = ('participation', 'round', 'pool',)
|
|
|
|
show_change_link = True
|
|
|
|
|
|
|
|
|
2023-04-03 16:10:52 +00:00
|
|
|
@admin.register(Draw)
|
|
|
|
class DrawAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('tournament', 'teams', 'current_round', 'get_state',)
|
2024-02-23 20:43:44 +00:00
|
|
|
list_filter = ('tournament', 'current_round__number',)
|
2023-04-03 16:10:52 +00:00
|
|
|
search_fields = ('tournament__name', 'tournament__participation__team__trigram',)
|
2024-02-23 20:43:44 +00:00
|
|
|
autocomplete_fields = ('tournament',)
|
|
|
|
inlines = (RoundInline,)
|
2023-04-03 16:10:52 +00:00
|
|
|
|
|
|
|
@admin.display(description=_("teams"))
|
|
|
|
def teams(self, record: Draw):
|
|
|
|
return ', '.join(p.team.trigram for p in record.tournament.participations.filter(valid=True).all())
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Round)
|
|
|
|
class RoundAdmin(admin.ModelAdmin):
|
2024-02-23 20:43:44 +00:00
|
|
|
list_display = ('draw', 'tournament', 'number', 'teams',)
|
2023-04-03 16:10:52 +00:00
|
|
|
list_filter = ('draw__tournament', 'number',)
|
|
|
|
search_fields = ('draw__tournament__name', 'pool__teamdraw__participation__team__trigram')
|
|
|
|
ordering = ('draw__tournament__name', 'number')
|
2024-02-23 20:43:44 +00:00
|
|
|
autocomplete_fields = ('draw', 'current_pool',)
|
|
|
|
inlines = (PoolInline,)
|
|
|
|
|
|
|
|
@admin.display(description=_("tournament"), ordering='draw__tournament__name')
|
|
|
|
def tournament(self, record):
|
|
|
|
return record.draw.tournament
|
2023-04-03 16:10:52 +00:00
|
|
|
|
|
|
|
@admin.display(description=_("teams"))
|
|
|
|
def teams(self, record: Round):
|
|
|
|
return ', '.join(td.participation.team.trigram for td in record.team_draws)
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Pool)
|
|
|
|
class PoolAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('tournament', 'round', 'letter', 'teams')
|
|
|
|
list_filter = ('round__draw__tournament', 'round__number', 'letter')
|
|
|
|
ordering = ('round__draw__tournament__name', 'round', 'letter')
|
|
|
|
search_fields = ('round__draw__tournament__name', 'teamdraw__participation__team__trigram',)
|
2024-02-23 20:43:44 +00:00
|
|
|
autocomplete_fields = ('round', 'current_team', 'associated_pool',)
|
|
|
|
inlines = (TeamDrawInline,)
|
2023-04-03 16:10:52 +00:00
|
|
|
|
|
|
|
@admin.display(ordering='round__draw__tournament__name', description=_("tournament"))
|
|
|
|
def tournament(self, record):
|
|
|
|
return record.round.draw.tournament
|
|
|
|
|
|
|
|
@admin.display(description=_("teams"))
|
|
|
|
def teams(self, record: Round):
|
|
|
|
return ', '.join(td.participation.team.trigram for td in record.team_draws)
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(TeamDraw)
|
|
|
|
class TeamDrawAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('participation', 'tournament', 'view_round', 'pool', 'accepted', 'rejected',
|
|
|
|
'passage_index', 'choose_index', 'passage_dice', 'choice_dice',)
|
|
|
|
list_filter = ('round__draw__tournament', 'round__number', 'pool__letter',)
|
|
|
|
search_fields = ('round__draw__tournament__name', 'participation__team__trigram',)
|
2024-02-23 20:43:44 +00:00
|
|
|
autocomplete_fields = ('participation', 'round', 'pool',)
|
2023-04-03 16:10:52 +00:00
|
|
|
|
|
|
|
@admin.display(ordering='round__draw__tournament__name', description=_("tournament"))
|
|
|
|
def tournament(self, record):
|
|
|
|
return record.round.draw.tournament
|
|
|
|
|
|
|
|
@admin.display(ordering='round__number', description=_('round'))
|
|
|
|
def view_round(self, record):
|
2023-04-05 15:52:46 +00:00
|
|
|
return record.round.get_number_display()
|