forked from DGNum/gestioCOF
annulations reventes
This commit is contained in:
parent
2aaf9f681e
commit
8f7b036fbc
3 changed files with 18 additions and 9 deletions
|
@ -185,7 +185,8 @@ class Attribution(models.Model):
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class SpectacleRevente(models.Model):
|
class SpectacleRevente(models.Model):
|
||||||
attribution = models.OneToOneField(Attribution)
|
attribution = models.OneToOneField(Attribution,
|
||||||
|
related_name="revente")
|
||||||
date = models.DateTimeField("Date de mise en vente",
|
date = models.DateTimeField("Date de mise en vente",
|
||||||
default=timezone.now)
|
default=timezone.now)
|
||||||
sold = models.BooleanField("Vendue", default=False)
|
sold = models.BooleanField("Vendue", default=False)
|
||||||
|
@ -194,13 +195,17 @@ class SpectacleRevente(models.Model):
|
||||||
remaining_time = (self.attribution.spectacle.date - self.date)
|
remaining_time = (self.attribution.spectacle.date - self.date)
|
||||||
delay = max(datetime.timedelta(hours=2),
|
delay = max(datetime.timedelta(hours=2),
|
||||||
min(remaining_time//2, datetime.timedelta(days=2)))
|
min(remaining_time//2, datetime.timedelta(days=2)))
|
||||||
return self.date + delay
|
return self.date + delay + datetime.timedelta(hours=1)
|
||||||
expiration_time = property(get_expiration_time)
|
expiration_time = property(get_expiration_time)
|
||||||
|
|
||||||
def get_shotgun(self):
|
def get_shotgun(self):
|
||||||
return timezone.now() > self.expiration_time
|
return timezone.now() > self.expiration_time
|
||||||
shotgun = property(get_shotgun)
|
shotgun = property(get_shotgun)
|
||||||
|
|
||||||
|
def get_cancellable(self):
|
||||||
|
return timezone.now() < self.date + datetime.timedelta(hours=1)
|
||||||
|
cancellable = property(get_cancellable)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s -- %s" % (self.attribution.participant.user,
|
return "%s -- %s" % (self.attribution.participant.user,
|
||||||
self.attribution.spectacle.title)
|
self.attribution.spectacle.title)
|
||||||
|
|
|
@ -16,14 +16,18 @@
|
||||||
<input type="submit" value="Revendre les places sélectionnées">
|
<input type="submit" value="Revendre les places sélectionnées">
|
||||||
</form>
|
</form>
|
||||||
{%endif%}
|
{%endif%}
|
||||||
|
{% if resell %}
|
||||||
<h2>Places en cours de revente</h2>
|
<h2>Places en cours de revente</h2>
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<ol>
|
<ol>
|
||||||
{% for attribution in resell %}
|
{% for attribution in resell %}
|
||||||
<li>{{attribution.spectacle}} <input type="checkbox" name="annul" value="{{attribution.id}}"></li>
|
<form action="" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input type="hidden" name="annul" value="{{attribution.id}}">
|
||||||
|
<li>{{attribution.spectacle}} {% if attribution.revente.cancellable %}<input type="submit" value="Supprimer">{%endif%}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ol>
|
</ol>
|
||||||
<input type="submit" value="Annuler les reventes sélectionnées">
|
|
||||||
</form>
|
</form>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
10
bda/views.py
10
bda/views.py
|
@ -6,7 +6,6 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
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.contrib import messages
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
from django.core import serializers
|
from django.core import serializers
|
||||||
|
@ -307,14 +306,15 @@ def revente(request, tirage_id):
|
||||||
attribution = Attribution.objects.get(id=int(attr_id))
|
attribution = Attribution.objects.get(id=int(attr_id))
|
||||||
revente = SpectacleRevente(attribution=attribution)
|
revente = SpectacleRevente(attribution=attribution)
|
||||||
revente.save()
|
revente.save()
|
||||||
for attr_id in request.POST.getlist('annul'):
|
if 'annul' in request.POST:
|
||||||
revente = SpectacleRevente.objects.get(attribution__pk=attr_id)
|
revente = SpectacleRevente.objects\
|
||||||
|
.get(attribution__pk=request.POST['annul'])
|
||||||
revente.delete()
|
revente.delete()
|
||||||
|
|
||||||
attributions = participant.attribution_set.filter(
|
attributions = participant.attribution_set.filter(
|
||||||
spectacle__date__gte=timezone.now)
|
spectacle__date__gte=timezone.now)
|
||||||
resell = attributions.filter(spectaclerevente__isnull=False)
|
resell = attributions.filter(revente__isnull=False)
|
||||||
no_resell = attributions.filter(spectaclerevente__isnull=True)
|
no_resell = attributions.filter(revente__isnull=True)
|
||||||
return render(request, "bda-revente.html",
|
return render(request, "bda-revente.html",
|
||||||
{"participant": participant, 'tirage': tirage,
|
{"participant": participant, 'tirage': tirage,
|
||||||
"resell": resell, "no_resell": no_resell})
|
"resell": resell, "no_resell": no_resell})
|
||||||
|
|
Loading…
Reference in a new issue