Adapte l'interface admin
This commit is contained in:
parent
a67446048e
commit
fa98bb34bd
1 changed files with 47 additions and 11 deletions
58
bda/admin.py
58
bda/admin.py
|
@ -4,7 +4,7 @@ from custommail.shortcuts import send_mass_custom_mail
|
|||
from dal.autocomplete import ModelSelect2
|
||||
from django import forms
|
||||
from django.contrib import admin
|
||||
from django.db.models import Count, Sum
|
||||
from django.db.models import Count, Q, Sum
|
||||
from django.template.defaultfilters import pluralize
|
||||
from django.utils import timezone
|
||||
|
||||
|
@ -81,11 +81,13 @@ class WithListingAttributionInline(AttributionInline):
|
|||
exclude = ("given",)
|
||||
form = WithListingAttributionTabularAdminForm
|
||||
listing = True
|
||||
verbose_name_plural = "Attributions sur listing"
|
||||
|
||||
|
||||
class WithoutListingAttributionInline(AttributionInline):
|
||||
form = WithoutListingAttributionTabularAdminForm
|
||||
listing = False
|
||||
verbose_name_plural = "Attributions hors listing"
|
||||
|
||||
|
||||
class ParticipantAdminForm(forms.ModelForm):
|
||||
|
@ -96,12 +98,32 @@ class ParticipantAdminForm(forms.ModelForm):
|
|||
)
|
||||
|
||||
|
||||
class ParticipantPaidFilter(admin.SimpleListFilter):
|
||||
"""
|
||||
Permet de filtrer les participants sur s'ils ont payé leurs places ou pas
|
||||
"""
|
||||
|
||||
title = "A payé"
|
||||
parameter_name = "paid"
|
||||
|
||||
def lookups(self, request, model_admin):
|
||||
return ((True, "Oui"), (False, "Non"))
|
||||
|
||||
def queryset(self, request, queryset):
|
||||
return queryset.filter(paid=self.value())
|
||||
|
||||
|
||||
class ParticipantAdmin(ReadOnlyMixin, admin.ModelAdmin):
|
||||
inlines = [WithListingAttributionInline, WithoutListingAttributionInline]
|
||||
|
||||
def get_queryset(self, request):
|
||||
return Participant.objects.annotate(
|
||||
nb_places=Count("attributions"), total=Sum("attributions__price")
|
||||
qs = self.model.objects_paid.get_queryset()
|
||||
return qs.annotate(
|
||||
nb_places=Count("attributions"),
|
||||
remain=Sum(
|
||||
"attribution__spectacle__price", filter=Q(attribution__paid=False)
|
||||
),
|
||||
total=Sum("attributions__price"),
|
||||
)
|
||||
|
||||
def nb_places(self, obj):
|
||||
|
@ -110,6 +132,13 @@ class ParticipantAdmin(ReadOnlyMixin, admin.ModelAdmin):
|
|||
nb_places.admin_order_field = "nb_places"
|
||||
nb_places.short_description = "Nombre de places"
|
||||
|
||||
def paid(self, obj):
|
||||
return obj.paid
|
||||
|
||||
paid.short_description = "A payé"
|
||||
paid.boolean = True
|
||||
paid.admin_order_field = "paid"
|
||||
|
||||
def total(self, obj):
|
||||
tot = obj.total
|
||||
if tot:
|
||||
|
@ -118,14 +147,25 @@ class ParticipantAdmin(ReadOnlyMixin, admin.ModelAdmin):
|
|||
return "0 €"
|
||||
|
||||
total.admin_order_field = "total"
|
||||
total.short_description = "Total à payer"
|
||||
list_display = ("user", "nb_places", "total", "paid", "paymenttype", "tirage")
|
||||
list_filter = ("paid", "tirage")
|
||||
total.short_description = "Total des places"
|
||||
|
||||
def remain(self, obj):
|
||||
rem = obj.remain
|
||||
if rem:
|
||||
return "%.02f €" % rem
|
||||
else:
|
||||
return "0 €"
|
||||
|
||||
remain.admin_order_field = "remain"
|
||||
remain.short_description = "Reste à payer"
|
||||
|
||||
list_display = ("user", "nb_places", "total", "paid", "remain", "tirage")
|
||||
list_filter = (ParticipantPaidFilter, "tirage")
|
||||
search_fields = ("user__username", "user__first_name", "user__last_name")
|
||||
actions = ["send_attribs"]
|
||||
actions_on_bottom = True
|
||||
list_per_page = 400
|
||||
readonly_fields = ("total",)
|
||||
readonly_fields = ("total", "paid")
|
||||
readonly_fields_update = ("user", "tirage")
|
||||
form = ParticipantAdminForm
|
||||
|
||||
|
@ -183,11 +223,7 @@ class AttributionAdminForm(forms.ModelForm):
|
|||
|
||||
|
||||
class AttributionAdmin(ReadOnlyMixin, admin.ModelAdmin):
|
||||
def paid(self, obj):
|
||||
return obj.participant.paid
|
||||
|
||||
paid.short_description = "A payé"
|
||||
paid.boolean = True
|
||||
list_display = ("id", "spectacle", "participant", "given", "paid")
|
||||
search_fields = (
|
||||
"spectacle__title",
|
||||
|
|
Loading…
Reference in a new issue