revente de revente + confirmation de transfert de places

This commit is contained in:
Ludovic Stephan 2016-09-05 02:29:49 +02:00
parent 0b40ebb6f7
commit 3bc9880db1
4 changed files with 80 additions and 13 deletions

View file

@ -9,7 +9,7 @@ import random
from django.shortcuts import render, get_object_or_404
from django.contrib.auth.decorators import login_required
from django.db import models
from django.db.models import Count
from django.db.models import Count, Q
from django.core import serializers
from django.forms.models import inlineformset_factory
from django.http import HttpResponseBadRequest
@ -293,8 +293,14 @@ def revente(request, tirage_id):
if resellform.is_valid():
attributions = resellform.cleaned_data["attributions"]
for attribution in attributions:
revente = SpectacleRevente(attribution=attribution)
revente, created = SpectacleRevente.objects.get_or_create(
attribution=attribution,
defaults={'seller': participant})
if not created:
revente.seller = participant
revente.date = timezone.now()
revente.save()
elif 'annul' in request.POST:
annulform = AnnulForm(participant, request.POST, prefix='annul')
resellform = ResellForm(participant, prefix='resell')
@ -302,19 +308,54 @@ def revente(request, tirage_id):
attributions = annulform.cleaned_data["attributions"]
for attribution in attributions:
attribution.revente.delete()
elif 'transfer' in request.POST:
resellform = ResellForm(participant, prefix='resell')
annulform = AnnulForm(participant, prefix='annul')
revente_id = request.POST['transfer'][0]
rev = SpectacleRevente.objects.filter(soldTo__isnull=False,
id=revente_id)
if rev.exists():
revente = rev.get()
attrib = revente.attribution
attrib.participant = revente.soldTo
attrib.save()
elif 'reinit' in request.POST:
resellform = ResellForm(participant, prefix='resell')
annulform = AnnulForm(participant, prefix='annul')
revente_id = request.POST['transfer'][0]
rev = SpectacleRevente.objects.filter(soldTo__isnull=False,
id=revente_id)
if rev.exists():
revente = rev.get()
revente.date = timezone.now() - timedelta(hours=1)
revente.soldTo = None
revente.interested = None
# schedule job
else:
resellform = ResellForm(participant, prefix='resell')
annulform = AnnulForm(participant, prefix='annul')
else:
resellform = ResellForm(participant, prefix='resell')
annulform = AnnulForm(participant, prefix='annul')
overdue = participant.attribution_set.filter(
spectacle__date__gte=timezone.now(),
revente__isnull=False,
revente__date__lte=timezone.now()-timedelta(hours=1))
revente__seller=participant,
revente__date__lte=timezone.now()-timedelta(hours=1)).filter(
Q(revente__soldTo__isnull=True) | Q(revente__soldTo=participant))
sold = participant.attribution_set.filter(
spectacle__date__gte=timezone.now(),
revente__isnull=False,
revente__soldTo__isnull=False).exclude(
revente__soldTo=participant)
return render(request, "bda-revente.html",
{'tirage': tirage, 'overdue': overdue,
{'tirage': tirage, 'overdue': overdue, "sold": sold,
"annulform": annulform, "resellform": resellform})
@ -395,10 +436,10 @@ Contacte-moi si tu es toujours intéressé·e !
request.user.get_full_name(), request.user.email)
send_mail("BdA-Revente : %s" % spectacle.title, mail,
request.user.email,
[revente.attribution.participant.user.email],
[revente.seller.user.email],
fail_silently=False)
return render(request, "bda-success.html",
{"seller": revente.attribution.participant.user,
{"seller": revente.seller.user,
"spectacle": spectacle})
return render(request, "revente-confirm.html",