forked from DGNum/gestioCOF
change resell and reinit forms
This commit is contained in:
parent
f5b23174de
commit
d9402e1059
3 changed files with 68 additions and 85 deletions
69
bda/views.py
69
bda/views.py
|
@ -26,7 +26,7 @@ from bda.models import Spectacle, Participant, ChoixSpectacle, Attribution,\
|
|||
Tirage, SpectacleRevente
|
||||
from bda.algorithm import Algorithm
|
||||
from bda.forms import BaseBdaFormSet, TokenForm, ResellForm, AnnulForm,\
|
||||
InscriptionReventeForm
|
||||
InscriptionReventeForm, SoldForm
|
||||
|
||||
|
||||
@cof_required
|
||||
|
@ -316,13 +316,18 @@ def revente(request, tirage_id):
|
|||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||
participant, created = Participant.objects.get_or_create(
|
||||
user=request.user, tirage=tirage)
|
||||
|
||||
if not participant.paid:
|
||||
return render(request, "bda-notpaid.html", {})
|
||||
|
||||
resellform = ResellForm(participant, prefix='resell')
|
||||
annulform = AnnulForm(participant, prefix='annul')
|
||||
soldform = SoldForm(participant, prefix='sold')
|
||||
|
||||
if request.method == 'POST':
|
||||
# On met en vente une place
|
||||
if 'resell' in request.POST:
|
||||
resellform = ResellForm(participant, request.POST, prefix='resell')
|
||||
annulform = AnnulForm(participant, prefix='annul')
|
||||
if resellform.is_valid():
|
||||
datatuple = []
|
||||
attributions = resellform.cleaned_data["attributions"]
|
||||
|
@ -354,7 +359,6 @@ def revente(request, tirage_id):
|
|||
# On annule une revente
|
||||
elif 'annul' in request.POST:
|
||||
annulform = AnnulForm(participant, request.POST, prefix='annul')
|
||||
resellform = ResellForm(participant, prefix='resell')
|
||||
if annulform.is_valid():
|
||||
attributions = annulform.cleaned_data["attributions"]
|
||||
for attribution in attributions:
|
||||
|
@ -362,44 +366,31 @@ def revente(request, tirage_id):
|
|||
# On confirme une vente en transférant la place à la personne qui a
|
||||
# gagné le tirage
|
||||
elif 'transfer' in request.POST:
|
||||
resellform = ResellForm(participant, prefix='resell')
|
||||
annulform = AnnulForm(participant, prefix='annul')
|
||||
soldform = SoldForm(participant, request.POST, prefix='sold')
|
||||
if soldform.is_valid():
|
||||
attributions = soldform.cleaned_data['attributions']
|
||||
for attribution in attributions:
|
||||
attribution.participant = attribution.revente.soldTo
|
||||
attribution.save()
|
||||
|
||||
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()
|
||||
# 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:
|
||||
resellform = ResellForm(participant, prefix='resell')
|
||||
annulform = AnnulForm(participant, prefix='annul')
|
||||
revente_id = request.POST['reinit'][0]
|
||||
rev = SpectacleRevente.objects.filter(soldTo__isnull=False,
|
||||
id=revente_id)
|
||||
if rev.exists():
|
||||
revente = rev.get()
|
||||
if revente.attribution.spectacle.date > timezone.now():
|
||||
revente.date = timezone.now() - timedelta(hours=1)
|
||||
revente.soldTo = None
|
||||
revente.notif_sent = False
|
||||
revente.tirage_done = False
|
||||
revente.shotgun = False
|
||||
if revente.answered_mail:
|
||||
revente.answered_mail.clear()
|
||||
revente.save()
|
||||
|
||||
else:
|
||||
resellform = ResellForm(participant, prefix='resell')
|
||||
annulform = AnnulForm(participant, prefix='annul')
|
||||
else:
|
||||
resellform = ResellForm(participant, prefix='resell')
|
||||
annulform = AnnulForm(participant, prefix='annul')
|
||||
soldform = SoldForm(participant, request.POST, prefix='sold')
|
||||
if soldform.is_valid():
|
||||
attributions = soldform.cleaned_data['attributions']
|
||||
for attribution in attributions:
|
||||
if attribution.spectacle.date > timezone.now():
|
||||
revente = attribution.revente
|
||||
revente.date = timezone.now() - timedelta(minutes=65)
|
||||
revente.soldTo = None
|
||||
revente.notif_sent = False
|
||||
revente.tirage_done = False
|
||||
revente.shotgun = False
|
||||
if revente.answered_mail:
|
||||
revente.answered_mail.clear()
|
||||
revente.save()
|
||||
|
||||
overdue = participant.attribution_set.filter(
|
||||
spectacle__date__gte=timezone.now(),
|
||||
|
@ -407,13 +398,9 @@ def revente(request, tirage_id):
|
|||
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)
|
||||
|
||||
return render(request, "bda-revente.html",
|
||||
{'tirage': tirage, 'overdue': overdue, "sold": sold,
|
||||
{'tirage': tirage, 'overdue': overdue, "soldform": soldform,
|
||||
"annulform": annulform, "resellform": resellform})
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue