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
|
||||
class SpectacleRevente(models.Model):
|
||||
attribution = models.OneToOneField(Attribution)
|
||||
attribution = models.OneToOneField(Attribution,
|
||||
related_name="revente")
|
||||
date = models.DateTimeField("Date de mise en vente",
|
||||
default=timezone.now)
|
||||
sold = models.BooleanField("Vendue", default=False)
|
||||
|
@ -194,13 +195,17 @@ class SpectacleRevente(models.Model):
|
|||
remaining_time = (self.attribution.spectacle.date - self.date)
|
||||
delay = max(datetime.timedelta(hours=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)
|
||||
|
||||
def get_shotgun(self):
|
||||
return timezone.now() > self.expiration_time
|
||||
shotgun = property(get_shotgun)
|
||||
|
||||
def get_cancellable(self):
|
||||
return timezone.now() < self.date + datetime.timedelta(hours=1)
|
||||
cancellable = property(get_cancellable)
|
||||
|
||||
def __str__(self):
|
||||
return "%s -- %s" % (self.attribution.participant.user,
|
||||
self.attribution.spectacle.title)
|
||||
|
|
|
@ -16,14 +16,18 @@
|
|||
<input type="submit" value="Revendre les places sélectionnées">
|
||||
</form>
|
||||
{%endif%}
|
||||
{% if resell %}
|
||||
<h2>Places en cours de revente</h2>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
<ol>
|
||||
{% 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 %}
|
||||
</ol>
|
||||
<input type="submit" value="Annuler les reventes sélectionnées">
|
||||
</form>
|
||||
{% endif %}
|
||||
{% 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.contrib.auth.decorators import login_required
|
||||
from django.contrib import messages
|
||||
from django.db import models
|
||||
from django.db.models import Count
|
||||
from django.core import serializers
|
||||
|
@ -307,14 +306,15 @@ def revente(request, tirage_id):
|
|||
attribution = Attribution.objects.get(id=int(attr_id))
|
||||
revente = SpectacleRevente(attribution=attribution)
|
||||
revente.save()
|
||||
for attr_id in request.POST.getlist('annul'):
|
||||
revente = SpectacleRevente.objects.get(attribution__pk=attr_id)
|
||||
if 'annul' in request.POST:
|
||||
revente = SpectacleRevente.objects\
|
||||
.get(attribution__pk=request.POST['annul'])
|
||||
revente.delete()
|
||||
|
||||
attributions = participant.attribution_set.filter(
|
||||
spectacle__date__gte=timezone.now)
|
||||
resell = attributions.filter(spectaclerevente__isnull=False)
|
||||
no_resell = attributions.filter(spectaclerevente__isnull=True)
|
||||
resell = attributions.filter(revente__isnull=False)
|
||||
no_resell = attributions.filter(revente__isnull=True)
|
||||
return render(request, "bda-revente.html",
|
||||
{"participant": participant, 'tirage': tirage,
|
||||
"resell": resell, "no_resell": no_resell})
|
||||
|
|
Loading…
Reference in a new issue