forked from DGNum/gestioCOF
Merge branch 'master' into Kerl/use_django_custommail
This commit is contained in:
commit
b9c2efaf0e
9 changed files with 112 additions and 72 deletions
98
bda/views.py
98
bda/views.py
|
@ -271,6 +271,7 @@ def revente(request, tirage_id):
|
|||
if not participant.paid:
|
||||
return render(request, "bda-notpaid.html", {})
|
||||
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')
|
||||
|
@ -279,12 +280,17 @@ def revente(request, tirage_id):
|
|||
attributions = resellform.cleaned_data["attributions"]
|
||||
with transaction.atomic():
|
||||
for attribution in attributions:
|
||||
revente, created = SpectacleRevente.objects.get_or_create(
|
||||
attribution=attribution,
|
||||
defaults={'seller': participant})
|
||||
revente, created = \
|
||||
SpectacleRevente.objects.get_or_create(
|
||||
attribution=attribution,
|
||||
defaults={'seller': participant})
|
||||
if not created:
|
||||
revente.seller = participant
|
||||
revente.date = timezone.now()
|
||||
revente.soldTo = None
|
||||
revente.notif_sent = False
|
||||
revente.tirage_done = False
|
||||
revente.shotgun = False
|
||||
context = {
|
||||
'vendeur': participant.user,
|
||||
'show': attribution.spectacle,
|
||||
|
@ -297,7 +303,7 @@ def revente(request, tirage_id):
|
|||
mails_data,
|
||||
from_email=settings.MAIL_DATA['revente']['FROM']
|
||||
)
|
||||
|
||||
# On annule une revente
|
||||
elif 'annul' in request.POST:
|
||||
annulform = AnnulForm(participant, request.POST, prefix='annul')
|
||||
resellform = ResellForm(participant, prefix='resell')
|
||||
|
@ -305,7 +311,8 @@ def revente(request, tirage_id):
|
|||
attributions = annulform.cleaned_data["attributions"]
|
||||
for attribution in attributions:
|
||||
attribution.revente.delete()
|
||||
|
||||
# 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')
|
||||
|
@ -318,7 +325,9 @@ def revente(request, tirage_id):
|
|||
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')
|
||||
|
@ -332,6 +341,7 @@ def revente(request, tirage_id):
|
|||
revente.soldTo = None
|
||||
revente.notif_sent = False
|
||||
revente.tirage_done = False
|
||||
revente.shotgun = False
|
||||
if revente.answered_mail:
|
||||
revente.answered_mail.clear()
|
||||
revente.save()
|
||||
|
@ -352,8 +362,7 @@ def revente(request, tirage_id):
|
|||
sold = participant.attribution_set.filter(
|
||||
spectacle__date__gte=timezone.now(),
|
||||
revente__isnull=False,
|
||||
revente__soldTo__isnull=False).exclude(
|
||||
revente__soldTo=participant)
|
||||
revente__soldTo__isnull=False)
|
||||
|
||||
return render(request, "bda-revente.html",
|
||||
{'tirage': tirage, 'overdue': overdue, "sold": sold,
|
||||
|
@ -365,13 +374,14 @@ def revente_interested(request, revente_id):
|
|||
revente = get_object_or_404(SpectacleRevente, id=revente_id)
|
||||
participant, created = Participant.objects.get_or_create(
|
||||
user=request.user, tirage=revente.attribution.spectacle.tirage)
|
||||
if timezone.now() < revente.date + timedelta(hours=1) or revente.shotgun:
|
||||
return render(request, "bda-wrongtime.html", {})
|
||||
if (timezone.now() < revente.date + timedelta(hours=1)) or revente.shotgun:
|
||||
return render(request, "bda-wrongtime.html",
|
||||
{"revente": revente})
|
||||
|
||||
revente.answered_mail.add(participant)
|
||||
return render(request, "bda-interested.html",
|
||||
{"spectacle": revente.attribution.spectacle,
|
||||
"date": revente.expiration_time})
|
||||
"date": revente.date_tirage})
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -379,23 +389,9 @@ def list_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)
|
||||
spectacles = tirage.spectacle_set.filter(
|
||||
date__gte=timezone.now())
|
||||
shotgun = []
|
||||
deja_revente = False
|
||||
success = False
|
||||
for spectacle in spectacles:
|
||||
revente_objects = SpectacleRevente.objects.filter(
|
||||
attribution__spectacle=spectacle,
|
||||
soldTo__isnull=True)
|
||||
revente_count = 0
|
||||
for revente in revente_objects:
|
||||
if revente.shotgun:
|
||||
revente_count += 1
|
||||
if revente_count:
|
||||
spectacle.revente_count = revente_count
|
||||
shotgun.append(spectacle)
|
||||
|
||||
inscrit_revente = False
|
||||
if request.method == 'POST':
|
||||
form = InscriptionReventeForm(tirage, request.POST)
|
||||
if form.is_valid():
|
||||
|
@ -405,15 +401,24 @@ def list_revente(request, tirage_id):
|
|||
for spectacle in choices:
|
||||
qset = SpectacleRevente.objects.filter(
|
||||
attribution__spectacle=spectacle)
|
||||
if qset.exists():
|
||||
# On l'inscrit à l'un des tirages au sort
|
||||
for revente in qset.all():
|
||||
if revente.shotgun and not revente.soldTo:
|
||||
deja_revente = True
|
||||
else:
|
||||
revente.answered_mail.add(participant)
|
||||
revente.save()
|
||||
break
|
||||
if qset.filter(shotgun=True, soldTo__isnull=True).exists():
|
||||
# Une place est disponible au shotgun, on suggère à
|
||||
# l'utilisateur d'aller la récupérer
|
||||
deja_revente = True
|
||||
else:
|
||||
# La place n'est pas disponible au shotgun, si des reventes
|
||||
# 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
|
||||
success = True
|
||||
else:
|
||||
form = InscriptionReventeForm(
|
||||
|
@ -421,8 +426,9 @@ def list_revente(request, tirage_id):
|
|||
initial={'spectacles': participant.choicesrevente.all()})
|
||||
|
||||
return render(request, "liste-reventes.html",
|
||||
{"form": form, 'shotgun': shotgun,
|
||||
"deja_revente": deja_revente, "success": success})
|
||||
{"form": form,
|
||||
"deja_revente": deja_revente, "success": success,
|
||||
"inscrit_revente": inscrit_revente})
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -434,15 +440,16 @@ def buy_revente(request, spectacle_id):
|
|||
reventes = SpectacleRevente.objects.filter(
|
||||
attribution__spectacle=spectacle,
|
||||
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():
|
||||
revente = reventes.filter(seller=participant)[0]
|
||||
revente.delete()
|
||||
return HttpResponseRedirect(reverse("bda-shotgun",
|
||||
args=[tirage.id]))
|
||||
reventes_shotgun = []
|
||||
for revente in reventes.all():
|
||||
if revente.shotgun:
|
||||
reventes_shotgun.append(revente)
|
||||
|
||||
reventes_shotgun = list(reventes.filter(shotgun=True).all())
|
||||
|
||||
if not reventes_shotgun:
|
||||
return render(request, "bda-no-revente.html", {})
|
||||
|
@ -478,14 +485,11 @@ def revente_shotgun(request, tirage_id):
|
|||
date__gte=timezone.now())
|
||||
shotgun = []
|
||||
for spectacle in spectacles:
|
||||
revente_objects = SpectacleRevente.objects.filter(
|
||||
reventes = SpectacleRevente.objects.filter(
|
||||
attribution__spectacle=spectacle,
|
||||
shotgun=True,
|
||||
soldTo__isnull=True)
|
||||
revente_count = 0
|
||||
for revente in revente_objects:
|
||||
if revente.shotgun:
|
||||
revente_count += 1
|
||||
if revente_count:
|
||||
if reventes.exists():
|
||||
shotgun.append(spectacle)
|
||||
|
||||
return render(request, "bda-shotgun.html",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue