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
|
2021-01-21 21:22:21 +00:00
|
|
|
from django.contrib.admin import ModelAdmin
|
2024-02-23 20:43:44 +00:00
|
|
|
from django.contrib.auth.admin import UserAdmin
|
|
|
|
from django.contrib.auth.models import User
|
2023-04-03 17:13:15 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2024-02-23 20:43:44 +00:00
|
|
|
from polymorphic.admin import PolymorphicChildModelAdmin, PolymorphicChildModelFilter, PolymorphicParentModelAdmin, \
|
|
|
|
PolymorphicInlineSupportMixin, StackedPolymorphicInline
|
2020-12-27 10:49:54 +00:00
|
|
|
|
2023-04-05 15:52:46 +00:00
|
|
|
from .models import CoachRegistration, ParticipantRegistration, Payment, Registration, \
|
2023-04-03 17:13:15 +00:00
|
|
|
StudentRegistration, VolunteerRegistration
|
2020-12-27 10:49:54 +00:00
|
|
|
|
|
|
|
|
2024-02-23 20:43:44 +00:00
|
|
|
class RegistrationInline(StackedPolymorphicInline):
|
|
|
|
class StudentRegistrationInline(StackedPolymorphicInline.Child):
|
|
|
|
model = StudentRegistration
|
|
|
|
autocomplete_fields = ('team',)
|
|
|
|
show_change_link = True
|
|
|
|
|
|
|
|
class CoachRegistrationInline(StackedPolymorphicInline.Child):
|
|
|
|
model = CoachRegistration
|
|
|
|
autocomplete_fields = ('team',)
|
|
|
|
show_change_link = True
|
|
|
|
|
|
|
|
class VolunteerRegistrationInline(StackedPolymorphicInline.Child):
|
|
|
|
model = VolunteerRegistration
|
|
|
|
show_change_link = True
|
|
|
|
|
|
|
|
model = Registration
|
|
|
|
child_inlines = (
|
|
|
|
StudentRegistrationInline,
|
|
|
|
CoachRegistrationInline,
|
|
|
|
VolunteerRegistrationInline,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class PaymentInline(admin.TabularInline):
|
|
|
|
model = Payment
|
|
|
|
extra = 0
|
|
|
|
autocomplete_fields = ('registrations',)
|
|
|
|
|
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
@admin.register(Registration)
|
|
|
|
class RegistrationAdmin(PolymorphicParentModelAdmin):
|
2023-02-19 23:23:18 +00:00
|
|
|
child_models = (StudentRegistration, CoachRegistration, VolunteerRegistration,)
|
2023-04-03 17:13:15 +00:00
|
|
|
list_display = ('user', 'first_name', 'last_name', 'type', 'email_confirmed',)
|
|
|
|
list_filter = (PolymorphicChildModelFilter, 'email_confirmed',)
|
|
|
|
search_fields = ('user__first_name', 'user__last_name', 'user__email',)
|
2020-12-27 10:49:54 +00:00
|
|
|
polymorphic_list = True
|
|
|
|
|
2023-04-03 17:13:15 +00:00
|
|
|
@admin.display(description=_('first name'), ordering='user__first_name')
|
|
|
|
def first_name(self, record):
|
|
|
|
return record.user.first_name
|
|
|
|
|
|
|
|
@admin.display(description=_('last name'), ordering='user__last_name')
|
|
|
|
def last_name(self, record):
|
|
|
|
return record.user.last_name
|
|
|
|
|
2023-04-05 15:52:46 +00:00
|
|
|
|
2023-04-03 17:13:15 +00:00
|
|
|
@admin.register(ParticipantRegistration)
|
|
|
|
class ParticipantRegistrationAdmin(PolymorphicChildModelAdmin):
|
|
|
|
list_display = ('user', 'first_name', 'last_name', 'type', 'team', 'email_confirmed',)
|
|
|
|
list_filter = ('email_confirmed',)
|
|
|
|
search_fields = ('user__first_name', 'user__last_name', 'user__email',)
|
|
|
|
autocomplete_fields = ('user', 'team',)
|
|
|
|
|
|
|
|
@admin.display(description=_('first name'), ordering='user__first_name')
|
|
|
|
def first_name(self, record):
|
|
|
|
return record.user.first_name
|
|
|
|
|
|
|
|
@admin.display(description=_('last name'), ordering='user__last_name')
|
|
|
|
def last_name(self, record):
|
|
|
|
return record.user.last_name
|
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
|
|
|
|
@admin.register(StudentRegistration)
|
|
|
|
class StudentRegistrationAdmin(PolymorphicChildModelAdmin):
|
2023-04-03 17:13:15 +00:00
|
|
|
list_display = ('user', 'first_name', 'last_name', 'team', 'email_confirmed',)
|
|
|
|
list_filter = ('email_confirmed',)
|
|
|
|
search_fields = ('user__first_name', 'user__last_name', 'user__email',)
|
|
|
|
autocomplete_fields = ('user', 'team',)
|
|
|
|
|
|
|
|
@admin.display(description=_('first name'), ordering='user__first_name')
|
|
|
|
def first_name(self, record):
|
|
|
|
return record.user.first_name
|
|
|
|
|
|
|
|
@admin.display(description=_('last name'), ordering='user__last_name')
|
|
|
|
def last_name(self, record):
|
|
|
|
return record.user.last_name
|
2020-12-27 10:49:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
@admin.register(CoachRegistration)
|
|
|
|
class CoachRegistrationAdmin(PolymorphicChildModelAdmin):
|
2023-04-03 17:13:15 +00:00
|
|
|
list_display = ('user', 'first_name', 'last_name', 'team', 'email_confirmed',)
|
|
|
|
list_filter = ('email_confirmed',)
|
|
|
|
search_fields = ('user__first_name', 'user__last_name', 'user__email',)
|
|
|
|
autocomplete_fields = ('user', 'team',)
|
|
|
|
|
|
|
|
@admin.display(description=_('first name'), ordering='user__first_name')
|
|
|
|
def first_name(self, record):
|
|
|
|
return record.user.first_name
|
|
|
|
|
|
|
|
@admin.display(description=_('last name'), ordering='user__last_name')
|
|
|
|
def last_name(self, record):
|
|
|
|
return record.user.last_name
|
2020-12-27 10:49:54 +00:00
|
|
|
|
|
|
|
|
2023-02-19 23:23:18 +00:00
|
|
|
@admin.register(VolunteerRegistration)
|
|
|
|
class VolunteerRegistrationAdmin(PolymorphicChildModelAdmin):
|
2023-04-03 17:13:15 +00:00
|
|
|
list_display = ('user', 'first_name', 'last_name', 'tournaments', 'email_confirmed',)
|
|
|
|
list_filter = ('organized_tournaments', 'email_confirmed',)
|
|
|
|
search_fields = ('user__first_name', 'user__last_name', 'user__email',)
|
|
|
|
autocomplete_fields = ('user',)
|
|
|
|
|
|
|
|
@admin.display(description=_('first name'), ordering='user__first_name')
|
|
|
|
def first_name(self, record):
|
|
|
|
return record.user.first_name
|
|
|
|
|
|
|
|
@admin.display(description=_('last name'), ordering='user__last_name')
|
|
|
|
def last_name(self, record):
|
|
|
|
return record.user.last_name
|
|
|
|
|
|
|
|
@admin.display(description=_("tournaments"))
|
|
|
|
def tournaments(self, record):
|
|
|
|
return ', '.join(tr.name for tr in record.interesting_tournaments) or None
|
2021-01-21 21:22:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Payment)
|
|
|
|
class PaymentAdmin(ModelAdmin):
|
2024-02-23 20:43:44 +00:00
|
|
|
list_display = ('concerned_people', 'tournament', 'team', 'grouped', 'type', 'amount', 'valid', )
|
|
|
|
search_fields = ('registrations__user__last_name', 'registrations__user__first_name', 'registrations__user__email',
|
|
|
|
'registrations__team__name', 'registrations__team__participation__team__trigram',)
|
2024-02-12 21:30:27 +00:00
|
|
|
list_filter = ('registrations__team__participation__valid', 'type',
|
2024-02-23 20:43:44 +00:00
|
|
|
'grouped', 'valid', 'registrations__team__participation__tournament', 'final',)
|
2024-02-12 21:30:27 +00:00
|
|
|
autocomplete_fields = ('registrations',)
|
2024-02-23 20:43:44 +00:00
|
|
|
actions = ('mark_as_valid', 'mark_as_pending', 'mark_as_invalid',)
|
2024-02-12 21:30:27 +00:00
|
|
|
|
|
|
|
@admin.display(description=_('concerned people'))
|
|
|
|
def concerned_people(self, record: Payment):
|
|
|
|
return ", ".join(f"{reg.user.first_name} {reg.user.last_name}" for reg in record.registrations.all())
|
2024-02-23 20:43:44 +00:00
|
|
|
|
|
|
|
@admin.action(description=_('Mark as valid'))
|
|
|
|
def mark_as_valid(self, request, queryset):
|
|
|
|
queryset.update(valid=True)
|
|
|
|
|
|
|
|
@admin.action(description=_('Mark as pending'))
|
|
|
|
def mark_as_pending(self, request, queryset):
|
|
|
|
queryset.update(valid=None)
|
|
|
|
|
|
|
|
@admin.action(description=_('Mark as invalid'))
|
|
|
|
def mark_as_invalid(self, request, queryset):
|
|
|
|
queryset.update(valid=False)
|
|
|
|
|
|
|
|
|
|
|
|
admin.site.unregister(User)
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(User)
|
|
|
|
class UserCustomAdmin(PolymorphicInlineSupportMixin, UserAdmin):
|
|
|
|
inlines = [RegistrationInline]
|