forked from DGNum/gestioCOF
revente de revente + confirmation de transfert de places
This commit is contained in:
parent
0b40ebb6f7
commit
3bc9880db1
|
@ -52,8 +52,8 @@ class ResellForm(forms.Form):
|
||||||
def __init__(self, participant, *args, **kwargs):
|
def __init__(self, participant, *args, **kwargs):
|
||||||
super(ResellForm, self).__init__(*args, **kwargs)
|
super(ResellForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['attributions'].queryset = participant.attribution_set\
|
self.fields['attributions'].queryset = participant.attribution_set\
|
||||||
.filter(spectacle__date__gte=timezone.now(),
|
.filter(spectacle__date__gte=timezone.now())\
|
||||||
revente__isnull=True)
|
.exclude(revente__seller=participant)
|
||||||
|
|
||||||
|
|
||||||
class AnnulForm(forms.Form):
|
class AnnulForm(forms.Form):
|
||||||
|
@ -67,7 +67,8 @@ class AnnulForm(forms.Form):
|
||||||
self.fields['attributions'].queryset = participant.attribution_set\
|
self.fields['attributions'].queryset = participant.attribution_set\
|
||||||
.filter(spectacle__date__gte=timezone.now(),
|
.filter(spectacle__date__gte=timezone.now(),
|
||||||
revente__isnull=False,
|
revente__isnull=False,
|
||||||
revente__date__gte=timezone.now()-timedelta(hours=1))
|
revente__date__gte=timezone.now()-timedelta(hours=1),
|
||||||
|
revente__seller=participant)
|
||||||
|
|
||||||
|
|
||||||
class InscriptionReventeForm(forms.Form):
|
class InscriptionReventeForm(forms.Form):
|
||||||
|
|
|
@ -221,6 +221,8 @@ class SpectacleRevente(models.Model):
|
||||||
interested = models.ManyToManyField(Participant,
|
interested = models.ManyToManyField(Participant,
|
||||||
related_name="wanted",
|
related_name="wanted",
|
||||||
blank=True)
|
blank=True)
|
||||||
|
seller = models.ForeignKey(Participant,
|
||||||
|
related_name="original_shows")
|
||||||
soldTo = models.ForeignKey(Participant, blank=True, null=True)
|
soldTo = models.ForeignKey(Participant, blank=True, null=True)
|
||||||
|
|
||||||
def get_expiration_time(self):
|
def get_expiration_time(self):
|
||||||
|
@ -235,7 +237,7 @@ class SpectacleRevente(models.Model):
|
||||||
shotgun = property(get_shotgun)
|
shotgun = property(get_shotgun)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s -- %s" % (self.attribution.participant.user,
|
return "%s -- %s" % (self.seller,
|
||||||
self.attribution.spectacle.title)
|
self.attribution.spectacle.title)
|
||||||
|
|
||||||
def send_notif(self):
|
def send_notif(self):
|
||||||
|
@ -261,7 +263,7 @@ class SpectacleRevente(models.Model):
|
||||||
def tirage(self):
|
def tirage(self):
|
||||||
inscrits = self.interested
|
inscrits = self.interested
|
||||||
spectacle = self.attribution.spectacle
|
spectacle = self.attribution.spectacle
|
||||||
user = self.attribution.participant.user
|
seller = self.seller
|
||||||
if inscrits.exists():
|
if inscrits.exists():
|
||||||
idx = random.randint(0, inscrits.count() - 1)
|
idx = random.randint(0, inscrits.count() - 1)
|
||||||
winner = inscrits.all()[idx]
|
winner = inscrits.all()[idx]
|
||||||
|
@ -273,7 +275,7 @@ Tu peux contacter le vendeur à l'adresse %s.
|
||||||
|
|
||||||
Chaleureusement,
|
Chaleureusement,
|
||||||
Le BdA""" % (spectacle.title, spectacle.date_no_seconds(),
|
Le BdA""" % (spectacle.title, spectacle.date_no_seconds(),
|
||||||
spectacle.location, spectacle.price, user.email)
|
spectacle.location, spectacle.price, seller.email)
|
||||||
|
|
||||||
mail.send_mail("BdA-Revente : %s" % spectacle.title,
|
mail.send_mail("BdA-Revente : %s" % spectacle.title,
|
||||||
mail_buyer, "bda@ens.fr", [winner.user.email],
|
mail_buyer, "bda@ens.fr", [winner.user.email],
|
||||||
|
@ -286,5 +288,5 @@ Chaleureusement,
|
||||||
Le BdA""" % (spectacle.title, winner.user.get_full_name(), winner.user.email)
|
Le BdA""" % (spectacle.title, winner.user.get_full_name(), winner.user.email)
|
||||||
|
|
||||||
mail.send_mail("BdA-Revente : %s" % spectacle.title,
|
mail.send_mail("BdA-Revente : %s" % spectacle.title,
|
||||||
mail_seller, "bda@ens.fr", [user.email],
|
mail_seller, "bda@ens.fr", [seller.email],
|
||||||
fail_silently=False)
|
fail_silently=False)
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<br>
|
<br>
|
||||||
|
{% if annulform.attributions or overdue %}
|
||||||
<h3>Places en cours de revente</h3>
|
<h3>Places en cours de revente</h3>
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
@ -45,6 +46,28 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% if annulform.attributions %}
|
||||||
<input type="submit" class="btn btn-primary" name="annul" value="Annuler les reventes sélectionnées">
|
<input type="submit" class="btn btn-primary" name="annul" value="Annuler les reventes sélectionnées">
|
||||||
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
<br>
|
||||||
|
{% if sold %}
|
||||||
|
<h3>Places revendues</h3>
|
||||||
|
<table class="table">
|
||||||
|
{% for attrib in sold %}
|
||||||
|
<tr>
|
||||||
|
<form action="" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<td>{{attrib.spectacle}}</td>
|
||||||
|
<td>{{attrib.revente.soldTo.user.get_full_name}}</td>
|
||||||
|
<td><button type="submit" class="btn btn-primary" name="transfer"
|
||||||
|
value={{attrib.revente.id}}>Transférer</button></td>
|
||||||
|
<td><button type="submit" class="btn btn-primary" name="reinit"
|
||||||
|
value={{attrib.revente.id}}>Réinitialiser</button></td>
|
||||||
|
</form>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
53
bda/views.py
53
bda/views.py
|
@ -9,7 +9,7 @@ import random
|
||||||
from django.shortcuts import render, get_object_or_404
|
from django.shortcuts import render, get_object_or_404
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Count
|
from django.db.models import Count, Q
|
||||||
from django.core import serializers
|
from django.core import serializers
|
||||||
from django.forms.models import inlineformset_factory
|
from django.forms.models import inlineformset_factory
|
||||||
from django.http import HttpResponseBadRequest
|
from django.http import HttpResponseBadRequest
|
||||||
|
@ -293,8 +293,14 @@ def revente(request, tirage_id):
|
||||||
if resellform.is_valid():
|
if resellform.is_valid():
|
||||||
attributions = resellform.cleaned_data["attributions"]
|
attributions = resellform.cleaned_data["attributions"]
|
||||||
for attribution in attributions:
|
for attribution in attributions:
|
||||||
revente = SpectacleRevente(attribution=attribution)
|
revente, created = SpectacleRevente.objects.get_or_create(
|
||||||
|
attribution=attribution,
|
||||||
|
defaults={'seller': participant})
|
||||||
|
if not created:
|
||||||
|
revente.seller = participant
|
||||||
|
revente.date = timezone.now()
|
||||||
revente.save()
|
revente.save()
|
||||||
|
|
||||||
elif 'annul' in request.POST:
|
elif 'annul' in request.POST:
|
||||||
annulform = AnnulForm(participant, request.POST, prefix='annul')
|
annulform = AnnulForm(participant, request.POST, prefix='annul')
|
||||||
resellform = ResellForm(participant, prefix='resell')
|
resellform = ResellForm(participant, prefix='resell')
|
||||||
|
@ -302,19 +308,54 @@ def revente(request, tirage_id):
|
||||||
attributions = annulform.cleaned_data["attributions"]
|
attributions = annulform.cleaned_data["attributions"]
|
||||||
for attribution in attributions:
|
for attribution in attributions:
|
||||||
attribution.revente.delete()
|
attribution.revente.delete()
|
||||||
|
|
||||||
|
elif 'transfer' in request.POST:
|
||||||
|
resellform = ResellForm(participant, prefix='resell')
|
||||||
|
annulform = AnnulForm(participant, prefix='annul')
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
elif 'reinit' in request.POST:
|
||||||
|
resellform = ResellForm(participant, prefix='resell')
|
||||||
|
annulform = AnnulForm(participant, prefix='annul')
|
||||||
|
revente_id = request.POST['transfer'][0]
|
||||||
|
rev = SpectacleRevente.objects.filter(soldTo__isnull=False,
|
||||||
|
id=revente_id)
|
||||||
|
if rev.exists():
|
||||||
|
revente = rev.get()
|
||||||
|
revente.date = timezone.now() - timedelta(hours=1)
|
||||||
|
revente.soldTo = None
|
||||||
|
revente.interested = None
|
||||||
|
# schedule job
|
||||||
|
|
||||||
else:
|
else:
|
||||||
resellform = ResellForm(participant, prefix='resell')
|
resellform = ResellForm(participant, prefix='resell')
|
||||||
annulform = AnnulForm(participant, prefix='annul')
|
annulform = AnnulForm(participant, prefix='annul')
|
||||||
else:
|
else:
|
||||||
resellform = ResellForm(participant, prefix='resell')
|
resellform = ResellForm(participant, prefix='resell')
|
||||||
annulform = AnnulForm(participant, prefix='annul')
|
annulform = AnnulForm(participant, prefix='annul')
|
||||||
|
|
||||||
overdue = participant.attribution_set.filter(
|
overdue = participant.attribution_set.filter(
|
||||||
spectacle__date__gte=timezone.now(),
|
spectacle__date__gte=timezone.now(),
|
||||||
revente__isnull=False,
|
revente__isnull=False,
|
||||||
revente__date__lte=timezone.now()-timedelta(hours=1))
|
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).exclude(
|
||||||
|
revente__soldTo=participant)
|
||||||
|
|
||||||
return render(request, "bda-revente.html",
|
return render(request, "bda-revente.html",
|
||||||
{'tirage': tirage, 'overdue': overdue,
|
{'tirage': tirage, 'overdue': overdue, "sold": sold,
|
||||||
"annulform": annulform, "resellform": resellform})
|
"annulform": annulform, "resellform": resellform})
|
||||||
|
|
||||||
|
|
||||||
|
@ -395,10 +436,10 @@ Contacte-moi si tu es toujours intéressé·e !
|
||||||
request.user.get_full_name(), request.user.email)
|
request.user.get_full_name(), request.user.email)
|
||||||
send_mail("BdA-Revente : %s" % spectacle.title, mail,
|
send_mail("BdA-Revente : %s" % spectacle.title, mail,
|
||||||
request.user.email,
|
request.user.email,
|
||||||
[revente.attribution.participant.user.email],
|
[revente.seller.user.email],
|
||||||
fail_silently=False)
|
fail_silently=False)
|
||||||
return render(request, "bda-success.html",
|
return render(request, "bda-success.html",
|
||||||
{"seller": revente.attribution.participant.user,
|
{"seller": revente.seller.user,
|
||||||
"spectacle": spectacle})
|
"spectacle": spectacle})
|
||||||
|
|
||||||
return render(request, "revente-confirm.html",
|
return render(request, "revente-confirm.html",
|
||||||
|
|
Loading…
Reference in a new issue