Misc fixes

This commit is contained in:
Ludovic Stephan 2017-10-26 12:40:11 +02:00
parent 6a6549e0d7
commit 785555c05c
4 changed files with 30 additions and 31 deletions

View file

@ -5,7 +5,6 @@ import random
import hashlib
import time
import json
from datetime import timedelta
from custommail.shortcuts import send_mass_custom_mail, send_custom_mail
from custommail.models import CustomMail
from django.shortcuts import render, get_object_or_404
@ -14,6 +13,7 @@ from django.contrib import messages
from django.db import transaction
from django.core import serializers
from django.db.models import Count, Q, Prefetch
from django.template.defaultfilters import pluralize
from django.forms.models import inlineformset_factory
from django.http import (
HttpResponseBadRequest, HttpResponseRedirect, JsonResponse
@ -376,6 +376,7 @@ def revente_manage(request, tirage_id):
defaults={'seller': participant})
if not created:
revente.reset()
context = {
'vendeur': participant.user,
'show': attribution.spectacle,
@ -414,15 +415,10 @@ def revente_manage(request, tirage_id):
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.confirmed_entry:
revente.confirmed_entry.clear()
revente.save()
# On antidate pour envoyer le mail plus vite
new_date = (timezone.now()
- SpectacleRevente.remorse_time)
revente.reset(new_date=new_date)
overdue = participant.attribution_set.filter(
spectacle__date__gte=timezone.now(),
@ -442,7 +438,6 @@ def revente_tirages(request, tirage_id):
tirage = get_object_or_404(Tirage, id=tirage_id)
participant, _ = Participant.objects.get_or_create(
user=request.user, tirage=tirage)
unsub = 0
subform = ReventeTirageForm(participant, prefix="subscribe")
annulform = ReventeTirageAnnulForm(participant, prefix="annul")
@ -451,33 +446,29 @@ def revente_tirages(request, tirage_id):
subform = ReventeTirageForm(participant, request.POST,
prefix="subscribe")
if subform.is_valid():
sub = 0
reventes = subform.cleaned_data['reventes']
count = reventes.count()
for revente in reventes:
revente.confirmed_entry.add(participant)
sub += 1
if sub > 0:
plural = "s" if sub > 1 else ""
if count > 0:
messages.success(
request,
"Tu as bien été inscrit à {} revente{}"
.format(sub, plural)
.format(count, pluralize(count))
)
elif "annul" in request.POST:
annulform = ReventeTirageAnnulForm(participant, request.POST,
prefix="annul")
if annulform.is_valid():
unsub = 0
reventes = annulform.cleaned_data['reventes']
count = reventes.count()
for revente in reventes:
revente.confirmed_entry.remove(participant)
unsub += 1
if unsub > 0:
plural = "s" if unsub > 1 else ""
if count > 0:
messages.success(
request,
"Tu as bien été désinscrit de {} revente{}"
.format(unsub, plural)
.format(count, pluralize(count))
)
return render(request, "bda/revente/tirages.html",