From 2aaf9f681ec103a9c1c1f934058670af3a92bdf2 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sat, 23 Jul 2016 22:22:17 +0200 Subject: [PATCH] interface de revente de places --- bda/templates/bda-revente.html | 37 ++++++++++++++++++---------------- bda/views.py | 25 +++++++++++++++-------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/bda/templates/bda-revente.html b/bda/templates/bda-revente.html index c901a7d1..9527a28b 100644 --- a/bda/templates/bda-revente.html +++ b/bda/templates/bda-revente.html @@ -1,26 +1,29 @@ {% extends "base_title.html" %} {% load staticfiles %} -{% block extra_head %} - -{% endblock %} - {% block realcontent %}

Revente de place

-
+{% if no_resell %} +

Places non revendues

+ {% csrf_token %} -{% if form.spectacle.errors %}{% endif %} -

-

-Bonjour,
-
-Je souhaite revendre {{ form.count }} place(s) pour {{ form.spectacle }}.
-Contactez-moi par email si vous êtes intéressé !
-
-{{ user.get_full_name }} ({{ user.email }}) -
-

- +
    + {% for attribution in no_resell %} +
  1. {{attribution.spectacle}}
  2. + {% endfor %} +
+ +
+{%endif%} +

Places en cours de revente

+
+ {% csrf_token %} +
    + {% for attribution in resell %} +
  1. {{attribution.spectacle}}
  2. + {% endfor %} +
+
{% endblock %} diff --git a/bda/views.py b/bda/views.py index fbf75359..ab445052 100644 --- a/bda/views.py +++ b/bda/views.py @@ -6,6 +6,7 @@ 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 @@ -21,10 +22,10 @@ import time from gestioncof.decorators import cof_required, buro_required from bda.models import Spectacle, Participant, ChoixSpectacle, Attribution,\ - Tirage, render_template + Tirage, render_template, SpectacleRevente from bda.algorithm import Algorithm -from bda.forms import BaseBdaFormSet, TokenForm, ResellForm +from bda.forms import BaseBdaFormSet, TokenForm @cof_required @@ -302,13 +303,21 @@ def revente(request, tirage_id): if not participant.paid: return render(request, "bda-notpaid.html", {}) if request.POST: - form = ResellForm(participant, request.POST) - if form.is_valid(): - return do_resell(request, form) - else: - form = ResellForm(participant) + for attr_id in request.POST.getlist('resell'): + 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) + 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) return render(request, "bda-revente.html", - {"form": form, 'tirage': tirage}) + {"participant": participant, 'tirage': tirage, + "resell": resell, "no_resell": no_resell}) @buro_required