2016-07-15 00:02:56 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-06-10 15:43:37 +02:00
|
|
|
from __future__ import division
|
2016-07-15 00:02:56 +02:00
|
|
|
from __future__ import print_function
|
2016-05-26 22:44:10 +02:00
|
|
|
from __future__ import unicode_literals
|
2016-06-10 15:43:37 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
from django.shortcuts import render, get_object_or_404
|
2012-07-11 17:39:20 +02:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2013-09-05 22:20:52 +02:00
|
|
|
from django.db import models
|
2016-06-22 02:29:20 +02:00
|
|
|
from django.db.models import Count
|
2014-08-19 12:54:22 +02:00
|
|
|
from django.core import serializers
|
2016-06-05 02:18:12 +02:00
|
|
|
from django.forms.models import inlineformset_factory
|
2016-08-26 06:06:45 +02:00
|
|
|
from django.http import HttpResponseBadRequest
|
2014-08-19 12:54:22 +02:00
|
|
|
import hashlib
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
from django.core.mail import send_mail
|
2016-06-05 02:18:12 +02:00
|
|
|
from django.utils import timezone
|
2016-06-06 18:43:56 +02:00
|
|
|
from django.views.generic.list import ListView
|
2013-09-05 22:20:52 +02:00
|
|
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
from gestioncof.decorators import cof_required, buro_required
|
2016-07-09 22:31:56 +02:00
|
|
|
from bda.models import Spectacle, Participant, ChoixSpectacle, Attribution,\
|
2016-07-10 13:19:10 +02:00
|
|
|
Tirage, render_template
|
2013-09-05 22:20:52 +02:00
|
|
|
from bda.algorithm import Algorithm
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-05-27 17:52:02 +02:00
|
|
|
from bda.forms import BaseBdaFormSet, TokenForm, ResellForm
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2013-10-01 15:27:19 +02:00
|
|
|
@cof_required
|
2016-06-05 02:18:12 +02:00
|
|
|
def etat_places(request, tirage_id):
|
|
|
|
tirage = get_object_or_404(Tirage, id=tirage_id)
|
2016-06-06 11:11:33 +02:00
|
|
|
spectacles1 = ChoixSpectacle.objects \
|
|
|
|
.filter(spectacle__tirage=tirage) \
|
|
|
|
.filter(double_choice="1") \
|
|
|
|
.all() \
|
2016-07-09 21:19:37 +02:00
|
|
|
.values('spectacle', 'spectacle__title') \
|
2016-06-06 11:11:33 +02:00
|
|
|
.annotate(total=models.Count('spectacle'))
|
|
|
|
spectacles2 = ChoixSpectacle.objects \
|
|
|
|
.filter(spectacle__tirage=tirage) \
|
|
|
|
.exclude(double_choice="1") \
|
|
|
|
.all() \
|
2016-07-09 21:19:37 +02:00
|
|
|
.values('spectacle', 'spectacle__title') \
|
2016-06-06 11:11:33 +02:00
|
|
|
.annotate(total=models.Count('spectacle'))
|
2016-06-07 22:49:19 +02:00
|
|
|
spectacles = tirage.spectacle_set.all()
|
2013-09-05 22:20:52 +02:00
|
|
|
spectacles_dict = {}
|
|
|
|
total = 0
|
|
|
|
for spectacle in spectacles:
|
|
|
|
spectacle.total = 0
|
2015-01-06 11:01:15 +01:00
|
|
|
spectacle.ratio = 0.0
|
2013-09-05 22:20:52 +02:00
|
|
|
spectacles_dict[spectacle.id] = spectacle
|
|
|
|
for spectacle in spectacles1:
|
|
|
|
spectacles_dict[spectacle["spectacle"]].total += spectacle["total"]
|
2016-06-05 02:18:12 +02:00
|
|
|
spectacles_dict[spectacle["spectacle"]].ratio = \
|
|
|
|
spectacles_dict[spectacle["spectacle"]].total / \
|
2016-06-10 15:43:37 +02:00
|
|
|
spectacles_dict[spectacle["spectacle"]].slots
|
2016-07-09 21:19:37 +02:00
|
|
|
total += spectacle["total"]
|
2013-09-05 22:20:52 +02:00
|
|
|
for spectacle in spectacles2:
|
2016-05-21 23:57:36 +02:00
|
|
|
spectacles_dict[spectacle["spectacle"]].total += 2*spectacle["total"]
|
2016-06-05 02:18:12 +02:00
|
|
|
spectacles_dict[spectacle["spectacle"]].ratio = \
|
|
|
|
spectacles_dict[spectacle["spectacle"]].total / \
|
2016-06-10 15:43:37 +02:00
|
|
|
spectacles_dict[spectacle["spectacle"]].slots
|
2016-07-09 21:19:37 +02:00
|
|
|
total += spectacle["total"]
|
2016-06-05 02:18:12 +02:00
|
|
|
return render(request, "etat-places.html",
|
2016-07-09 22:31:56 +02:00
|
|
|
{"spectacles": spectacles, "total": total, 'tirage': tirage})
|
2013-09-05 22:20:52 +02:00
|
|
|
|
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
def _hash_queryset(queryset):
|
2016-09-24 17:34:15 +02:00
|
|
|
data = serializers.serialize("json", queryset).encode('utf-8')
|
2014-08-19 12:54:22 +02:00
|
|
|
hasher = hashlib.sha256()
|
|
|
|
hasher.update(data)
|
|
|
|
return hasher.hexdigest()
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
@cof_required
|
2016-06-05 02:18:12 +02:00
|
|
|
def places(request, tirage_id):
|
|
|
|
tirage = get_object_or_404(Tirage, id=tirage_id)
|
|
|
|
participant, created = Participant.objects.get_or_create(
|
2016-07-09 22:31:56 +02:00
|
|
|
user=request.user, tirage=tirage)
|
2016-06-05 02:18:12 +02:00
|
|
|
places = participant.attribution_set.order_by(
|
2016-07-09 22:31:56 +02:00
|
|
|
"spectacle__date", "spectacle").all()
|
2014-08-19 12:54:22 +02:00
|
|
|
total = sum([place.spectacle.price for place in places])
|
|
|
|
filtered_places = []
|
|
|
|
places_dict = {}
|
|
|
|
spectacles = []
|
|
|
|
dates = []
|
|
|
|
warning = False
|
|
|
|
for place in places:
|
|
|
|
if place.spectacle in spectacles:
|
|
|
|
places_dict[place.spectacle].double = True
|
|
|
|
else:
|
|
|
|
place.double = False
|
|
|
|
places_dict[place.spectacle] = place
|
|
|
|
spectacles.append(place.spectacle)
|
|
|
|
filtered_places.append(place)
|
|
|
|
date = place.spectacle.date.date()
|
|
|
|
if date in dates:
|
|
|
|
warning = True
|
|
|
|
else:
|
|
|
|
dates.append(date)
|
|
|
|
return render(request, "resume_places.html",
|
|
|
|
{"participant": participant,
|
|
|
|
"places": filtered_places,
|
2016-06-05 02:18:12 +02:00
|
|
|
"tirage": tirage,
|
2014-08-19 12:54:22 +02:00
|
|
|
"total": total,
|
|
|
|
"warning": warning})
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
@cof_required
|
2016-06-05 02:18:12 +02:00
|
|
|
def inscription(request, tirage_id):
|
|
|
|
tirage = get_object_or_404(Tirage, id=tirage_id)
|
2016-06-06 19:22:01 +02:00
|
|
|
if timezone.now() < tirage.ouverture:
|
2016-08-13 02:57:49 +02:00
|
|
|
error_desc = tirage.ouverture.strftime('Ouverture le %d %b %Y à %H:%M')
|
2016-06-06 19:22:01 +02:00
|
|
|
return render(request, 'resume_inscription.html',
|
2016-07-09 22:31:56 +02:00
|
|
|
{"error_title": "Le tirage n'est pas encore ouvert !",
|
|
|
|
"error_description": error_desc})
|
2016-06-05 02:18:12 +02:00
|
|
|
if timezone.now() > tirage.fermeture:
|
|
|
|
participant, created = Participant.objects.get_or_create(
|
2016-07-09 22:31:56 +02:00
|
|
|
user=request.user, tirage=tirage)
|
2014-08-19 12:54:22 +02:00
|
|
|
choices = participant.choixspectacle_set.order_by("priority").all()
|
2016-06-05 02:18:12 +02:00
|
|
|
return render(request, "resume_inscription.html",
|
2016-07-09 22:31:56 +02:00
|
|
|
{"error_title": "C'est fini !",
|
|
|
|
"error_description":
|
2016-05-26 22:44:10 +02:00
|
|
|
"Tirage au sort dans la journée !",
|
2016-07-09 22:31:56 +02:00
|
|
|
"choices": choices})
|
|
|
|
|
2016-06-06 11:19:27 +02:00
|
|
|
def formfield_callback(f, **kwargs):
|
|
|
|
if f.name == "spectacle":
|
2016-06-07 22:49:19 +02:00
|
|
|
kwargs['queryset'] = tirage.spectacle_set
|
2016-06-06 11:19:27 +02:00
|
|
|
return f.formfield(**kwargs)
|
|
|
|
BdaFormSet = inlineformset_factory(
|
2016-07-09 22:31:56 +02:00
|
|
|
Participant,
|
|
|
|
ChoixSpectacle,
|
|
|
|
fields=("spectacle", "double_choice", "priority"),
|
|
|
|
formset=BaseBdaFormSet,
|
|
|
|
formfield_callback=formfield_callback)
|
2016-06-05 02:18:12 +02:00
|
|
|
participant, created = Participant.objects.get_or_create(
|
2016-07-09 22:31:56 +02:00
|
|
|
user=request.user, tirage=tirage)
|
2012-07-11 17:39:20 +02:00
|
|
|
success = False
|
2014-08-19 12:54:22 +02:00
|
|
|
stateerror = False
|
2012-07-11 17:39:20 +02:00
|
|
|
if request.method == "POST":
|
2014-08-19 12:54:22 +02:00
|
|
|
dbstate = _hash_queryset(participant.choixspectacle_set.all())
|
|
|
|
if "dbstate" in request.POST and dbstate != request.POST["dbstate"]:
|
|
|
|
stateerror = True
|
2016-06-04 13:25:35 +02:00
|
|
|
formset = BdaFormSet(instance=participant)
|
2014-08-19 12:54:22 +02:00
|
|
|
else:
|
2016-06-04 13:25:35 +02:00
|
|
|
formset = BdaFormSet(request.POST, instance=participant)
|
2014-08-19 12:54:22 +02:00
|
|
|
if formset.is_valid():
|
2016-06-05 02:18:12 +02:00
|
|
|
formset.save()
|
2014-08-19 12:54:22 +02:00
|
|
|
success = True
|
2016-06-04 13:25:35 +02:00
|
|
|
formset = BdaFormSet(instance=participant)
|
2012-07-11 17:39:20 +02:00
|
|
|
else:
|
2016-06-04 13:25:35 +02:00
|
|
|
formset = BdaFormSet(instance=participant)
|
2014-08-19 12:54:22 +02:00
|
|
|
dbstate = _hash_queryset(participant.choixspectacle_set.all())
|
2013-09-05 22:20:52 +02:00
|
|
|
total_price = 0
|
2016-06-05 02:18:12 +02:00
|
|
|
for choice in participant.choixspectacle_set.all():
|
2013-09-05 22:20:52 +02:00
|
|
|
total_price += choice.spectacle.price
|
2016-07-09 21:19:37 +02:00
|
|
|
if choice.double:
|
|
|
|
total_price += choice.spectacle.price
|
2016-06-05 02:18:12 +02:00
|
|
|
return render(request, "inscription-bda.html",
|
2016-07-09 22:31:56 +02:00
|
|
|
{"formset": formset,
|
|
|
|
"success": success,
|
|
|
|
"total_price": total_price,
|
|
|
|
"dbstate": dbstate,
|
|
|
|
'tirage': tirage,
|
|
|
|
"stateerror": stateerror})
|
2013-09-05 22:20:52 +02:00
|
|
|
|
|
|
|
|
2016-06-05 02:18:12 +02:00
|
|
|
def do_tirage(request, tirage_id):
|
2016-06-05 16:00:46 +02:00
|
|
|
tirage_elt = get_object_or_404(Tirage, id=tirage_id)
|
2013-09-05 22:20:52 +02:00
|
|
|
form = TokenForm(request.POST)
|
|
|
|
if not form.is_valid():
|
2016-07-15 00:02:56 +02:00
|
|
|
return tirage(request, tirage_id)
|
2014-08-19 12:54:22 +02:00
|
|
|
start = time.time()
|
2013-09-05 22:20:52 +02:00
|
|
|
data = {}
|
2016-06-07 22:49:19 +02:00
|
|
|
shows = tirage_elt.spectacle_set.select_related().all()
|
2016-06-08 13:26:04 +02:00
|
|
|
members = tirage_elt.participant_set.all()
|
2016-07-09 23:59:25 +02:00
|
|
|
choices = ChoixSpectacle.objects.filter(spectacle__tirage=tirage_elt) \
|
|
|
|
.order_by('participant', 'priority').select_related().all()
|
2013-09-05 22:20:52 +02:00
|
|
|
algo = Algorithm(shows, members, choices)
|
|
|
|
results = algo(form.cleaned_data["token"])
|
|
|
|
total_slots = 0
|
|
|
|
total_losers = 0
|
|
|
|
for (_, members, losers) in results:
|
|
|
|
total_slots += len(members)
|
|
|
|
total_losers += len(losers)
|
|
|
|
data["total_slots"] = total_slots
|
|
|
|
data["total_losers"] = total_losers
|
|
|
|
data["shows"] = shows
|
|
|
|
data["token"] = form.cleaned_data["token"]
|
|
|
|
data["members"] = members
|
|
|
|
data["results"] = results
|
|
|
|
total_sold = 0
|
|
|
|
total_deficit = 0
|
|
|
|
opera_deficit = 0
|
2014-08-19 12:54:22 +02:00
|
|
|
for (show, members, _) in results:
|
|
|
|
deficit = (show.slots - len(members)) * show.price
|
2013-09-05 22:20:52 +02:00
|
|
|
total_sold += show.slots * show.price
|
|
|
|
if deficit >= 0:
|
2016-05-26 22:44:10 +02:00
|
|
|
if "Opéra" in show.location.name:
|
2013-09-05 22:20:52 +02:00
|
|
|
opera_deficit += deficit
|
|
|
|
total_deficit += deficit
|
|
|
|
data["total_sold"] = total_sold - total_deficit
|
|
|
|
data["total_deficit"] = total_deficit
|
|
|
|
data["opera_deficit"] = opera_deficit
|
2014-08-19 12:54:22 +02:00
|
|
|
data["duration"] = time.time() - start
|
2013-09-05 22:20:52 +02:00
|
|
|
if request.user.is_authenticated():
|
|
|
|
members2 = {}
|
2016-07-09 21:19:37 +02:00
|
|
|
# Participant objects are not shared accross spectacle results,
|
|
|
|
# so assign a single object for each Participant id
|
|
|
|
members_uniq = {}
|
2013-09-05 22:20:52 +02:00
|
|
|
for (show, members, _) in results:
|
|
|
|
for (member, _, _, _) in members:
|
2014-08-19 12:54:22 +02:00
|
|
|
if member.id not in members_uniq:
|
|
|
|
members_uniq[member.id] = member
|
2013-09-05 22:20:52 +02:00
|
|
|
members2[member] = []
|
|
|
|
member.total = 0
|
2014-08-19 12:54:22 +02:00
|
|
|
member = members_uniq[member.id]
|
2013-09-05 22:20:52 +02:00
|
|
|
members2[member].append(show)
|
|
|
|
member.total += show.price
|
|
|
|
members2 = members2.items()
|
2016-06-05 02:18:12 +02:00
|
|
|
data["members2"] = sorted(members2, key=lambda m: m[0].user.last_name)
|
2016-06-05 13:59:24 +02:00
|
|
|
# À partir d'ici, le tirage devient effectif
|
2016-07-08 00:39:31 +02:00
|
|
|
Attribution.objects.filter(spectacle__tirage=tirage_elt).delete()
|
|
|
|
tirage_elt.tokens += "%s\n\"\"\"%s\"\"\"\n" % (
|
2016-07-10 14:42:09 +02:00
|
|
|
timezone.now().strftime("%y-%m-%d %H:%M:%S"),
|
2016-07-08 00:39:31 +02:00
|
|
|
form.cleaned_data['token'])
|
2016-07-08 20:27:27 +02:00
|
|
|
tirage_elt.enable_do_tirage = False
|
2016-07-08 00:39:31 +02:00
|
|
|
tirage_elt.save()
|
2016-07-15 13:48:51 +02:00
|
|
|
Attribution.objects.bulk_create([
|
|
|
|
Attribution(spectacle=show, participant=member)
|
|
|
|
for show, members, _ in results
|
|
|
|
for member, _, _, _ in members])
|
2013-09-05 22:20:52 +02:00
|
|
|
return render(request, "bda-attrib-extra.html", data)
|
|
|
|
else:
|
|
|
|
return render(request, "bda-attrib.html", data)
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2016-06-05 13:59:24 +02:00
|
|
|
@buro_required
|
2016-06-05 02:18:12 +02:00
|
|
|
def tirage(request, tirage_id):
|
2016-07-08 20:33:26 +02:00
|
|
|
tirage_elt = get_object_or_404(Tirage, id=tirage_id)
|
2016-07-15 02:16:53 +02:00
|
|
|
if not (tirage_elt.enable_do_tirage
|
|
|
|
and tirage_elt.fermeture < timezone.now()):
|
2016-07-08 20:33:26 +02:00
|
|
|
return render(request, "tirage-failed.html", {'tirage': tirage_elt})
|
2013-09-05 22:20:52 +02:00
|
|
|
if request.POST:
|
|
|
|
form = TokenForm(request.POST)
|
|
|
|
if form.is_valid():
|
2016-06-05 02:18:12 +02:00
|
|
|
return do_tirage(request, tirage_id)
|
2013-09-05 22:20:52 +02:00
|
|
|
else:
|
|
|
|
form = TokenForm()
|
|
|
|
return render(request, "bda-token.html", {"form": form})
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
def do_resell(request, form):
|
|
|
|
spectacle = form.cleaned_data["spectacle"]
|
|
|
|
count = form.cleaned_data["count"]
|
|
|
|
places = "2 places" if count == "2" else "une place"
|
2016-05-26 22:44:10 +02:00
|
|
|
mail = """Bonjour,
|
2013-09-05 22:20:52 +02:00
|
|
|
|
|
|
|
Je souhaite revendre %s pour %s le %s (%s) à %.02f€.
|
2014-08-19 12:54:22 +02:00
|
|
|
Contactez moi par email si vous êtes intéressé·e·s !
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2016-06-05 02:18:12 +02:00
|
|
|
%s (%s)""" % (places, spectacle.title, spectacle.date_no_seconds(),
|
2016-07-09 22:31:56 +02:00
|
|
|
spectacle.location, spectacle.price,
|
|
|
|
request.user.get_full_name(), request.user.email)
|
2014-08-19 12:54:22 +02:00
|
|
|
send_mail("%s" % spectacle, mail,
|
2013-09-05 22:20:52 +02:00
|
|
|
request.user.email, ["bda-revente@lists.ens.fr"],
|
2016-07-09 21:19:37 +02:00
|
|
|
fail_silently=False)
|
2016-07-09 22:31:56 +02:00
|
|
|
return render(request, "bda-success.html",
|
|
|
|
{"show": spectacle, "places": places})
|
2013-09-05 22:20:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2016-06-05 02:18:12 +02:00
|
|
|
def revente(request, tirage_id):
|
|
|
|
tirage = get_object_or_404(Tirage, id=tirage_id)
|
|
|
|
participant, created = Participant.objects.get_or_create(
|
2016-07-09 22:31:56 +02:00
|
|
|
user=request.user, tirage=tirage)
|
2013-09-05 22:20:52 +02:00
|
|
|
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)
|
2016-07-09 22:31:56 +02:00
|
|
|
return render(request, "bda-revente.html",
|
|
|
|
{"form": form, 'tirage': tirage})
|
2013-09-05 22:20:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
@buro_required
|
2016-06-05 02:18:12 +02:00
|
|
|
def spectacle(request, tirage_id, spectacle_id):
|
|
|
|
tirage = get_object_or_404(Tirage, id=tirage_id)
|
2016-06-15 21:19:39 +02:00
|
|
|
spectacle = get_object_or_404(Spectacle, id=spectacle_id, tirage=tirage)
|
2016-06-12 18:36:21 +02:00
|
|
|
attributions = spectacle.attribues.all()
|
|
|
|
participants = {}
|
|
|
|
for attrib in attributions:
|
|
|
|
participant = attrib.participant
|
2016-07-09 21:19:37 +02:00
|
|
|
participant_info = {'lastname': participant.user.last_name,
|
|
|
|
'name': participant.user.get_full_name,
|
|
|
|
'username': participant.user.username,
|
|
|
|
'email': participant.user.email,
|
|
|
|
'given': int(attrib.given),
|
|
|
|
'paid': participant.paid,
|
2016-06-15 22:37:23 +02:00
|
|
|
'nb_places': 1}
|
2016-06-12 19:29:50 +02:00
|
|
|
if participant.id in participants:
|
2016-07-09 21:19:37 +02:00
|
|
|
participants[participant.id]['nb_places'] += 1
|
2016-06-16 22:55:34 +02:00
|
|
|
participants[participant.id]['given'] += attrib.given
|
2016-06-12 18:36:21 +02:00
|
|
|
else:
|
2016-06-15 19:34:10 +02:00
|
|
|
participants[participant.id] = participant_info
|
2016-06-15 21:19:39 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
participants_info = sorted(participants.values(),
|
2016-07-09 22:31:56 +02:00
|
|
|
key=lambda part: part['lastname'])
|
2016-07-09 21:19:37 +02:00
|
|
|
return render(request, "bda-participants.html",
|
2016-07-09 22:31:56 +02:00
|
|
|
{"spectacle": spectacle, "participants": participants_info})
|
2016-06-06 18:43:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
class SpectacleListView(ListView):
|
|
|
|
model = Spectacle
|
|
|
|
template_name = 'spectacle_list.html'
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2016-06-06 18:43:56 +02:00
|
|
|
def get_queryset(self):
|
|
|
|
self.tirage = get_object_or_404(Tirage, id=self.kwargs['tirage_id'])
|
2016-06-08 18:37:38 +02:00
|
|
|
categories = self.tirage.spectacle_set.all()
|
2016-06-06 18:43:56 +02:00
|
|
|
return categories
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2016-06-06 18:43:56 +02:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(SpectacleListView, self).get_context_data(**kwargs)
|
|
|
|
context['tirage_id'] = self.tirage.id
|
2016-06-12 18:36:21 +02:00
|
|
|
context['tirage_name'] = self.tirage.title
|
2016-06-06 18:43:56 +02:00
|
|
|
return context
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
@buro_required
|
2016-06-05 02:18:12 +02:00
|
|
|
def unpaid(request, tirage_id):
|
|
|
|
tirage = get_object_or_404(Tirage, id=tirage_id)
|
2016-06-22 02:29:20 +02:00
|
|
|
unpaid = tirage.participant_set \
|
2016-07-09 22:31:56 +02:00
|
|
|
.annotate(nb_attributions=Count('attribution')) \
|
|
|
|
.filter(paid=False, nb_attributions__gt=0).all()
|
2016-06-05 02:18:12 +02:00
|
|
|
return render(request, "bda-unpaid.html", {"unpaid": unpaid})
|
2016-05-21 23:57:36 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2016-06-10 23:53:29 +02:00
|
|
|
@buro_required
|
|
|
|
def send_rappel(request, spectacle_id):
|
|
|
|
show = get_object_or_404(Spectacle, id=spectacle_id)
|
|
|
|
# Mails d'exemples
|
|
|
|
fake_member = request.user
|
|
|
|
fake_member.nb_attr = 1
|
2016-06-11 00:17:26 +02:00
|
|
|
exemple_mail_1place = render_template('mail-rappel.txt', {
|
2016-06-10 23:53:29 +02:00
|
|
|
'member': fake_member,
|
|
|
|
'show': show})
|
|
|
|
fake_member.nb_attr = 2
|
2016-06-11 00:17:26 +02:00
|
|
|
exemple_mail_2places = render_template('mail-rappel.txt', {
|
2016-06-10 23:53:29 +02:00
|
|
|
'member': fake_member,
|
|
|
|
'show': show})
|
2016-07-10 14:19:19 +02:00
|
|
|
# Contexte
|
|
|
|
ctxt = {'show': show,
|
|
|
|
'exemple_mail_1place': exemple_mail_1place,
|
|
|
|
'exemple_mail_2places': exemple_mail_2places}
|
|
|
|
# Envoi confirmé
|
|
|
|
if request.method == 'POST':
|
|
|
|
members = show.send_rappel()
|
|
|
|
ctxt['sent'] = True
|
|
|
|
ctxt['members'] = members
|
|
|
|
# Demande de confirmation
|
|
|
|
else:
|
|
|
|
ctxt['sent'] = False
|
|
|
|
return render(request, "mails-rappel.html", ctxt)
|
2016-08-23 16:22:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
def descriptions_spectacles(request, tirage_id):
|
|
|
|
tirage = get_object_or_404(Tirage, id=tirage_id)
|
2016-08-26 06:06:45 +02:00
|
|
|
shows_qs = tirage.spectacle_set
|
|
|
|
category_name = request.GET.get('category', '')
|
|
|
|
location_id = request.GET.get('location', '')
|
|
|
|
if category_name:
|
|
|
|
shows_qs = shows_qs.filter(category__name=category_name)
|
|
|
|
if location_id:
|
|
|
|
try:
|
|
|
|
shows_qs = shows_qs.filter(location__id=int(location_id))
|
|
|
|
except ValueError:
|
|
|
|
return HttpResponseBadRequest(
|
|
|
|
"La variable GET 'location' doit contenir un entier")
|
|
|
|
return render(request, 'descriptions.html', {'shows': shows_qs.all()})
|