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

View file

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

View file

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

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",