forked from DGNum/gestioCOF
Messages et docstrings
- Ajout d'un message à l'aide de `message_user` lorsque les actions sont effectuées - Ajouts de docstrings là où c'est préconisé par pylint.
This commit is contained in:
parent
8d1f599577
commit
33545b028e
1 changed files with 32 additions and 5 deletions
37
bda/admin.py
37
bda/admin.py
|
@ -5,15 +5,15 @@ from __future__ import print_function
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.db.models import Sum, Count
|
from django.db.models import Sum, Count
|
||||||
|
from django.template.defaultfilters import pluralize
|
||||||
|
from django.utils import timezone
|
||||||
|
from django import forms
|
||||||
from bda.models import Spectacle, Salle, Participant, ChoixSpectacle,\
|
from bda.models import Spectacle, Salle, Participant, ChoixSpectacle,\
|
||||||
Attribution, Tirage, Quote, CategorieSpectacle, SpectacleRevente
|
Attribution, Tirage, Quote, CategorieSpectacle, SpectacleRevente
|
||||||
from django import forms
|
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from django.utils import timezone
|
|
||||||
|
|
||||||
import autocomplete_light
|
import autocomplete_light
|
||||||
|
|
||||||
|
@ -212,9 +212,15 @@ class SalleAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
|
|
||||||
class SpectacleReventeAdmin(admin.ModelAdmin):
|
class SpectacleReventeAdmin(admin.ModelAdmin):
|
||||||
|
"""
|
||||||
|
Administration des reventes de spectacles
|
||||||
|
"""
|
||||||
model = SpectacleRevente
|
model = SpectacleRevente
|
||||||
|
|
||||||
def spectacle(self, obj):
|
def spectacle(self, obj):
|
||||||
|
"""
|
||||||
|
Raccourci vers le spectacle associé à la revente.
|
||||||
|
"""
|
||||||
return obj.attribution.spectacle
|
return obj.attribution.spectacle
|
||||||
|
|
||||||
list_display = ("spectacle", "seller", "date", "soldTo")
|
list_display = ("spectacle", "seller", "date", "soldTo")
|
||||||
|
@ -225,17 +231,32 @@ class SpectacleReventeAdmin(admin.ModelAdmin):
|
||||||
'seller__user__first_name',
|
'seller__user__first_name',
|
||||||
'seller__user__last_name']
|
'seller__user__last_name']
|
||||||
|
|
||||||
actions = ['transfer', 'reinit', ]
|
actions = ['transfer', 'reinit']
|
||||||
actions_on_bottom = True
|
actions_on_bottom = True
|
||||||
|
|
||||||
def transfer(self, request, queryset):
|
def transfer(self, request, queryset):
|
||||||
for revente in queryset.exclude(soldTo__isnull=True).all():
|
"""
|
||||||
|
Effectue le transfert des reventes pour lesquels on connaît l'acheteur.
|
||||||
|
"""
|
||||||
|
reventes = queryset.exclude(soldTo__isnull=True).all()
|
||||||
|
count = reventes.count()
|
||||||
|
for revente in reventes:
|
||||||
attrib = revente.attribution
|
attrib = revente.attribution
|
||||||
attrib.participant = revente.soldTo
|
attrib.participant = revente.soldTo
|
||||||
attrib.save()
|
attrib.save()
|
||||||
|
self.message_user(
|
||||||
|
request,
|
||||||
|
"%d attribution%s %s été transférée%s avec succès." % (
|
||||||
|
count, pluralize(count),
|
||||||
|
pluralize(count, "a,ont"), pluralize(count))
|
||||||
|
)
|
||||||
transfer.short_description = "Transférer les reventes sélectionnées"
|
transfer.short_description = "Transférer les reventes sélectionnées"
|
||||||
|
|
||||||
def reinit(self, request, queryset):
|
def reinit(self, request, queryset):
|
||||||
|
"""
|
||||||
|
Réinitialise les reventes.
|
||||||
|
"""
|
||||||
|
count = queryset.count()
|
||||||
for revente in queryset.all():
|
for revente in queryset.all():
|
||||||
revente.date = timezone.now() - timedelta(hours=1)
|
revente.date = timezone.now() - timedelta(hours=1)
|
||||||
revente.soldTo = None
|
revente.soldTo = None
|
||||||
|
@ -244,6 +265,12 @@ class SpectacleReventeAdmin(admin.ModelAdmin):
|
||||||
if revente.answered_mail:
|
if revente.answered_mail:
|
||||||
revente.answered_mail.clear()
|
revente.answered_mail.clear()
|
||||||
revente.save()
|
revente.save()
|
||||||
|
self.message_user(
|
||||||
|
request,
|
||||||
|
"%d attribution%s %s été réinitialisée%s avec succès." % (
|
||||||
|
count, pluralize(count),
|
||||||
|
pluralize(count, "a,ont"), pluralize(count))
|
||||||
|
)
|
||||||
reinit.short_description = "Réinitialiser les reventes sélectionnées"
|
reinit.short_description = "Réinitialiser les reventes sélectionnées"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue