forked from DGNum/gestioCOF
Merge branch 'Elarnon/bda_tirage_message_d_erreur_quand_il_y_a_une_erreur' into 'master'
Affiche un message d'erreur lors de l'enregistrement des voeux BDA See merge request klub-dev-ens/gestioCOF!330
This commit is contained in:
commit
6524f89ebd
1 changed files with 21 additions and 16 deletions
37
bda/views.py
37
bda/views.py
|
@ -10,6 +10,7 @@ from django.conf import settings
|
|||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core import serializers
|
||||
from django.core.exceptions import NON_FIELD_ERRORS
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db import transaction
|
||||
from django.db.models import Count, Prefetch
|
||||
|
@ -188,22 +189,38 @@ def inscription(request, tirage_id):
|
|||
ChoixSpectacle,
|
||||
fields=("spectacle", "double_choice", "priority"),
|
||||
formset=InscriptionInlineFormSet,
|
||||
error_messages={
|
||||
NON_FIELD_ERRORS: {
|
||||
"unique_together": "Vous avez déjà demandé ce voeu plus haut !"
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
success = False
|
||||
stateerror = False
|
||||
if request.method == "POST":
|
||||
# use *this* queryset
|
||||
dbstate = _hash_queryset(participant.choixspectacle_set.all())
|
||||
if "dbstate" in request.POST and dbstate != request.POST["dbstate"]:
|
||||
stateerror = True
|
||||
formset = BdaFormSet(instance=participant)
|
||||
messages.error(
|
||||
request,
|
||||
"Impossible d'enregistrer vos modifications "
|
||||
": vous avez apporté d'autres modifications "
|
||||
"entre temps.",
|
||||
)
|
||||
else:
|
||||
formset = BdaFormSet(request.POST, instance=participant)
|
||||
if formset.is_valid():
|
||||
formset.save()
|
||||
success = True
|
||||
formset = BdaFormSet(instance=participant)
|
||||
messages.success(
|
||||
request, "Votre inscription a été mise à jour avec succès !"
|
||||
)
|
||||
else:
|
||||
messages.error(
|
||||
request,
|
||||
"Une erreur s'est produite lors de l'enregistrement de vos vœux. "
|
||||
"Avez-vous demandé plusieurs fois le même spectacle ?",
|
||||
)
|
||||
else:
|
||||
formset = BdaFormSet(instance=participant)
|
||||
# use *this* queryset
|
||||
|
@ -214,18 +231,6 @@ def inscription(request, tirage_id):
|
|||
total_price += choice.spectacle.price
|
||||
if choice.double:
|
||||
total_price += choice.spectacle.price
|
||||
# Messages
|
||||
if success:
|
||||
messages.success(
|
||||
request, "Votre inscription a été mise à jour avec " "succès !"
|
||||
)
|
||||
if stateerror:
|
||||
messages.error(
|
||||
request,
|
||||
"Impossible d'enregistrer vos modifications "
|
||||
": vous avez apporté d'autres modifications "
|
||||
"entre temps.",
|
||||
)
|
||||
return render(
|
||||
request,
|
||||
"bda/inscription-tirage.html",
|
||||
|
|
Loading…
Reference in a new issue