diff --git a/bda/templates/liste-reventes.html b/bda/templates/liste-reventes.html
new file mode 100644
index 00000000..6ae20388
--- /dev/null
+++ b/bda/templates/liste-reventes.html
@@ -0,0 +1,23 @@
+{% extends "base_title.html" %}
+{% load staticfiles %}
+
+{% block realcontent %}
+
Inscriptions pour BDA-Revente
+
+
+ {% if shotgun %}
+ Places disponibles immédiatement
+
+ {% for spectacle in shotgun %}
+ - {{spectacle}}
+ {% endfor %}
+ {% endif %}
+{% endblock %}
diff --git a/bda/templates/revente-confirm.html b/bda/templates/revente-confirm.html
new file mode 100644
index 00000000..d1a348aa
--- /dev/null
+++ b/bda/templates/revente-confirm.html
@@ -0,0 +1,14 @@
+{% extends "base_title.html" %}
+{% load staticfiles %}
+
+{# TODO: ajouter template du mail ? Changer formulation #}
+{%block realcontent %}
+Vous êtes sur le point de racheter une place pour {{spectacle.title}} à {{selected.attribution.participant.user.get_full_name}} ; confirmez-vous ceci ? Un mail lui sera envoyé pour le/la notifier et vous permettre d'entrer en contact.
+
+
+
+{%endblock%}
diff --git a/bda/views.py b/bda/views.py
index 82c09b55..3c42f94d 100644
--- a/bda/views.py
+++ b/bda/views.py
@@ -4,6 +4,8 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
+import random
+
from django.shortcuts import render, get_object_or_404
from django.contrib.auth.decorators import login_required
from django.db import models
@@ -320,6 +322,50 @@ def revente(request, tirage_id):
"resell": resell, "no_resell": no_resell})
+@login_required
+def list_revente(request, tirage_id):
+ tirage = get_object_or_404(Tirage, id=tirage_id)
+ participant, created = Participant.objects.get_or_create(
+ user=request.user, tirage=tirage)
+ spectacles = tirage.spectacle_set.all()
+ shotgun = []
+ for spectacle in spectacles:
+ spectacle.am_interested = spectacle.revente.filter(
+ pk=participant.id).exists()
+ revente_objects = SpectacleRevente.objects.filter(
+ attribution__spectacle=spectacle)
+ revente_count = 0
+ for revente in revente_objects:
+ if revente.shotgun:
+ revente_count += 1
+ if revente_count:
+ spectacle.revente_count = revente_count
+ shotgun.append(spectacle)
+ return render(request, "liste-reventes.html",
+ {"participant": participant, 'tirage': tirage,
+ "spectacles": spectacles, 'shotgun': shotgun})
+
+
+@login_required
+def buy_revente(request, spectacle_id):
+ spectacle = get_object_or_404(Spectacle, id=spectacle_id)
+ tirage = spectacle.tirage
+ participant, created = Participant.objects.get_or_create(
+ user=request.user, tirage=tirage)
+ reventes = SpectacleRevente.objects.filter(
+ attribution__spectacle=spectacle)
+ if request.POST:
+ revente = SpectacleRevente.objects.get(pk=request.POST['id'])
+ revente.soldTo = participant
+ revente.save()
+
+ if reventes.exists():
+ idx = random.randint(0, reventes.count() - 1)
+ selected = reventes.all()[idx]
+ return render(request, "revente-confirm.html",
+ {"selected": selected, "spectacle": spectacle})
+
+
@buro_required
def spectacle(request, tirage_id, spectacle_id):
tirage = get_object_or_404(Tirage, id=tirage_id)