PEP8: Enforced other rules, including 80 cols

This commit is contained in:
Théophile Bastian 2016-07-09 21:31:56 +01:00
parent c7a3656ded
commit 88bccc0e60
23 changed files with 571 additions and 324 deletions

View file

@ -18,7 +18,8 @@ from datetime import timedelta
import time
from gestioncof.decorators import cof_required, buro_required
from bda.models import Spectacle, Participant, ChoixSpectacle, Attribution, Tirage
from bda.models import Spectacle, Participant, ChoixSpectacle, Attribution,\
Tirage
from bda.algorithm import Algorithm
from bda.forms import BaseBdaFormSet, TokenForm, ResellForm
@ -59,7 +60,7 @@ def etat_places(request, tirage_id):
spectacles_dict[spectacle["spectacle"]].slots
total += spectacle["total"]
return render(request, "etat-places.html",
{"spectacles": spectacles, "total": total, 'tirage': tirage})
{"spectacles": spectacles, "total": total, 'tirage': tirage})
def _hash_queryset(queryset):
@ -73,9 +74,9 @@ def _hash_queryset(queryset):
def places(request, tirage_id):
tirage = get_object_or_404(Tirage, id=tirage_id)
participant, created = Participant.objects.get_or_create(
user=request.user, tirage=tirage)
user=request.user, tirage=tirage)
places = participant.attribution_set.order_by(
"spectacle__date", "spectacle").all()
"spectacle__date", "spectacle").all()
total = sum([place.spectacle.price for place in places])
filtered_places = []
places_dict = {}
@ -107,9 +108,9 @@ def places(request, tirage_id):
def places_ics(request, tirage_id):
tirage = get_object_or_404(Tirage, id=tirage_id)
participant, created = Participant.objects.get_or_create(
user=request.user, tirage=tirage)
user=request.user, tirage=tirage)
places = participant.attribution_set.order_by(
"spectacle__date", "spectacle").all()
"spectacle__date", "spectacle").all()
filtered_places = []
places_dict = {}
spectacles = []
@ -133,30 +134,32 @@ def inscription(request, tirage_id):
tirage = get_object_or_404(Tirage, id=tirage_id)
if timezone.now() < tirage.ouverture:
error_desc = "Ouverture le %s" % (
tirage.ouverture.strftime('%d %b %Y à %H:%M'))
tirage.ouverture.strftime('%d %b %Y à %H:%M'))
return render(request, 'resume_inscription.html',
{ "error_title": "Le tirage n'est pas encore ouvert !",
"error_description": error_desc})
{"error_title": "Le tirage n'est pas encore ouvert !",
"error_description": error_desc})
if timezone.now() > tirage.fermeture:
participant, created = Participant.objects.get_or_create(
user=request.user, tirage=tirage)
user=request.user, tirage=tirage)
choices = participant.choixspectacle_set.order_by("priority").all()
return render(request, "resume_inscription.html",
{ "error_title": "C'est fini !",
"error_description": u"Tirage au sort dans la journée !",
"choices": choices})
{"error_title": "C'est fini !",
"error_description":
u"Tirage au sort dans la journée !",
"choices": choices})
def formfield_callback(f, **kwargs):
if f.name == "spectacle":
kwargs['queryset'] = tirage.spectacle_set
return f.formfield(**kwargs)
BdaFormSet = inlineformset_factory(
Participant,
ChoixSpectacle,
fields=("spectacle", "double_choice", "priority"),
formset=BaseBdaFormSet,
formfield_callback=formfield_callback)
Participant,
ChoixSpectacle,
fields=("spectacle", "double_choice", "priority"),
formset=BaseBdaFormSet,
formfield_callback=formfield_callback)
participant, created = Participant.objects.get_or_create(
user=request.user, tirage=tirage)
user=request.user, tirage=tirage)
success = False
stateerror = False
if request.method == "POST":
@ -179,12 +182,12 @@ def inscription(request, tirage_id):
if choice.double:
total_price += choice.spectacle.price
return render(request, "inscription-bda.html",
{ "formset": formset,
"success": success,
"total_price": total_price,
"dbstate": dbstate,
'tirage': tirage,
"stateerror": stateerror})
{"formset": formset,
"success": success,
"total_price": total_price,
"dbstate": dbstate,
'tirage': tirage,
"stateerror": stateerror})
def do_tirage(request, tirage_id):
@ -198,8 +201,8 @@ def do_tirage(request, tirage_id):
data = {}
shows = tirage_elt.spectacle_set.select_related().all()
members = tirage_elt.participant_set.all()
choices = ChoixSpectacle.objects.filter(spectacle__tirage=tirage_elt).order_by(
'participant', 'priority').select_related().all()
choices = ChoixSpectacle.objects.filter(spectacle__tirage=tirage_elt).\
order_by('participant', 'priority').select_related().all()
algo = Algorithm(shows, members, choices)
results = algo(form.cleaned_data["token"])
total_slots = 0
@ -248,8 +251,8 @@ def do_tirage(request, tirage_id):
# cf. issue #32
if False:
Attribution.objects.filter(
spectacle__tirage=tirage_elt
).delete()
spectacle__tirage=tirage_elt
).delete()
for (show, members, _) in results:
for (member, _, _, _) in members:
attrib = Attribution(spectacle=show, participant=member)
@ -280,19 +283,20 @@ Je souhaite revendre %s pour %s le %s (%s) à %.02f€.
Contactez moi par email si vous êtes intéressé·e·s !
%s (%s)""" % (places, spectacle.title, spectacle.date_no_seconds(),
spectacle.location, spectacle.price, request.user.get_full_name(),
request.user.email)
spectacle.location, spectacle.price,
request.user.get_full_name(), request.user.email)
send_mail("%s" % spectacle, mail,
request.user.email, ["bda-revente@lists.ens.fr"],
fail_silently=False)
return render(request, "bda-success.html", {"show": spectacle, "places": places})
return render(request, "bda-success.html",
{"show": spectacle, "places": places})
@login_required
def 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)
user=request.user, tirage=tirage)
if not participant.paid:
return render(request, "bda-notpaid.html", {})
if request.POST:
@ -301,7 +305,8 @@ def revente(request, tirage_id):
return do_resell(request, form)
else:
form = ResellForm(participant)
return render(request, "bda-revente.html", {"form": form, 'tirage': tirage})
return render(request, "bda-revente.html",
{"form": form, 'tirage': tirage})
@buro_required
@ -326,9 +331,9 @@ def spectacle(request, tirage_id, spectacle_id):
participants[participant.id] = participant_info
participants_info = sorted(participants.values(),
key=lambda part: part['lastname'])
key=lambda part: part['lastname'])
return render(request, "bda-participants.html",
{"spectacle": spectacle, "participants": participants_info})
{"spectacle": spectacle, "participants": participants_info})
class SpectacleListView(ListView):
@ -351,8 +356,8 @@ class SpectacleListView(ListView):
def unpaid(request, tirage_id):
tirage = get_object_or_404(Tirage, id=tirage_id)
unpaid = tirage.participant_set \
.annotate(nb_attributions=Count('attribution')) \
.filter(paid=False, nb_attributions__gt=0).all()
.annotate(nb_attributions=Count('attribution')) \
.filter(paid=False, nb_attributions__gt=0).all()
return render(request, "bda-unpaid.html", {"unpaid": unpaid})
@ -363,5 +368,5 @@ def liste_spectacles_ics(request, tirage_id):
for spectacle in spectacles:
spectacle.dtend = spectacle.date + timedelta(seconds=7200)
return render(request, "liste_spectacles.ics",
{"spectacles": spectacles, "tirage": tirage},
content_type="text/calendar")
{"spectacles": spectacles, "tirage": tirage},
content_type="text/calendar")