forked from DGNum/gestioCOF
Simplifie la Logique
This commit is contained in:
parent
e09fa2b847
commit
511981e762
1 changed files with 14 additions and 24 deletions
38
bda/views.py
38
bda/views.py
|
@ -190,23 +190,31 @@ def inscription(request, tirage_id):
|
||||||
formset=InscriptionInlineFormSet,
|
formset=InscriptionInlineFormSet,
|
||||||
)
|
)
|
||||||
|
|
||||||
success = False
|
|
||||||
stateerror = False
|
|
||||||
form_invalid = False
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
# use *this* queryset
|
# use *this* queryset
|
||||||
dbstate = _hash_queryset(participant.choixspectacle_set.all())
|
dbstate = _hash_queryset(participant.choixspectacle_set.all())
|
||||||
if "dbstate" in request.POST and dbstate != request.POST["dbstate"]:
|
if "dbstate" in request.POST and dbstate != request.POST["dbstate"]:
|
||||||
stateerror = True
|
|
||||||
formset = BdaFormSet(instance=participant)
|
formset = BdaFormSet(instance=participant)
|
||||||
|
messages.error(
|
||||||
|
request,
|
||||||
|
"Impossible d'enregistrer vos modifications "
|
||||||
|
": vous avez apporté d'autres modifications "
|
||||||
|
"entre temps.",
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
formset = BdaFormSet(request.POST, instance=participant)
|
formset = BdaFormSet(request.POST, instance=participant)
|
||||||
if formset.is_valid():
|
if formset.is_valid():
|
||||||
formset.save()
|
formset.save()
|
||||||
success = True
|
|
||||||
formset = BdaFormSet(instance=participant)
|
formset = BdaFormSet(instance=participant)
|
||||||
|
messages.success(
|
||||||
|
request, "Votre inscription a été mise à jour avec succès !"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
form_invalid = True
|
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:
|
else:
|
||||||
formset = BdaFormSet(instance=participant)
|
formset = BdaFormSet(instance=participant)
|
||||||
# use *this* queryset
|
# use *this* queryset
|
||||||
|
@ -217,24 +225,6 @@ def inscription(request, tirage_id):
|
||||||
total_price += choice.spectacle.price
|
total_price += choice.spectacle.price
|
||||||
if choice.double:
|
if choice.double:
|
||||||
total_price += choice.spectacle.price
|
total_price += choice.spectacle.price
|
||||||
# Messages
|
|
||||||
if success:
|
|
||||||
messages.success(
|
|
||||||
request, "Votre inscription a été mise à jour avec succès !"
|
|
||||||
)
|
|
||||||
elif stateerror:
|
|
||||||
messages.error(
|
|
||||||
request,
|
|
||||||
"Impossible d'enregistrer vos modifications "
|
|
||||||
": vous avez apporté d'autres modifications "
|
|
||||||
"entre temps.",
|
|
||||||
)
|
|
||||||
elif form_invalid:
|
|
||||||
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 ?",
|
|
||||||
)
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"bda/inscription-tirage.html",
|
"bda/inscription-tirage.html",
|
||||||
|
|
Loading…
Reference in a new issue