Merge branch 'Aufinal/clean_code' into Kerl/clean_code_amend

This commit is contained in:
Martin Pépin 2016-12-21 11:31:07 +01:00
commit 847345bb63
5 changed files with 45 additions and 31 deletions

View file

@ -68,9 +68,8 @@ class AnnulForm(forms.Form):
self.fields['attributions'].queryset = participant.attribution_set\
.filter(spectacle__date__gte=timezone.now(),
revente__isnull=False,
revente__date__gt=timezone.now()-timedelta(hours=1))\
.filter(Q(revente__soldTo__isnull=True) |
Q(revente__soldTo=participant))
revente__date__gt=timezone.now()-timedelta(hours=1),
revente__soldTo__isnull=True)
class InscriptionReventeForm(forms.Form):

View file

@ -2,6 +2,19 @@
from __future__ import unicode_literals
from django.db import models, migrations
from django.utils import timezone
from datetime import timedelta
def forwards_func(apps, schema_editor):
SpectacleRevente = apps.get_model("bda", "SpectacleRevente")
for revente in SpectacleRevente.objects.all():
is_expired = timezone.now() > revente.date_tirage()
is_direct = (revente.attribution.spectacle.date >= revente.date and
timezone.now() > revente.date + timedelta(minutes=15))
revente.shotgun = is_expired or is_direct
revente.save()
class Migration(migrations.Migration):
@ -16,4 +29,5 @@ class Migration(migrations.Migration):
name='shotgun',
field=models.BooleanField(default=False, verbose_name='Disponible imm\xe9diatement'),
),
migrations.RunPython(forwards_func, migrations.RunPython.noop),
]

View file

@ -8,7 +8,10 @@
{% endif %}
{% if deja_revente %}
<p class="success">Des reventes existent déjà pour certains de ces spectacles ; vérifie les places disponibles sans tirage !</p>
{% elif inscrit_revente %}
<p class="success">Tu as été inscrit à une revente en cours pour ce spectacle !</p>
{% endif %}
<form action="" class="form-horizontal" method="post">
{% csrf_token %}
<div class="form-group">

View file

@ -287,6 +287,7 @@ def revente(request, tirage_id):
if not created:
revente.seller = participant
revente.date = timezone.now()
revente.soldTo = None
revente.notif_sent = False
revente.tirage_done = False
revente.shotgun = False
@ -346,6 +347,7 @@ def revente(request, tirage_id):
revente.soldTo = None
revente.notif_sent = False
revente.tirage_done = False
revente.shotgun = False
if revente.answered_mail:
revente.answered_mail.clear()
revente.save()
@ -366,8 +368,7 @@ def revente(request, tirage_id):
sold = participant.attribution_set.filter(
spectacle__date__gte=timezone.now(),
revente__isnull=False,
revente__soldTo__isnull=False).exclude(
revente__soldTo=participant)
revente__soldTo__isnull=False)
return render(request, "bda-revente.html",
{'tirage': tirage, 'overdue': overdue, "sold": sold,
@ -396,6 +397,7 @@ def list_revente(request, tirage_id):
user=request.user, tirage=tirage)
deja_revente = False
success = False
inscrit_revente = False
if request.method == 'POST':
form = InscriptionReventeForm(tirage, request.POST)
if form.is_valid():
@ -422,6 +424,7 @@ def list_revente(request, tirage_id):
if min_resell is not None:
min_resell.answered_mail.add(participant)
min_resell.save()
inscrit_revente = True
success = True
else:
form = InscriptionReventeForm(
@ -430,7 +433,8 @@ def list_revente(request, tirage_id):
return render(request, "liste-reventes.html",
{"form": form,
"deja_revente": deja_revente, "success": success})
"deja_revente": deja_revente, "success": success,
"inscrit_revente": inscrit_revente})
@login_required
@ -485,14 +489,11 @@ def revente_shotgun(request, tirage_id):
date__gte=timezone.now())
shotgun = []
for spectacle in spectacles:
revente_objects = SpectacleRevente.objects.filter(
reventes = SpectacleRevente.objects.filter(
attribution__spectacle=spectacle,
shotgun=True,
soldTo__isnull=True)
revente_count = 0
for revente in revente_objects:
if revente.shotgun:
revente_count += 1
if revente_count:
if reventes.exists():
shotgun.append(spectacle)
return render(request, "bda-shotgun.html",

View file

@ -550,7 +550,6 @@ def export_members(request):
return response
@buro_required
def csv_export_mega(filename, qs):
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename=' + filename
@ -572,12 +571,12 @@ def csv_export_mega(filename, qs):
@buro_required
def export_mega_remarksonly(request):
filename = 'remarques_mega_2015.csv'
filename = 'remarques_mega_2016.csv'
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename=' + filename
writer = unicodecsv.writer(response)
event = Event.objects.get(title="Mega 15")
event = Event.objects.get(title="Mega 2016")
commentfield = event.commentfields.get(name="Commentaires")
for val in commentfield.values.all():
reg = val.registration
@ -600,42 +599,40 @@ def export_mega_bytype(request, type):
if type not in types:
raise Http404
event = Event.objects.get(title="Mega 15")
event = Event.objects.get(title="Mega 2016")
type_option = event.options.get(name="Type")
participant_type = type_option.choices.get(value=types[type]).id
qs = EventRegistration.objects.filter(event=event).filter(
options__id__exact=participant_type)
return csv_export_mega(type + '_mega_2015.csv', qs)
return csv_export_mega(type + '_mega_2016.csv', qs)
@buro_required
def export_mega_orgas(request):
event = Event.objects.get(title="Mega 15")
type_option = event.options.get(name="Type")
participant_type_a = type_option.choices.get(value="Conscrit étudiant").id
participant_type_b = type_option.choices.get(value="Conscrit élève").id
event = Event.objects.get(title="Mega 2016")
type_option = event.options.get(name="Conscrit ou orga ?")
participant_type = type_option.choices.get(value="Vieux").id
qs = EventRegistration.objects.filter(event=event).exclude(
options__id__in=(participant_type_a, participant_type_b))
return csv_export_mega('orgas_mega_15.csv', qs)
options__id=participant_type)
return csv_export_mega('orgas_mega_2016.csv', qs)
@buro_required
def export_mega_participants(request):
event = Event.objects.get(title="Mega 15")
type_option = event.options.get(name="Type")
participant_type_a = type_option.choices.get(value="Conscrit étudiant").id
participant_type_b = type_option.choices.get(value="Conscrit élève").id
event = Event.objects.get(title="Mega 2016")
type_option = event.options.get(name="Conscrit ou orga ?")
participant_type = type_option.choices.get(value="Conscrit").id
qs = EventRegistration.objects.filter(event=event).filter(
options__id__in=(participant_type_a, participant_type_b))
return csv_export_mega('participants_mega_15.csv', qs)
options__id=participant_type)
return csv_export_mega('participants_mega_2016.csv', qs)
@buro_required
def export_mega(request):
event = Event.objects.filter(title="Mega 15")
event = Event.objects.filter(title="Mega 2016")
qs = EventRegistration.objects.filter(event=event) \
.order_by("user__username")
return csv_export_mega('all_mega_2015.csv', qs)
return csv_export_mega('all_mega_2016.csv', qs)
@buro_required