diff --git a/bda/models.py b/bda/models.py index b0dd8aeb..1e80b248 100644 --- a/bda/models.py +++ b/bda/models.py @@ -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) diff --git a/bda/templates/bda-revente.html b/bda/templates/bda-revente.html index 9527a28b..16fbc0e2 100644 --- a/bda/templates/bda-revente.html +++ b/bda/templates/bda-revente.html @@ -16,14 +16,18 @@ {%endif%} +{% if resell %}

Places en cours de revente

{% csrf_token %}
    {% for attribution in resell %} -
  1. {{attribution.spectacle}}
  2. + + {% csrf_token %} + +
  3. {{attribution.spectacle}} {% if attribution.revente.cancellable %}{%endif%}
  4. {% endfor %}
-
+{% endif %} {% endblock %} diff --git a/bda/views.py b/bda/views.py index ab445052..82c09b55 100644 --- a/bda/views.py +++ b/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})