2020-12-27 10:49:54 +00:00
|
|
|
# Copyright (C) 2020 by Animath
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
from django.contrib import admin
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
2022-05-15 14:43:07 +00:00
|
|
|
from .models import Note, Participation, Passage, Pool, Solution, Synthesis, Team, Tournament, Tweak
|
2020-12-27 10:49:54 +00:00
|
|
|
|
|
|
|
|
2024-02-23 20:43:44 +00:00
|
|
|
class ParticipationInline(admin.StackedInline):
|
|
|
|
model = Participation
|
|
|
|
extra = 0
|
|
|
|
autocomplete_fields = ('team', 'tournament',)
|
|
|
|
show_change_link = True
|
|
|
|
|
|
|
|
|
|
|
|
class ParticipationTabularInline(admin.TabularInline):
|
|
|
|
model = Participation
|
|
|
|
extra = 0
|
|
|
|
fields = ('team', 'valid', 'final',)
|
|
|
|
readonly_fields = ('team',)
|
|
|
|
ordering = ('final', 'valid', 'team__trigram',)
|
|
|
|
autocomplete_fields = ('tournament',)
|
|
|
|
show_change_link = True
|
|
|
|
|
|
|
|
|
|
|
|
class SolutionInline(admin.TabularInline):
|
|
|
|
model = Solution
|
|
|
|
extra = 0
|
|
|
|
ordering = ('problem',)
|
|
|
|
autocomplete_fields = ('participation',)
|
|
|
|
show_change_link = True
|
|
|
|
|
|
|
|
|
|
|
|
class SynthesisInline(admin.TabularInline):
|
|
|
|
model = Synthesis
|
|
|
|
extra = 0
|
|
|
|
ordering = ('passage__solution_number', 'type',)
|
|
|
|
autocomplete_fields = ('passage',)
|
|
|
|
show_change_link = True
|
|
|
|
|
|
|
|
|
|
|
|
class PoolInline(admin.TabularInline):
|
|
|
|
model = Pool
|
|
|
|
extra = 0
|
2024-03-24 14:36:51 +00:00
|
|
|
autocomplete_fields = ('tournament', 'participations', 'jury_president', 'juries',)
|
2024-02-23 20:43:44 +00:00
|
|
|
show_change_link = True
|
|
|
|
|
|
|
|
|
|
|
|
class PassageInline(admin.TabularInline):
|
|
|
|
model = Passage
|
|
|
|
extra = 0
|
|
|
|
ordering = ('position',)
|
2024-07-05 09:47:19 +00:00
|
|
|
autocomplete_fields = ('defender', 'opponent', 'reviewer', 'observer',)
|
2024-02-23 20:43:44 +00:00
|
|
|
show_change_link = True
|
|
|
|
|
|
|
|
|
|
|
|
class NoteInline(admin.TabularInline):
|
|
|
|
model = Note
|
|
|
|
extra = 0
|
|
|
|
autocomplete_fields = ('jury',)
|
|
|
|
show_change_link = True
|
|
|
|
|
|
|
|
|
|
|
|
class TweakInline(admin.TabularInline):
|
|
|
|
model = Tweak
|
|
|
|
extra = 0
|
|
|
|
autocomplete_fields = ('participation', 'pool',)
|
|
|
|
show_change_link = True
|
|
|
|
|
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
@admin.register(Team)
|
|
|
|
class TeamAdmin(admin.ModelAdmin):
|
2023-04-03 17:13:15 +00:00
|
|
|
list_display = ('name', 'trigram', 'tournament', 'valid', 'final',)
|
2020-12-27 10:49:54 +00:00
|
|
|
search_fields = ('name', 'trigram',)
|
2023-04-03 17:13:15 +00:00
|
|
|
list_filter = ('participation__valid', 'participation__tournament', 'participation__final',)
|
2024-02-23 20:43:44 +00:00
|
|
|
inlines = (ParticipationInline,)
|
2020-12-27 10:49:54 +00:00
|
|
|
|
2023-04-03 17:13:15 +00:00
|
|
|
@admin.display(description=_("tournament"))
|
|
|
|
def tournament(self, record):
|
|
|
|
return record.participation.tournament
|
|
|
|
|
|
|
|
@admin.display(description=_("valid"), boolean=True)
|
2020-12-27 10:49:54 +00:00
|
|
|
def valid(self, team):
|
|
|
|
return team.participation.valid
|
|
|
|
|
2023-04-03 17:13:15 +00:00
|
|
|
@admin.display(description=_("selected for final"), boolean=True)
|
|
|
|
def final(self, team):
|
|
|
|
return team.participation.final
|
2020-12-27 10:49:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Participation)
|
|
|
|
class ParticipationAdmin(admin.ModelAdmin):
|
2023-04-03 17:13:15 +00:00
|
|
|
list_display = ('team', 'tournament', 'valid', 'final',)
|
2020-12-27 10:49:54 +00:00
|
|
|
search_fields = ('team__name', 'team__trigram',)
|
2024-03-24 20:37:37 +00:00
|
|
|
list_filter = ('valid', 'tournament',)
|
2023-04-03 17:13:15 +00:00
|
|
|
autocomplete_fields = ('team', 'tournament',)
|
2024-02-23 20:43:44 +00:00
|
|
|
inlines = (SolutionInline, SynthesisInline,)
|
2020-12-28 17:52:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Pool)
|
|
|
|
class PoolAdmin(admin.ModelAdmin):
|
2024-04-18 12:53:58 +00:00
|
|
|
list_display = ('__str__', 'tournament', 'round', 'letter', 'room', 'teams', 'jury_president',)
|
|
|
|
list_filter = ('tournament', 'round', 'letter', 'room',)
|
2020-12-28 17:52:50 +00:00
|
|
|
search_fields = ('participations__team__name', 'participations__team__trigram',)
|
2024-03-24 14:36:51 +00:00
|
|
|
autocomplete_fields = ('tournament', 'participations', 'jury_president', 'juries',)
|
2024-02-23 20:43:44 +00:00
|
|
|
inlines = (PassageInline, TweakInline,)
|
2023-04-03 17:13:15 +00:00
|
|
|
|
|
|
|
@admin.display(description=_("teams"))
|
|
|
|
def teams(self, record: Pool):
|
|
|
|
return ', '.join(p.team.trigram for p in record.participations.all())
|
2020-12-27 10:49:54 +00:00
|
|
|
|
|
|
|
|
2021-01-21 21:22:21 +00:00
|
|
|
@admin.register(Passage)
|
|
|
|
class PassageAdmin(admin.ModelAdmin):
|
2024-07-05 09:00:11 +00:00
|
|
|
list_display = ('__str__', 'defender_trigram', 'solution_number', 'opponent_trigram', 'reviewer_trigram',
|
2024-07-05 09:47:19 +00:00
|
|
|
'observer_trigram', 'pool_abbr', 'position', 'tournament')
|
2023-04-03 17:13:15 +00:00
|
|
|
list_filter = ('pool__tournament', 'pool__round', 'pool__letter', 'solution_number',)
|
2021-01-21 21:22:21 +00:00
|
|
|
search_fields = ('pool__participations__team__name', 'pool__participations__team__trigram',)
|
2024-02-23 20:43:44 +00:00
|
|
|
ordering = ('pool__tournament', 'pool__round', 'pool__letter', 'position',)
|
2024-07-05 09:47:19 +00:00
|
|
|
autocomplete_fields = ('pool', 'defender', 'opponent', 'reviewer', 'observer',)
|
2024-02-23 20:43:44 +00:00
|
|
|
inlines = (NoteInline,)
|
2023-04-03 17:13:15 +00:00
|
|
|
|
2024-02-23 20:43:44 +00:00
|
|
|
@admin.display(description=_("defender"), ordering='defender__team__trigram')
|
2023-04-03 17:13:15 +00:00
|
|
|
def defender_trigram(self, record: Passage):
|
|
|
|
return record.defender.team.trigram
|
|
|
|
|
2024-02-23 20:43:44 +00:00
|
|
|
@admin.display(description=_("opponent"), ordering='opponent__team__trigram')
|
2023-04-03 17:13:15 +00:00
|
|
|
def opponent_trigram(self, record: Passage):
|
|
|
|
return record.opponent.team.trigram
|
|
|
|
|
2024-07-05 09:00:11 +00:00
|
|
|
@admin.display(description=_("reviewer"), ordering='reviewer__team__trigram')
|
|
|
|
def reviewer_trigram(self, record: Passage):
|
|
|
|
return record.reviewer.team.trigram
|
2023-04-03 17:13:15 +00:00
|
|
|
|
2024-07-05 09:47:19 +00:00
|
|
|
@admin.display(description=_("observer"), ordering='observer__team__trigram')
|
|
|
|
def observer_trigram(self, record: Passage):
|
|
|
|
return record.observer.team.trigram
|
|
|
|
|
2024-02-23 20:43:44 +00:00
|
|
|
@admin.display(description=_("pool"), ordering='pool__letter')
|
2023-04-03 17:13:15 +00:00
|
|
|
def pool_abbr(self, record):
|
2024-04-18 13:12:45 +00:00
|
|
|
return f"{record.pool.short_name}"
|
2023-04-03 17:13:15 +00:00
|
|
|
|
2024-02-23 20:43:44 +00:00
|
|
|
@admin.display(description=_("tournament"), ordering='pool__tournament__name')
|
2023-04-03 17:13:15 +00:00
|
|
|
def tournament(self, record: Passage):
|
|
|
|
return record.pool.tournament
|
2021-01-21 21:22:21 +00:00
|
|
|
|
|
|
|
|
2021-04-09 14:17:12 +00:00
|
|
|
@admin.register(Note)
|
|
|
|
class NoteAdmin(admin.ModelAdmin):
|
2023-04-03 17:13:15 +00:00
|
|
|
list_display = ('passage', 'pool', 'jury', 'defender_writing', 'defender_oral',
|
2024-07-05 09:47:19 +00:00
|
|
|
'opponent_writing', 'opponent_oral', 'reviewer_writing', 'reviewer_oral',
|
|
|
|
'observer_writing', 'observer_oral',)
|
2023-04-03 17:13:15 +00:00
|
|
|
list_filter = ('passage__pool__letter', 'passage__solution_number', 'jury',
|
|
|
|
'defender_writing', 'defender_oral', 'opponent_writing', 'opponent_oral',
|
2024-07-05 09:47:19 +00:00
|
|
|
'reviewer_writing', 'reviewer_oral', 'observer_writing', 'observer_oral')
|
2023-04-03 17:13:15 +00:00
|
|
|
search_fields = ('jury__user__last_name', 'jury__user__first_name', 'passage__defender__team__trigram',)
|
|
|
|
autocomplete_fields = ('jury', 'passage',)
|
|
|
|
|
|
|
|
@admin.display(description=_("pool"))
|
|
|
|
def pool(self, record):
|
2024-04-18 13:12:45 +00:00
|
|
|
return record.passage.pool.short_name
|
2021-04-09 14:17:12 +00:00
|
|
|
|
|
|
|
|
2020-12-28 17:52:50 +00:00
|
|
|
@admin.register(Solution)
|
|
|
|
class SolutionAdmin(admin.ModelAdmin):
|
2023-04-03 17:13:15 +00:00
|
|
|
list_display = ('team', 'tournament', 'problem', 'final_solution',)
|
|
|
|
list_filter = ('problem', 'participation__tournament', 'final_solution',)
|
2020-12-28 17:52:50 +00:00
|
|
|
search_fields = ('participation__team__name', 'participation__team__trigram',)
|
2023-04-03 17:13:15 +00:00
|
|
|
autocomplete_fields = ('participation',)
|
|
|
|
|
|
|
|
@admin.display(ordering='participation__team', description=_("team"))
|
|
|
|
def team(self, record):
|
|
|
|
return record.participation.team
|
|
|
|
|
|
|
|
@admin.display(ordering='participation__tournament__name', description=_("tournament"))
|
|
|
|
def tournament(self, record):
|
|
|
|
return Tournament.final_tournament() if record.final_solution else record.participation.tournament
|
2020-12-27 10:49:54 +00:00
|
|
|
|
|
|
|
|
2020-12-28 17:52:50 +00:00
|
|
|
@admin.register(Synthesis)
|
|
|
|
class SynthesisAdmin(admin.ModelAdmin):
|
2023-04-03 17:13:15 +00:00
|
|
|
list_display = ('participation', 'type', 'defender', 'passage',)
|
|
|
|
list_filter = ('participation__tournament', 'type', 'passage__solution_number',)
|
2020-12-28 17:52:50 +00:00
|
|
|
search_fields = ('participation__team__name', 'participation__team__trigram',)
|
2023-04-03 17:13:15 +00:00
|
|
|
autocomplete_fields = ('participation', 'passage',)
|
|
|
|
|
|
|
|
@admin.display(description=_("defender"))
|
|
|
|
def defender(self, record: Synthesis):
|
|
|
|
return record.passage.defender
|
|
|
|
|
|
|
|
@admin.display(description=_("problem"))
|
|
|
|
def problem(self, record: Synthesis):
|
|
|
|
return record.passage.solution_number
|
2020-12-27 10:49:54 +00:00
|
|
|
|
|
|
|
|
2020-12-28 17:52:50 +00:00
|
|
|
@admin.register(Tournament)
|
|
|
|
class TournamentAdmin(admin.ModelAdmin):
|
2024-02-23 20:43:44 +00:00
|
|
|
list_display = ('name', 'date_start', 'date_end',)
|
2020-12-28 17:52:50 +00:00
|
|
|
search_fields = ('name',)
|
2024-02-23 20:43:44 +00:00
|
|
|
ordering = ('date_start', 'name',)
|
2023-04-03 17:13:15 +00:00
|
|
|
autocomplete_fields = ('organizers',)
|
2024-02-23 20:43:44 +00:00
|
|
|
inlines = (ParticipationTabularInline, PoolInline,)
|
2022-05-15 14:43:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Tweak)
|
|
|
|
class TweakAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('participation', 'pool', 'diff',)
|
2024-03-30 19:38:13 +00:00
|
|
|
list_filter = ('pool__tournament', 'pool__round',)
|
|
|
|
search_fields = ('participation__team__name', 'participation__team__trigram',)
|
2023-04-03 17:13:15 +00:00
|
|
|
autocomplete_fields = ('participation', 'pool',)
|