forked from DGNum/gestioCOF
Merge branch 'Kerl/clean_code_amend' into 'Aufinal/clean_code'
Kerl/clean code amend Ajoute quelques commentaires Reformate le texte en 80 colonnes Améliore l'algo d'inscription à la revente en inscrivant les gens à la revente ayant le moins d'inscrits See merge request !135
This commit is contained in:
commit
acfcddce07
1 changed files with 40 additions and 23 deletions
51
bda/views.py
51
bda/views.py
|
@ -271,6 +271,7 @@ def revente(request, tirage_id):
|
||||||
if not participant.paid:
|
if not participant.paid:
|
||||||
return render(request, "bda-notpaid.html", {})
|
return render(request, "bda-notpaid.html", {})
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
# On met en vente une place
|
||||||
if 'resell' in request.POST:
|
if 'resell' in request.POST:
|
||||||
resellform = ResellForm(participant, request.POST, prefix='resell')
|
resellform = ResellForm(participant, request.POST, prefix='resell')
|
||||||
annulform = AnnulForm(participant, prefix='annul')
|
annulform = AnnulForm(participant, prefix='annul')
|
||||||
|
@ -279,7 +280,8 @@ def revente(request, tirage_id):
|
||||||
attributions = resellform.cleaned_data["attributions"]
|
attributions = resellform.cleaned_data["attributions"]
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
for attribution in attributions:
|
for attribution in attributions:
|
||||||
revente, created = SpectacleRevente.objects.get_or_create(
|
revente, created = \
|
||||||
|
SpectacleRevente.objects.get_or_create(
|
||||||
attribution=attribution,
|
attribution=attribution,
|
||||||
defaults={'seller': participant})
|
defaults={'seller': participant})
|
||||||
if not created:
|
if not created:
|
||||||
|
@ -289,21 +291,25 @@ def revente(request, tirage_id):
|
||||||
revente.notif_sent = False
|
revente.notif_sent = False
|
||||||
revente.tirage_done = False
|
revente.tirage_done = False
|
||||||
revente.shotgun = False
|
revente.shotgun = False
|
||||||
mail_subject = "BdA-Revente : {:s}".format(attribution.spectacle.title)
|
mail_subject = "BdA-Revente : {:s}".format(
|
||||||
mail_body = loader.render_to_string('bda/mails/revente-new.txt', {
|
attribution.spectacle.title)
|
||||||
'vendeur': participant.user,
|
mail_body = loader.render_to_string(
|
||||||
|
'bda/mails/revente-new.txt',
|
||||||
|
{'vendeur': participant.user,
|
||||||
'spectacle': attribution.spectacle,
|
'spectacle': attribution.spectacle,
|
||||||
'revente': revente,
|
'revente': revente}
|
||||||
})
|
)
|
||||||
mails.append(mail.EmailMessage(
|
mails.append(mail.EmailMessage(
|
||||||
mail_subject, mail_body,
|
mail_subject, mail_body,
|
||||||
from_email=settings.MAIL_DATA['revente']['FROM'],
|
from_email=settings.MAIL_DATA['revente']['FROM'],
|
||||||
to=[participant.user.email],
|
to=[participant.user.email],
|
||||||
reply_to=[settings.MAIL_DATA['revente']['REPLYTO']],
|
reply_to=[
|
||||||
|
settings.MAIL_DATA['revente']['REPLYTO']
|
||||||
|
],
|
||||||
))
|
))
|
||||||
revente.save()
|
revente.save()
|
||||||
mail.get_connection().send_messages(mails)
|
mail.get_connection().send_messages(mails)
|
||||||
|
# On annule une revente
|
||||||
elif 'annul' in request.POST:
|
elif 'annul' in request.POST:
|
||||||
annulform = AnnulForm(participant, request.POST, prefix='annul')
|
annulform = AnnulForm(participant, request.POST, prefix='annul')
|
||||||
resellform = ResellForm(participant, prefix='resell')
|
resellform = ResellForm(participant, prefix='resell')
|
||||||
|
@ -311,7 +317,8 @@ def revente(request, tirage_id):
|
||||||
attributions = annulform.cleaned_data["attributions"]
|
attributions = annulform.cleaned_data["attributions"]
|
||||||
for attribution in attributions:
|
for attribution in attributions:
|
||||||
attribution.revente.delete()
|
attribution.revente.delete()
|
||||||
|
# On confirme une vente en transférant la place à la personne qui a
|
||||||
|
# gagné le tirage
|
||||||
elif 'transfer' in request.POST:
|
elif 'transfer' in request.POST:
|
||||||
resellform = ResellForm(participant, prefix='resell')
|
resellform = ResellForm(participant, prefix='resell')
|
||||||
annulform = AnnulForm(participant, prefix='annul')
|
annulform = AnnulForm(participant, prefix='annul')
|
||||||
|
@ -324,7 +331,9 @@ def revente(request, tirage_id):
|
||||||
attrib = revente.attribution
|
attrib = revente.attribution
|
||||||
attrib.participant = revente.soldTo
|
attrib.participant = revente.soldTo
|
||||||
attrib.save()
|
attrib.save()
|
||||||
|
# On annule la revente après le tirage au sort (par exemple si
|
||||||
|
# la personne qui a gagné le tirage ne se manifeste pas). La place est
|
||||||
|
# alors remise en vente
|
||||||
elif 'reinit' in request.POST:
|
elif 'reinit' in request.POST:
|
||||||
resellform = ResellForm(participant, prefix='resell')
|
resellform = ResellForm(participant, prefix='resell')
|
||||||
annulform = AnnulForm(participant, prefix='annul')
|
annulform = AnnulForm(participant, prefix='annul')
|
||||||
|
@ -398,16 +407,24 @@ def list_revente(request, tirage_id):
|
||||||
for spectacle in choices:
|
for spectacle in choices:
|
||||||
qset = SpectacleRevente.objects.filter(
|
qset = SpectacleRevente.objects.filter(
|
||||||
attribution__spectacle=spectacle)
|
attribution__spectacle=spectacle)
|
||||||
if qset.exists():
|
if qset.filter(shotgun=True, soldTo__isnull=True).exists():
|
||||||
# On l'inscrit à l'un des tirages au sort
|
# Une place est disponible au shotgun, on suggère à
|
||||||
for revente in qset.all():
|
# l'utilisateur d'aller la récupérer
|
||||||
if revente.shotgun and not revente.soldTo:
|
|
||||||
deja_revente = True
|
deja_revente = True
|
||||||
else:
|
else:
|
||||||
revente.answered_mail.add(participant)
|
# La place n'est pas disponible au shotgun, si des reventes
|
||||||
revente.save()
|
# pour ce spectacle existent déjà, on inscrit la personne à
|
||||||
|
# la revente ayant le moins d'inscrits
|
||||||
|
min_resell = (
|
||||||
|
qset.filter(shotgun=False)
|
||||||
|
.annotate(nb_subscribers=Count('answered_mail'))
|
||||||
|
.order_by('nb_subscribers')
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
if min_resell is not None:
|
||||||
|
min_resell.answered_mail.add(participant)
|
||||||
|
min_resell.save()
|
||||||
inscrit_revente = True
|
inscrit_revente = True
|
||||||
break
|
|
||||||
success = True
|
success = True
|
||||||
else:
|
else:
|
||||||
form = InscriptionReventeForm(
|
form = InscriptionReventeForm(
|
||||||
|
|
Loading…
Reference in a new issue