fix revente de reventes

This commit is contained in:
Ludovic Stephan 2016-11-12 22:45:52 -02:00
parent 13f282a289
commit 1ba2766231

View file

@ -285,6 +285,9 @@ def revente(request, tirage_id):
if not created: if not created:
revente.seller = participant revente.seller = participant
revente.date = timezone.now() revente.date = timezone.now()
revente.notif_sent = False
revente.tirage_done = False
revente.shotgun = False
mail_subject = "BdA-Revente : {:s}".format(attribution.spectacle.title) mail_subject = "BdA-Revente : {:s}".format(attribution.spectacle.title)
mail_body = loader.render_to_string('mail-revente-new.txt', { mail_body = loader.render_to_string('mail-revente-new.txt', {
'vendeur': participant.user, 'vendeur': participant.user,
@ -421,18 +424,22 @@ def buy_revente(request, spectacle_id):
reventes = SpectacleRevente.objects.filter( reventes = SpectacleRevente.objects.filter(
attribution__spectacle=spectacle, attribution__spectacle=spectacle,
soldTo__isnull=True) soldTo__isnull=True)
# Si l'utilisateur veut racheter une place qu'il est en train de revendre,
# on supprime la revente en question.
if reventes.filter(seller=participant).exists(): if reventes.filter(seller=participant).exists():
revente = reventes.filter(seller=participant)[0] revente = reventes.filter(seller=participant)[0]
revente.delete() revente.delete()
return HttpResponseRedirect(reverse("bda-shotgun", return HttpResponseRedirect(reverse("bda-shotgun",
args=[tirage.id])) args=[tirage.id]))
reventes_shotgun = reventes.filter(shotgun=True)
if not reventes_shotgun.exists(): reventes_shotgun = list(reventes.filter(shotgun=True).all())
if not reventes_shotgun:
return render(request, "bda-no-revente.html", {}) return render(request, "bda-no-revente.html", {})
if request.POST: if request.POST:
revente = random.choice(reventes_shotgun.all()) revente = random.choice(reventes_shotgun)
revente.soldTo = participant revente.soldTo = participant
revente.save() revente.save()
mail = """Bonjour ! mail = """Bonjour !