achat des reventes au shotgun

This commit is contained in:
Ludovic Stephan 2016-07-25 02:52:49 +02:00
parent 7f87bfe8e2
commit 78096bd6d0
3 changed files with 83 additions and 0 deletions

View file

@ -0,0 +1,23 @@
{% extends "base_title.html" %}
{% load staticfiles %}
{% block realcontent %}
<h2>Inscriptions pour BDA-Revente</h2>
<form action="" method="post">
{% csrf_token %}
<ul>
{% for spectacle in spectacles %}
<li>{{spectacle}} <input type="checkbox" name="spect_id" value="{{spectacle.id}}" {% if spectacle.am_interested %}checked{%endif%}></li>
{%endfor%}
</ul>
<input type="submit" value="S'inscrire pour les places sélectionnées">
</form>
{% if shotgun %}
<h2>Places disponibles immédiatement</h2>
<ul>
{% for spectacle in shotgun %}
<li><a href="{% url "bda-buy-revente" spectacle.id %}">{{spectacle}}</a></li>
{% endfor %}
{% endif %}
{% endblock %}

View file

@ -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.
<form action="" method="post">
{% csrf_token %}
<input type="hidden" name="id" value="{{selected.id}}">
<input type="submit" value="Confirmer">
</form>
{%endblock%}

View file

@ -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)