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

@ -43,11 +43,13 @@ class TokenForm(forms.Form):
class AttributionModelMultipleChoiceField(forms.ModelMultipleChoiceField): class AttributionModelMultipleChoiceField(forms.ModelMultipleChoiceField):
def label_from_instance(self, obj): def label_from_instance(self, obj):
return "%s" % str(obj.spectacle) return str(obj.spectacle)
class ReventeModelMultipleChoiceField(forms.ModelMultipleChoiceField): class ReventeModelMultipleChoiceField(forms.ModelMultipleChoiceField):
def label_from_instance(self, obj): def label_from_instance(self, obj):
return "%s" % str(obj.attribution.spectacle) return str(obj.attribution.spectacle)
class ResellForm(forms.Form): class ResellForm(forms.Form):
attributions = AttributionModelMultipleChoiceField( attributions = AttributionModelMultipleChoiceField(
@ -66,6 +68,7 @@ class ResellForm(forms.Form):
'participant__user') 'participant__user')
) )
class AnnulForm(forms.Form): class AnnulForm(forms.Form):
attributions = AttributionModelMultipleChoiceField( attributions = AttributionModelMultipleChoiceField(
label='', label='',
@ -85,6 +88,7 @@ class AnnulForm(forms.Form):
'participant__user') 'participant__user')
) )
class InscriptionReventeForm(forms.Form): class InscriptionReventeForm(forms.Form):
spectacles = forms.ModelMultipleChoiceField( spectacles = forms.ModelMultipleChoiceField(
queryset=Spectacle.objects.none(), queryset=Spectacle.objects.none(),
@ -99,6 +103,7 @@ class InscriptionReventeForm(forms.Form):
.filter(date__gte=timezone.now()) .filter(date__gte=timezone.now())
) )
class ReventeTirageAnnulForm(forms.Form): class ReventeTirageAnnulForm(forms.Form):
reventes = ReventeModelMultipleChoiceField( reventes = ReventeModelMultipleChoiceField(
label='', label='',
@ -134,6 +139,7 @@ class ReventeTirageForm(forms.Form):
.select_related('attribution__spectacle') .select_related('attribution__spectacle')
) )
class SoldForm(forms.Form): class SoldForm(forms.Form):
attributions = AttributionModelMultipleChoiceField( attributions = AttributionModelMultipleChoiceField(
label='', label='',

View file

@ -11,11 +11,12 @@ class Migration(migrations.Migration):
] ]
operations = [ operations = [
migrations.RemoveField( migrations.RenameField(
model_name='spectaclerevente', model_name='spectaclerevente',
name='answered_mail', old_name='answered_mail',
new_name='confirmed_entry',
), ),
migrations.AddField( migrations.AlterField(
model_name='spectaclerevente', model_name='spectaclerevente',
name='confirmed_entry', name='confirmed_entry',
field=models.ManyToManyField(blank=True, related_name='entered', to='bda.Participant'), field=models.ManyToManyField(blank=True, related_name='entered', to='bda.Participant'),

View file

@ -168,6 +168,7 @@ class Participant(models.Model):
def __str__(self): def __str__(self):
return "%s - %s" % (self.user, self.tirage.title) return "%s - %s" % (self.user, self.tirage.title)
DOUBLE_CHOICES = ( DOUBLE_CHOICES = (
("1", "1 place"), ("1", "1 place"),
("autoquit", "2 places si possible, 1 sinon"), ("autoquit", "2 places si possible, 1 sinon"),
@ -292,15 +293,16 @@ class SpectacleRevente(models.Model):
class Meta: class Meta:
verbose_name = "Revente" verbose_name = "Revente"
def reset(self): def reset(self, new_date=timezone.now()):
"""Réinitialise la revente pour permettre une remise sur le marché""" """Réinitialise la revente pour permettre une remise sur le marché"""
self.seller = self.attribution.participant self.seller = self.attribution.participant
self.date = timezone.now() self.date = new_date
self.confirmed_entry.clear() self.confirmed_entry.clear()
self.soldTo = None self.soldTo = None
self.notif_sent = False self.notif_sent = False
self.tirage_done = False self.tirage_done = False
self.shotgun = False self.shotgun = False
self.save()
def send_notif(self): def send_notif(self):
""" """
@ -396,11 +398,10 @@ class SpectacleRevente(models.Model):
)) ))
send_mass_custom_mail(datatuple) send_mass_custom_mail(datatuple)
return winner
# Si personne ne veut de la place, elle part au shotgun # Si personne ne veut de la place, elle part au shotgun
else: else:
winner = None
self.shotgun = True self.shotgun = True
return None
self.tirage_done = True self.tirage_done = True
self.save() self.save()
return winner

View file

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