Merge branch 'Aufinal/reinit_admin' into 'master'
Aufinal/reinit admin Ajoute des fonctions de transfert et de réinitialisation des reventes dans l'interface admin ; fix temporaire pour les bugs de boutons. See merge request !101
This commit is contained in:
commit
388f42b05f
2 changed files with 53 additions and 2 deletions
53
bda/admin.py
53
bda/admin.py
|
@ -5,12 +5,13 @@ from __future__ import print_function
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.core.mail import send_mail
|
||||
|
||||
from django.contrib import admin
|
||||
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,\
|
||||
Attribution, Tirage, Quote, CategorieSpectacle, SpectacleRevente
|
||||
from django import forms
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
|
@ -211,9 +212,15 @@ class SalleAdmin(admin.ModelAdmin):
|
|||
|
||||
|
||||
class SpectacleReventeAdmin(admin.ModelAdmin):
|
||||
"""
|
||||
Administration des reventes de spectacles
|
||||
"""
|
||||
model = SpectacleRevente
|
||||
|
||||
def spectacle(self, obj):
|
||||
"""
|
||||
Raccourci vers le spectacle associé à la revente.
|
||||
"""
|
||||
return obj.attribution.spectacle
|
||||
|
||||
list_display = ("spectacle", "seller", "date", "soldTo")
|
||||
|
@ -224,6 +231,48 @@ class SpectacleReventeAdmin(admin.ModelAdmin):
|
|||
'seller__user__first_name',
|
||||
'seller__user__last_name']
|
||||
|
||||
actions = ['transfer', 'reinit']
|
||||
actions_on_bottom = True
|
||||
|
||||
def transfer(self, request, queryset):
|
||||
"""
|
||||
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.participant = revente.soldTo
|
||||
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"
|
||||
|
||||
def reinit(self, request, queryset):
|
||||
"""
|
||||
Réinitialise les reventes.
|
||||
"""
|
||||
count = queryset.count()
|
||||
for revente in queryset.all():
|
||||
revente.date = timezone.now() - timedelta(hours=1)
|
||||
revente.soldTo = None
|
||||
revente.notif_sent = False
|
||||
revente.tirage_done = False
|
||||
if revente.answered_mail:
|
||||
revente.answered_mail.clear()
|
||||
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"
|
||||
|
||||
|
||||
admin.site.register(CategorieSpectacle)
|
||||
admin.site.register(Spectacle, SpectacleAdmin)
|
||||
|
|
|
@ -333,6 +333,8 @@ def revente(request, tirage_id):
|
|||
revente = rev.get()
|
||||
revente.date = timezone.now() - timedelta(hours=1)
|
||||
revente.soldTo = None
|
||||
revente.notif_sent = False
|
||||
revente.tirage_done = False
|
||||
if revente.answered_mail:
|
||||
revente.answered_mail.clear()
|
||||
revente.save()
|
||||
|
|
Loading…
Reference in a new issue