mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 16:02:26 +01:00 
			
		
		
		
	Improve admin interface
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
		@@ -3,31 +3,95 @@
 | 
			
		||||
 | 
			
		||||
from django.contrib import admin
 | 
			
		||||
from django.contrib.admin import ModelAdmin
 | 
			
		||||
from polymorphic.admin import PolymorphicChildModelAdmin, PolymorphicParentModelAdmin
 | 
			
		||||
from django.utils.translation import gettext_lazy as _
 | 
			
		||||
from polymorphic.admin import PolymorphicChildModelAdmin, PolymorphicChildModelFilter, PolymorphicParentModelAdmin
 | 
			
		||||
 | 
			
		||||
from .models import CoachRegistration, Payment, Registration, StudentRegistration, VolunteerRegistration
 | 
			
		||||
from .models import CoachRegistration, Payment, ParticipantRegistration, Registration, \
 | 
			
		||||
    StudentRegistration, VolunteerRegistration
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@admin.register(Registration)
 | 
			
		||||
class RegistrationAdmin(PolymorphicParentModelAdmin):
 | 
			
		||||
    child_models = (StudentRegistration, CoachRegistration, VolunteerRegistration,)
 | 
			
		||||
    list_display = ("user", "type", "email_confirmed",)
 | 
			
		||||
    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',)
 | 
			
		||||
    polymorphic_list = True
 | 
			
		||||
 | 
			
		||||
    @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.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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@admin.register(StudentRegistration)
 | 
			
		||||
class StudentRegistrationAdmin(PolymorphicChildModelAdmin):
 | 
			
		||||
    pass
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@admin.register(CoachRegistration)
 | 
			
		||||
class CoachRegistrationAdmin(PolymorphicChildModelAdmin):
 | 
			
		||||
    pass
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@admin.register(VolunteerRegistration)
 | 
			
		||||
class VolunteerRegistrationAdmin(PolymorphicChildModelAdmin):
 | 
			
		||||
    pass
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@admin.register(Payment)
 | 
			
		||||
@@ -35,3 +99,4 @@ class PaymentAdmin(ModelAdmin):
 | 
			
		||||
    list_display = ('registration', 'type', 'valid', )
 | 
			
		||||
    search_fields = ('registration__user__last_name', 'registration__user__first_name', 'registration__user__email',)
 | 
			
		||||
    list_filter = ('type', 'valid',)
 | 
			
		||||
    autocomplete_fields = ('registration',)
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,26 @@
 | 
			
		||||
# Generated by Django 4.1.7 on 2023-04-03 17:12
 | 
			
		||||
 | 
			
		||||
from django.db import migrations
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Migration(migrations.Migration):
 | 
			
		||||
    dependencies = [
 | 
			
		||||
        ("registration", "0006_alter_registration_polymorphic_ctype"),
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    operations = [
 | 
			
		||||
        migrations.AlterModelOptions(
 | 
			
		||||
            name="participantregistration",
 | 
			
		||||
            options={
 | 
			
		||||
                "verbose_name": "participant registration",
 | 
			
		||||
                "verbose_name_plural": "participant registrations",
 | 
			
		||||
            },
 | 
			
		||||
        ),
 | 
			
		||||
        migrations.AlterModelOptions(
 | 
			
		||||
            name="volunteerregistration",
 | 
			
		||||
            options={
 | 
			
		||||
                "verbose_name": "volunteer registration",
 | 
			
		||||
                "verbose_name_plural": "volunteer registrations",
 | 
			
		||||
            },
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
@@ -192,6 +192,11 @@ class ParticipantRegistration(Registration):
 | 
			
		||||
        raise NotImplementedError
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    class Meta:
 | 
			
		||||
        verbose_name = _("participant registration")
 | 
			
		||||
        verbose_name_plural = _("participant registrations")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class StudentRegistration(ParticipantRegistration):
 | 
			
		||||
    """
 | 
			
		||||
    Specific registration for students.
 | 
			
		||||
@@ -317,6 +322,10 @@ class VolunteerRegistration(Registration):
 | 
			
		||||
        from registration.forms import VolunteerRegistrationForm
 | 
			
		||||
        return VolunteerRegistrationForm
 | 
			
		||||
 | 
			
		||||
    class Meta:
 | 
			
		||||
        verbose_name = _("volunteer registration")
 | 
			
		||||
        verbose_name_plural = _("volunteer registrations")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_scholarship_filename(instance, filename):
 | 
			
		||||
    return f"authorization/scholarship/scholarship_{instance.registration.pk}"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user