From 442f358cf5c35a19ae39a85aa4157d420f311ccb Mon Sep 17 00:00:00 2001 From: ludo Date: Sat, 25 Jun 2016 23:17:31 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Ajoute=20une=20v=C3=A9rification=20de=20tir?= =?UTF-8?q?age?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bda/admin.py | 11 +++++++++++ bda/models.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/bda/admin.py b/bda/admin.py index 476f7d89..0e257593 100644 --- a/bda/admin.py +++ b/bda/admin.py @@ -5,6 +5,7 @@ from django.core.mail import send_mail from django.contrib import admin from django.db.models import Sum, Count from bda.models import Spectacle, Salle, Participant, ChoixSpectacle, Attribution, Tirage +from django import forms from datetime import timedelta @@ -107,6 +108,15 @@ Le Bureau des Arts self.message_user(request, u"%s été informé%s avec succès." % (message_bit, plural)) send_attribs.short_description = u"Envoyer les résultats par mail" +class AttributionAdminForm(forms.ModelForm): + def clean(self): + cleaned_data=super(AttributionAdminForm, self).clean() + participant = cleaned_data.get("participant") + spectacle = cleaned_data.get("spectacle") + if participant and spectacle: + if participant.tirage != spectacle.tirage: + raise forms.ValidationError(u"Erreur : le participant et le spectacle n'appartiennent pas au même tirage") + class AttributionAdmin(admin.ModelAdmin): def paid(self, obj): return obj.participant.paid @@ -114,6 +124,7 @@ class AttributionAdmin(admin.ModelAdmin): paid.boolean = True list_display = ("id", "spectacle", "participant", "given", "paid") search_fields = ('spectacle__title', 'participant__user__username', 'participant__user__first_name', 'participant__user__last_name') + form = AttributionAdminForm import autocomplete_light class ChoixSpectacleAdmin(admin.ModelAdmin): diff --git a/bda/models.py b/bda/models.py index 16ea4818..294870c6 100644 --- a/bda/models.py +++ b/bda/models.py @@ -75,7 +75,7 @@ class Participant(models.Model): tirage = models.ForeignKey(Tirage) def __unicode__ (self): - return u"%s" % (self.user) + return u"%s, %s" % (self.user, self.tirage.title) DOUBLE_CHOICES = ( ("1", "1 place"), From dc02e9cd45db8379c7953c1335f2bf2959d8b46f Mon Sep 17 00:00:00 2001 From: ludo Date: Mon, 27 Jun 2016 13:18:58 +0200 Subject: [PATCH 2/2] ajoute des filtres pour les voeux et spectacles --- bda/admin.py | 11 +++++++---- bda/models.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bda/admin.py b/bda/admin.py index 0e257593..604ac883 100644 --- a/bda/admin.py +++ b/bda/admin.py @@ -116,6 +116,7 @@ class AttributionAdminForm(forms.ModelForm): if participant and spectacle: if participant.tirage != spectacle.tirage: raise forms.ValidationError(u"Erreur : le participant et le spectacle n'appartiennent pas au même tirage") + return cleaned_data class AttributionAdmin(admin.ModelAdmin): def paid(self, obj): @@ -129,14 +130,16 @@ class AttributionAdmin(admin.ModelAdmin): import autocomplete_light class ChoixSpectacleAdmin(admin.ModelAdmin): form = autocomplete_light.modelform_factory(ChoixSpectacle, exclude=[]) - list_display = ("participant", "spectacle", "priority", "double_choice") - list_filter = ("double_choice",) + def tirage(self, obj): + return obj.participant.tirage + list_display = ("participant", "tirage", "spectacle", "priority", "double_choice") + list_filter = ("double_choice", "participant__tirage") search_fields = ('participant__user__username', 'participant__user__first_name', 'participant__user__last_name') class SpectacleAdmin(admin.ModelAdmin): model = Spectacle - list_display = ("title", "date", "location", "slots", "price") - list_filter = ("location",) + list_display = ("title", "date", "tirage", "location", "slots", "price") + list_filter = ("location", "tirage",) search_fields = ("title", "location__name") class TirageAdmin(admin.ModelAdmin): diff --git a/bda/models.py b/bda/models.py index 294870c6..16ea4818 100644 --- a/bda/models.py +++ b/bda/models.py @@ -75,7 +75,7 @@ class Participant(models.Model): tirage = models.ForeignKey(Tirage) def __unicode__ (self): - return u"%s, %s" % (self.user, self.tirage.title) + return u"%s" % (self.user) DOUBLE_CHOICES = ( ("1", "1 place"),