2016-07-15 00:02:56 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-07-15 00:02:56 +02:00
|
|
|
from __future__ import division
|
|
|
|
from __future__ import print_function
|
2016-05-26 22:44:10 +02:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
from django.core.mail import send_mail
|
2012-07-11 17:39:20 +02:00
|
|
|
from django.contrib import admin
|
2014-08-19 12:54:22 +02:00
|
|
|
from django.db.models import Sum, Count
|
2016-11-04 08:35:17 +01:00
|
|
|
from django.template.defaultfilters import pluralize
|
|
|
|
from django.utils import timezone
|
|
|
|
from django import forms
|
2016-07-09 22:31:56 +02:00
|
|
|
from bda.models import Spectacle, Salle, Participant, ChoixSpectacle,\
|
2016-09-03 01:39:33 +02:00
|
|
|
Attribution, Tirage, Quote, CategorieSpectacle, SpectacleRevente
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-06-07 00:00:56 +02:00
|
|
|
from datetime import timedelta
|
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
import autocomplete_light
|
|
|
|
|
|
|
|
|
2012-07-11 17:39:20 +02:00
|
|
|
class ChoixSpectacleInline(admin.TabularInline):
|
|
|
|
model = ChoixSpectacle
|
|
|
|
sortable_field_name = "priority"
|
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
class AttributionInline(admin.TabularInline):
|
|
|
|
model = Attribution
|
2016-06-10 02:00:50 +02:00
|
|
|
extra = 0
|
2016-07-10 13:19:10 +02:00
|
|
|
|
2016-06-10 02:00:50 +02:00
|
|
|
def get_queryset(self, request):
|
|
|
|
qs = super(AttributionInline, self).get_queryset(request)
|
|
|
|
return qs.filter(spectacle__listing=False)
|
|
|
|
|
2016-07-10 13:19:10 +02:00
|
|
|
|
2016-06-10 02:00:50 +02:00
|
|
|
class AttributionInlineListing(admin.TabularInline):
|
|
|
|
model = Attribution
|
|
|
|
exclude = ('given', )
|
|
|
|
extra = 0
|
2016-07-10 13:19:10 +02:00
|
|
|
|
2016-06-10 02:00:50 +02:00
|
|
|
def get_queryset(self, request):
|
|
|
|
qs = super(AttributionInlineListing, self).get_queryset(request)
|
|
|
|
return qs.filter(spectacle__listing=True)
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2012-07-11 17:39:20 +02:00
|
|
|
class ParticipantAdmin(admin.ModelAdmin):
|
2016-07-10 13:19:10 +02:00
|
|
|
inlines = [AttributionInline, AttributionInlineListing]
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2016-05-24 00:25:29 +02:00
|
|
|
def get_queryset(self, request):
|
2016-07-09 21:19:37 +02:00
|
|
|
return Participant.objects.annotate(nb_places=Count('attributions'),
|
|
|
|
total=Sum('attributions__price'))
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
def nb_places(self, obj):
|
2014-08-19 12:54:22 +02:00
|
|
|
return obj.nb_places
|
|
|
|
nb_places.admin_order_field = "nb_places"
|
2013-09-05 22:20:52 +02:00
|
|
|
nb_places.short_description = "Nombre de places"
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
def total(self, obj):
|
2014-08-19 12:54:22 +02:00
|
|
|
tot = obj.total
|
2016-07-09 21:19:37 +02:00
|
|
|
if tot:
|
2016-05-26 22:44:10 +02:00
|
|
|
return "%.02f €" % tot
|
2016-07-09 21:19:37 +02:00
|
|
|
else:
|
2016-05-26 22:44:10 +02:00
|
|
|
return "0 €"
|
2014-08-19 12:54:22 +02:00
|
|
|
total.admin_order_field = "total"
|
2013-09-05 22:20:52 +02:00
|
|
|
total.short_description = "Total à payer"
|
2016-06-19 18:34:44 +02:00
|
|
|
list_display = ("user", "nb_places", "total", "paid", "paymenttype",
|
|
|
|
"tirage")
|
|
|
|
list_filter = ("paid", "tirage")
|
2013-09-05 22:20:52 +02:00
|
|
|
search_fields = ('user__username', 'user__first_name', 'user__last_name')
|
2016-07-09 21:19:37 +02:00
|
|
|
actions = ['send_attribs', ]
|
2013-09-05 22:20:52 +02:00
|
|
|
actions_on_bottom = True
|
|
|
|
list_per_page = 400
|
2016-06-10 18:01:03 +02:00
|
|
|
readonly_fields = ("total",)
|
2013-09-05 22:20:52 +02:00
|
|
|
|
|
|
|
def send_attribs(self, request, queryset):
|
|
|
|
for member in queryset.all():
|
|
|
|
attribs = member.attributions.all()
|
|
|
|
if len(attribs) == 0:
|
2016-05-26 22:44:10 +02:00
|
|
|
mail = """Cher-e %s,
|
2016-06-07 00:00:56 +02:00
|
|
|
|
|
|
|
Tu t'es inscrit-e pour le tirage au sort du BdA. Malheureusement, tu n'as
|
|
|
|
obtenu aucune place.
|
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
Nous proposons cependant de nombreuses offres hors-tirage tout au long de
|
|
|
|
l'année, et nous t'invitons à nous contacter si l'une d'entre elles
|
|
|
|
t'intéresse !
|
2016-06-07 00:00:56 +02:00
|
|
|
--
|
|
|
|
Le Bureau des Arts
|
|
|
|
|
|
|
|
"""
|
|
|
|
name = member.user.get_full_name()
|
|
|
|
mail = mail % name
|
|
|
|
else:
|
2016-07-15 00:02:56 +02:00
|
|
|
mail = """Cher-e %s,
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2016-06-07 00:00:56 +02:00
|
|
|
Tu t'es inscrit-e pour le tirage au sort du BdA. Tu as été sélectionné-e
|
2013-09-05 22:20:52 +02:00
|
|
|
pour les spectacles suivants :
|
|
|
|
|
|
|
|
%s
|
|
|
|
|
|
|
|
*Paiement*
|
2016-06-07 00:00:56 +02:00
|
|
|
L'intégralité de ces places de spectacles est à régler dès maintenant et AVANT
|
|
|
|
le %s, au bureau du COF pendant les heures de permanences (du lundi au vendredi
|
|
|
|
entre 12h et 14h, et entre 18h et 20h). Des facilités de paiement sont bien
|
2016-07-09 22:31:56 +02:00
|
|
|
évidemment possibles : nous pouvons ne pas encaisser le chèque immédiatement,
|
|
|
|
ou bien découper votre paiement en deux fois. Pour ceux qui ne pourraient pas
|
|
|
|
venir payer au bureau, merci de nous contacter par mail.
|
2013-09-05 22:20:52 +02:00
|
|
|
|
|
|
|
*Mode de retrait des places*
|
2016-07-09 22:31:56 +02:00
|
|
|
Au moment du paiement, certaines places vous seront remises directement,
|
|
|
|
d'autres seront à récupérer au cours de l'année, d'autres encore seront
|
|
|
|
nominatives et à retirer le soir même dans les theâtres correspondants.
|
|
|
|
Pour chaque spectacle, vous recevrez un mail quelques jours avant la
|
|
|
|
représentation vous indiquant le mode de retrait.
|
2014-08-19 12:54:22 +02:00
|
|
|
|
|
|
|
Nous vous rappelons que l'obtention de places du BdA vous engage à
|
|
|
|
respecter les règles de fonctionnement :
|
|
|
|
http://www.cof.ens.fr/bda/?page_id=1370
|
|
|
|
Le système de revente des places via les mails BdA-revente sera très
|
|
|
|
prochainement disponible, directement sur votre compte GestioCOF.
|
|
|
|
|
|
|
|
En vous souhaitant de très beaux spectacles tout au long de l'année,
|
2013-09-05 22:20:52 +02:00
|
|
|
--
|
2014-08-19 12:54:22 +02:00
|
|
|
Le Bureau des Arts
|
|
|
|
"""
|
2016-06-07 00:00:56 +02:00
|
|
|
attribs_text = ""
|
|
|
|
name = member.user.get_full_name()
|
|
|
|
for attrib in attribs:
|
2016-05-26 22:44:10 +02:00
|
|
|
attribs_text += "- 1 place pour %s\n" % attrib
|
2016-06-07 00:00:56 +02:00
|
|
|
deadline = member.tirage.fermeture + timedelta(days=7)
|
2016-07-09 22:31:56 +02:00
|
|
|
mail = mail % (name, attribs_text,
|
|
|
|
deadline.strftime('%d %b %Y'))
|
|
|
|
send_mail("Résultats du tirage au sort", mail,
|
|
|
|
"bda@ens.fr", [member.user.email],
|
|
|
|
fail_silently=True)
|
2013-09-05 22:20:52 +02:00
|
|
|
count = len(queryset.all())
|
|
|
|
if count == 1:
|
2016-05-26 22:44:10 +02:00
|
|
|
message_bit = "1 membre a"
|
2013-09-05 22:20:52 +02:00
|
|
|
plural = ""
|
|
|
|
else:
|
2016-05-26 22:44:10 +02:00
|
|
|
message_bit = "%d membres ont" % count
|
2013-09-05 22:20:52 +02:00
|
|
|
plural = "s"
|
2016-05-26 22:44:10 +02:00
|
|
|
self.message_user(request, "%s été informé%s avec succès."
|
2016-07-10 00:26:02 +02:00
|
|
|
% (message_bit, plural))
|
2016-05-26 22:44:10 +02:00
|
|
|
send_attribs.short_description = "Envoyer les résultats par mail"
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2016-06-25 23:17:31 +02:00
|
|
|
class AttributionAdminForm(forms.ModelForm):
|
|
|
|
def clean(self):
|
2016-07-09 21:19:37 +02:00
|
|
|
cleaned_data = super(AttributionAdminForm, self).clean()
|
2016-06-25 23:17:31 +02:00
|
|
|
participant = cleaned_data.get("participant")
|
|
|
|
spectacle = cleaned_data.get("spectacle")
|
|
|
|
if participant and spectacle:
|
|
|
|
if participant.tirage != spectacle.tirage:
|
2016-07-09 22:31:56 +02:00
|
|
|
raise forms.ValidationError(
|
2016-07-15 00:02:56 +02:00
|
|
|
"Erreur : le participant et le spectacle n'appartiennent"
|
|
|
|
"pas au même tirage")
|
2016-06-27 13:18:58 +02:00
|
|
|
return cleaned_data
|
2016-06-25 23:17:31 +02:00
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
class AttributionAdmin(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")
|
2016-07-09 22:31:56 +02:00
|
|
|
search_fields = ('spectacle__title', 'participant__user__username',
|
|
|
|
'participant__user__first_name',
|
|
|
|
'participant__user__last_name')
|
2016-06-25 23:17:31 +02:00
|
|
|
form = AttributionAdminForm
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
class ChoixSpectacleAdmin(admin.ModelAdmin):
|
2016-05-24 00:25:06 +02:00
|
|
|
form = autocomplete_light.modelform_factory(ChoixSpectacle, exclude=[])
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2016-06-27 13:18:58 +02:00
|
|
|
def tirage(self, obj):
|
|
|
|
return obj.participant.tirage
|
2016-07-09 22:31:56 +02:00
|
|
|
list_display = ("participant", "tirage", "spectacle", "priority",
|
|
|
|
"double_choice")
|
2016-06-27 13:18:58 +02:00
|
|
|
list_filter = ("double_choice", "participant__tirage")
|
2016-07-09 22:31:56 +02:00
|
|
|
search_fields = ('participant__user__username',
|
|
|
|
'participant__user__first_name',
|
2016-07-13 01:01:07 +02:00
|
|
|
'participant__user__last_name',
|
|
|
|
'spectacle__title')
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-08-26 05:28:04 +02:00
|
|
|
class QuoteInline(admin.TabularInline):
|
|
|
|
model = Quote
|
|
|
|
|
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
class SpectacleAdmin(admin.ModelAdmin):
|
2016-08-26 05:28:04 +02:00
|
|
|
inlines = [QuoteInline]
|
2014-08-19 12:54:22 +02:00
|
|
|
model = Spectacle
|
2016-07-08 21:53:21 +02:00
|
|
|
list_display = ("title", "date", "tirage", "location", "slots", "price",
|
|
|
|
"listing")
|
2016-06-27 13:18:58 +02:00
|
|
|
list_filter = ("location", "tirage",)
|
2014-08-19 12:54:22 +02:00
|
|
|
search_fields = ("title", "location__name")
|
2016-07-10 14:19:19 +02:00
|
|
|
readonly_fields = ("rappel_sent", )
|
2014-08-19 12:54:22 +02:00
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2016-06-10 17:04:00 +02:00
|
|
|
class TirageAdmin(admin.ModelAdmin):
|
|
|
|
model = Tirage
|
2016-07-08 00:18:58 +02:00
|
|
|
list_display = ("title", "ouverture", "fermeture", "active",
|
2016-08-26 05:28:04 +02:00
|
|
|
"enable_do_tirage")
|
2016-07-08 00:18:58 +02:00
|
|
|
readonly_fields = ("tokens", )
|
2016-06-10 17:04:00 +02:00
|
|
|
list_filter = ("active", )
|
|
|
|
search_fields = ("title", )
|
|
|
|
|
2016-07-13 01:01:07 +02:00
|
|
|
|
|
|
|
class SalleAdmin(admin.ModelAdmin):
|
|
|
|
model = Salle
|
|
|
|
search_fields = ('name', 'address')
|
|
|
|
|
|
|
|
|
2016-07-22 22:48:09 +02:00
|
|
|
class SpectacleReventeAdmin(admin.ModelAdmin):
|
2016-11-04 08:35:17 +01:00
|
|
|
"""
|
|
|
|
Administration des reventes de spectacles
|
|
|
|
"""
|
2016-07-22 22:48:09 +02:00
|
|
|
model = SpectacleRevente
|
|
|
|
|
|
|
|
def spectacle(self, obj):
|
2016-11-04 08:35:17 +01:00
|
|
|
"""
|
|
|
|
Raccourci vers le spectacle associé à la revente.
|
|
|
|
"""
|
2016-07-22 22:48:09 +02:00
|
|
|
return obj.attribution.spectacle
|
|
|
|
|
2016-09-05 03:10:06 +02:00
|
|
|
list_display = ("spectacle", "seller", "date", "soldTo")
|
2016-07-23 22:21:30 +02:00
|
|
|
raw_id_fields = ("attribution",)
|
|
|
|
readonly_fields = ("shotgun", "expiration_time")
|
2016-10-11 14:59:30 +02:00
|
|
|
search_fields = ['attribution__spectacle__title',
|
|
|
|
'seller__user__username',
|
|
|
|
'seller__user__first_name',
|
|
|
|
'seller__user__last_name']
|
2016-07-22 22:48:09 +02:00
|
|
|
|
2016-11-04 08:35:17 +01:00
|
|
|
actions = ['transfer', 'reinit']
|
2016-10-28 03:46:57 +02:00
|
|
|
actions_on_bottom = True
|
|
|
|
|
|
|
|
def transfer(self, request, queryset):
|
2016-11-04 08:35:17 +01:00
|
|
|
"""
|
|
|
|
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:
|
2016-10-28 18:15:37 +02:00
|
|
|
attrib = revente.attribution
|
|
|
|
attrib.participant = revente.soldTo
|
|
|
|
attrib.save()
|
2016-11-04 08:35:17 +01:00
|
|
|
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))
|
|
|
|
)
|
2016-10-28 03:46:57 +02:00
|
|
|
transfer.short_description = "Transférer les reventes sélectionnées"
|
|
|
|
|
|
|
|
def reinit(self, request, queryset):
|
2016-11-04 08:35:17 +01:00
|
|
|
"""
|
|
|
|
Réinitialise les reventes.
|
|
|
|
"""
|
|
|
|
count = queryset.count()
|
2016-10-28 03:46:57 +02:00
|
|
|
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()
|
2016-11-04 08:35:17 +01:00
|
|
|
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))
|
|
|
|
)
|
2016-10-28 03:46:57 +02:00
|
|
|
reinit.short_description = "Réinitialiser les reventes sélectionnées"
|
|
|
|
|
2016-07-22 22:48:09 +02:00
|
|
|
|
2016-08-26 05:28:04 +02:00
|
|
|
admin.site.register(CategorieSpectacle)
|
2014-08-19 12:54:22 +02:00
|
|
|
admin.site.register(Spectacle, SpectacleAdmin)
|
2016-07-13 01:01:07 +02:00
|
|
|
admin.site.register(Salle, SalleAdmin)
|
2012-07-11 17:39:20 +02:00
|
|
|
admin.site.register(Participant, ParticipantAdmin)
|
2013-09-05 22:20:52 +02:00
|
|
|
admin.site.register(Attribution, AttributionAdmin)
|
|
|
|
admin.site.register(ChoixSpectacle, ChoixSpectacleAdmin)
|
2016-06-10 17:04:00 +02:00
|
|
|
admin.site.register(Tirage, TirageAdmin)
|
2016-07-22 22:48:09 +02:00
|
|
|
admin.site.register(SpectacleRevente, SpectacleReventeAdmin)
|