forked from DGNum/gestioCOF
cleanup
This commit is contained in:
parent
b9c2efaf0e
commit
5f29caec3c
6 changed files with 67 additions and 79 deletions
|
@ -8,7 +8,6 @@ from datetime import timedelta
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.forms.models import BaseInlineFormSet
|
from django.forms.models import BaseInlineFormSet
|
||||||
from django.db.models import Q
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from bda.models import Attribution, Spectacle
|
from bda.models import Attribution, Spectacle
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from __future__ import division
|
|
||||||
from __future__ import print_function
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import calendar
|
import calendar
|
||||||
import random
|
import random
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
@ -108,7 +104,7 @@ class Spectacle(models.Model):
|
||||||
mails_data = [
|
mails_data = [
|
||||||
(
|
(
|
||||||
member[0].email,
|
member[0].email,
|
||||||
{'member': member[0],'nb_attr': member[1], 'show': self}
|
{'member': member[0], 'nb_attr': member[1], 'show': self}
|
||||||
)
|
)
|
||||||
for member in members.values()
|
for member in members.values()
|
||||||
]
|
]
|
||||||
|
|
67
bda/views.py
67
bda/views.py
|
@ -5,7 +5,13 @@ from __future__ import print_function
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import random
|
import random
|
||||||
from custommail.utils import send_mass_custom_mail, send_custom_mail
|
import hashlib
|
||||||
|
import time
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from custommail.utils import (
|
||||||
|
send_mass_custom_mail, send_custom_mail, render_mail
|
||||||
|
)
|
||||||
|
|
||||||
from django.shortcuts import render, get_object_or_404
|
from django.shortcuts import render, get_object_or_404
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
@ -16,15 +22,10 @@ from django.forms.models import inlineformset_factory
|
||||||
from django.http import HttpResponseBadRequest, HttpResponseRedirect
|
from django.http import HttpResponseBadRequest, HttpResponseRedirect
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import hashlib
|
|
||||||
|
|
||||||
from django.template import loader
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.views.generic.list import ListView
|
from django.views.generic.list import ListView
|
||||||
|
|
||||||
import time
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
from gestioncof.decorators import cof_required, buro_required
|
from gestioncof.decorators import cof_required, buro_required
|
||||||
from bda.models import Spectacle, Participant, ChoixSpectacle, Attribution,\
|
from bda.models import Spectacle, Participant, ChoixSpectacle, Attribution,\
|
||||||
Tirage, SpectacleRevente
|
Tirage, SpectacleRevente
|
||||||
|
@ -230,8 +231,8 @@ def do_tirage(request, tirage_id):
|
||||||
# À partir d'ici, le tirage devient effectif
|
# À partir d'ici, le tirage devient effectif
|
||||||
Attribution.objects.filter(spectacle__tirage=tirage_elt).delete()
|
Attribution.objects.filter(spectacle__tirage=tirage_elt).delete()
|
||||||
tirage_elt.tokens += "%s\n\"\"\"%s\"\"\"\n" % (
|
tirage_elt.tokens += "%s\n\"\"\"%s\"\"\"\n" % (
|
||||||
timezone.now().strftime("%y-%m-%d %H:%M:%S"),
|
timezone.now().strftime("%y-%m-%d %H:%M:%S"),
|
||||||
form.cleaned_data['token'])
|
form.cleaned_data['token'])
|
||||||
tirage_elt.enable_do_tirage = False
|
tirage_elt.enable_do_tirage = False
|
||||||
tirage_elt.save()
|
tirage_elt.save()
|
||||||
Attribution.objects.bulk_create([
|
Attribution.objects.bulk_create([
|
||||||
|
@ -354,15 +355,15 @@ def revente(request, tirage_id):
|
||||||
annulform = AnnulForm(participant, prefix='annul')
|
annulform = AnnulForm(participant, prefix='annul')
|
||||||
|
|
||||||
overdue = participant.attribution_set.filter(
|
overdue = participant.attribution_set.filter(
|
||||||
spectacle__date__gte=timezone.now(),
|
spectacle__date__gte=timezone.now(),
|
||||||
revente__isnull=False,
|
revente__isnull=False,
|
||||||
revente__seller=participant,
|
revente__seller=participant,
|
||||||
revente__date__lte=timezone.now()-timedelta(hours=1)).filter(
|
revente__date__lte=timezone.now()-timedelta(hours=1)).filter(
|
||||||
Q(revente__soldTo__isnull=True) | Q(revente__soldTo=participant))
|
Q(revente__soldTo__isnull=True) | Q(revente__soldTo=participant))
|
||||||
sold = participant.attribution_set.filter(
|
sold = participant.attribution_set.filter(
|
||||||
spectacle__date__gte=timezone.now(),
|
spectacle__date__gte=timezone.now(),
|
||||||
revente__isnull=False,
|
revente__isnull=False,
|
||||||
revente__soldTo__isnull=False)
|
revente__soldTo__isnull=False)
|
||||||
|
|
||||||
return render(request, "bda-revente.html",
|
return render(request, "bda-revente.html",
|
||||||
{'tirage': tirage, 'overdue': overdue, "sold": sold,
|
{'tirage': tirage, 'overdue': overdue, "sold": sold,
|
||||||
|
@ -372,7 +373,7 @@ def revente(request, tirage_id):
|
||||||
@login_required
|
@login_required
|
||||||
def revente_interested(request, revente_id):
|
def revente_interested(request, revente_id):
|
||||||
revente = get_object_or_404(SpectacleRevente, id=revente_id)
|
revente = get_object_or_404(SpectacleRevente, id=revente_id)
|
||||||
participant, created = Participant.objects.get_or_create(
|
participant, _ = Participant.objects.get_or_create(
|
||||||
user=request.user, tirage=revente.attribution.spectacle.tirage)
|
user=request.user, tirage=revente.attribution.spectacle.tirage)
|
||||||
if (timezone.now() < revente.date + timedelta(hours=1)) or revente.shotgun:
|
if (timezone.now() < revente.date + timedelta(hours=1)) or revente.shotgun:
|
||||||
return render(request, "bda-wrongtime.html",
|
return render(request, "bda-wrongtime.html",
|
||||||
|
@ -387,8 +388,8 @@ def revente_interested(request, revente_id):
|
||||||
@login_required
|
@login_required
|
||||||
def list_revente(request, tirage_id):
|
def list_revente(request, tirage_id):
|
||||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||||
participant, created = Participant.objects.get_or_create(
|
participant, _ = Participant.objects.get_or_create(
|
||||||
user=request.user, tirage=tirage)
|
user=request.user, tirage=tirage)
|
||||||
deja_revente = False
|
deja_revente = False
|
||||||
success = False
|
success = False
|
||||||
inscrit_revente = False
|
inscrit_revente = False
|
||||||
|
@ -400,7 +401,7 @@ def list_revente(request, tirage_id):
|
||||||
participant.save()
|
participant.save()
|
||||||
for spectacle in choices:
|
for spectacle in choices:
|
||||||
qset = SpectacleRevente.objects.filter(
|
qset = SpectacleRevente.objects.filter(
|
||||||
attribution__spectacle=spectacle)
|
attribution__spectacle=spectacle)
|
||||||
if qset.filter(shotgun=True, soldTo__isnull=True).exists():
|
if qset.filter(shotgun=True, soldTo__isnull=True).exists():
|
||||||
# Une place est disponible au shotgun, on suggère à
|
# Une place est disponible au shotgun, on suggère à
|
||||||
# l'utilisateur d'aller la récupérer
|
# l'utilisateur d'aller la récupérer
|
||||||
|
@ -422,24 +423,24 @@ def list_revente(request, tirage_id):
|
||||||
success = True
|
success = True
|
||||||
else:
|
else:
|
||||||
form = InscriptionReventeForm(
|
form = InscriptionReventeForm(
|
||||||
tirage,
|
tirage,
|
||||||
initial={'spectacles': participant.choicesrevente.all()})
|
initial={'spectacles': participant.choicesrevente.all()})
|
||||||
|
|
||||||
return render(request, "liste-reventes.html",
|
return render(request, "liste-reventes.html",
|
||||||
{"form": form,
|
{"form": form,
|
||||||
"deja_revente": deja_revente, "success": success,
|
"deja_revente": deja_revente, "success": success,
|
||||||
"inscrit_revente": inscrit_revente})
|
"inscrit_revente": inscrit_revente})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def buy_revente(request, spectacle_id):
|
def buy_revente(request, spectacle_id):
|
||||||
spectacle = get_object_or_404(Spectacle, id=spectacle_id)
|
spectacle = get_object_or_404(Spectacle, id=spectacle_id)
|
||||||
tirage = spectacle.tirage
|
tirage = spectacle.tirage
|
||||||
participant, created = Participant.objects.get_or_create(
|
participant, _ = Participant.objects.get_or_create(
|
||||||
user=request.user, tirage=tirage)
|
user=request.user, tirage=tirage)
|
||||||
reventes = SpectacleRevente.objects.filter(
|
reventes = SpectacleRevente.objects.filter(
|
||||||
attribution__spectacle=spectacle,
|
attribution__spectacle=spectacle,
|
||||||
soldTo__isnull=True)
|
soldTo__isnull=True)
|
||||||
|
|
||||||
# Si l'utilisateur veut racheter une place qu'il est en train de revendre,
|
# Si l'utilisateur veut racheter une place qu'il est en train de revendre,
|
||||||
# on supprime la revente en question.
|
# on supprime la revente en question.
|
||||||
|
@ -482,13 +483,13 @@ def buy_revente(request, spectacle_id):
|
||||||
def revente_shotgun(request, tirage_id):
|
def revente_shotgun(request, tirage_id):
|
||||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||||
spectacles = tirage.spectacle_set.filter(
|
spectacles = tirage.spectacle_set.filter(
|
||||||
date__gte=timezone.now())
|
date__gte=timezone.now())
|
||||||
shotgun = []
|
shotgun = []
|
||||||
for spectacle in spectacles:
|
for spectacle in spectacles:
|
||||||
reventes = SpectacleRevente.objects.filter(
|
reventes = SpectacleRevente.objects.filter(
|
||||||
attribution__spectacle=spectacle,
|
attribution__spectacle=spectacle,
|
||||||
shotgun=True,
|
shotgun=True,
|
||||||
soldTo__isnull=True)
|
soldTo__isnull=True)
|
||||||
if reventes.exists():
|
if reventes.exists():
|
||||||
shotgun.append(spectacle)
|
shotgun.append(spectacle)
|
||||||
|
|
||||||
|
@ -557,7 +558,7 @@ def send_rappel(request, spectacle_id):
|
||||||
'show': show,
|
'show': show,
|
||||||
'nb_attr': 1
|
'nb_attr': 1
|
||||||
})
|
})
|
||||||
exemple_mail_2place = render_mail('bda-rappel', {
|
exemple_mail_2places = render_mail('bda-rappel', {
|
||||||
'member': request.user,
|
'member': request.user,
|
||||||
'show': show,
|
'show': show,
|
||||||
'nb_attr': 2
|
'nb_attr': 2
|
||||||
|
@ -589,5 +590,5 @@ def descriptions_spectacles(request, tirage_id):
|
||||||
shows_qs = shows_qs.filter(location__id=int(location_id))
|
shows_qs = shows_qs.filter(location__id=int(location_id))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return HttpResponseBadRequest(
|
return HttpResponseBadRequest(
|
||||||
"La variable GET 'location' doit contenir un entier")
|
"La variable GET 'location' doit contenir un entier")
|
||||||
return render(request, 'descriptions.html', {'shows': shows_qs.all()})
|
return render(request, 'descriptions.html', {'shows': shows_qs.all()})
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from __future__ import division
|
from datetime import datetime
|
||||||
from __future__ import print_function
|
import base64
|
||||||
from __future__ import unicode_literals
|
import json
|
||||||
|
|
||||||
from custommail.utils import send_custom_mail, render_mail
|
from custommail.utils import render_mail
|
||||||
|
from captcha.fields import ReCaptchaField
|
||||||
|
|
||||||
from django.shortcuts import render, get_object_or_404, redirect
|
from django.shortcuts import render, get_object_or_404, redirect
|
||||||
|
from django.core import mail
|
||||||
from django.forms import ModelForm
|
from django.forms import ModelForm
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.forms.models import inlineformset_factory, BaseInlineFormSet
|
from django.forms.models import inlineformset_factory, BaseInlineFormSet
|
||||||
|
@ -14,7 +16,6 @@ from django.contrib.auth.models import User
|
||||||
from django.views.generic import ListView
|
from django.views.generic import ListView
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.template import loader
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.db.models import Min
|
from django.db.models import Min
|
||||||
|
@ -26,12 +27,6 @@ from gestioncof.petits_cours_models import PetitCoursDemande, \
|
||||||
from gestioncof.decorators import buro_required
|
from gestioncof.decorators import buro_required
|
||||||
from gestioncof.shared import lock_table, unlock_tables
|
from gestioncof.shared import lock_table, unlock_tables
|
||||||
|
|
||||||
from captcha.fields import ReCaptchaField
|
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
import base64
|
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
class DemandeListView(ListView):
|
class DemandeListView(ListView):
|
||||||
model = PetitCoursDemande
|
model = PetitCoursDemande
|
||||||
|
@ -148,7 +143,7 @@ def _finalize_traitement(request, demande, proposals, proposed_for,
|
||||||
"mainmail": mainmail,
|
"mainmail": mainmail,
|
||||||
"attribdata":
|
"attribdata":
|
||||||
base64.b64encode(json.dumps(attribdata)
|
base64.b64encode(json.dumps(attribdata)
|
||||||
.encode('utf_8')),
|
.encode('utf_8')),
|
||||||
"redo": redo,
|
"redo": redo,
|
||||||
"errors": errors,
|
"errors": errors,
|
||||||
})
|
})
|
||||||
|
@ -286,14 +281,14 @@ def _traitement_post(request, demande):
|
||||||
replyto = settings.MAIL_DATA['petits_cours']['REPLYTO']
|
replyto = settings.MAIL_DATA['petits_cours']['REPLYTO']
|
||||||
mails_to_send = []
|
mails_to_send = []
|
||||||
for (user, msg) in proposed_mails:
|
for (user, msg) in proposed_mails:
|
||||||
msg = EmailMessage("Petits cours ENS par le COF", msg,
|
msg = mail.EmailMessage("Petits cours ENS par le COF", msg,
|
||||||
frommail, [user.email],
|
frommail, [user.email],
|
||||||
[bccaddress], headers={'Reply-To': replyto})
|
[bccaddress], headers={'Reply-To': replyto})
|
||||||
mails_to_send.append(msg)
|
mails_to_send.append(msg)
|
||||||
mails_to_send.append(EmailMessage("Cours particuliers ENS", mainmail,
|
mails_to_send.append(mail.EmailMessage("Cours particuliers ENS", mainmail,
|
||||||
frommail, [demande.email],
|
frommail, [demande.email],
|
||||||
[bccaddress],
|
[bccaddress],
|
||||||
headers={'Reply-To': replyto}))
|
headers={'Reply-To': replyto}))
|
||||||
connection = mail.get_connection(fail_silently=True)
|
connection = mail.get_connection(fail_silently=True)
|
||||||
connection.send_messages(mails_to_send)
|
connection.send_messages(mails_to_send)
|
||||||
lock_table(PetitCoursAttributionCounter, PetitCoursAttribution, User)
|
lock_table(PetitCoursAttributionCounter, PetitCoursAttribution, User)
|
||||||
|
|
|
@ -9,10 +9,7 @@ from django.conf import settings
|
||||||
from django_cas_ng.backends import CASBackend
|
from django_cas_ng.backends import CASBackend
|
||||||
from django_cas_ng.utils import get_cas_client
|
from django_cas_ng.utils import get_cas_client
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.contrib.auth.models import User as DjangoUser
|
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.core.mail import send_mail
|
|
||||||
from django.template import Template, Context
|
|
||||||
|
|
||||||
from gestioncof.models import CofProfile
|
from gestioncof.models import CofProfile
|
||||||
|
|
||||||
|
@ -73,9 +70,9 @@ class COFCASBackend(CASBackend):
|
||||||
def context_processor(request):
|
def context_processor(request):
|
||||||
'''Append extra data to the context of the given request'''
|
'''Append extra data to the context of the given request'''
|
||||||
data = {
|
data = {
|
||||||
"user": request.user,
|
"user": request.user,
|
||||||
"site": Site.objects.get_current(),
|
"site": Site.objects.get_current(),
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -465,21 +465,21 @@ def registration(request):
|
||||||
current_registration.paid = \
|
current_registration.paid = \
|
||||||
(form.cleaned_data['status'] == 'paid')
|
(form.cleaned_data['status'] == 'paid')
|
||||||
current_registration.save()
|
current_registration.save()
|
||||||
if form.event.title == "Mega 15" and created_reg:
|
# if form.event.title == "Mega 15" and created_reg:
|
||||||
field = EventCommentField.objects.get(
|
# field = EventCommentField.objects.get(
|
||||||
event=form.event, name="Commentaires")
|
# event=form.event, name="Commentaires")
|
||||||
try:
|
# try:
|
||||||
comments = EventCommentValue.objects.get(
|
# comments = EventCommentValue.objects.get(
|
||||||
commentfield=field,
|
# commentfield=field,
|
||||||
registration=current_registration).content
|
# registration=current_registration).content
|
||||||
except EventCommentValue.DoesNotExist:
|
# except EventCommentValue.DoesNotExist:
|
||||||
comments = field.default
|
# comments = field.default
|
||||||
# FIXME : il faut faire quelque chose de propre ici,
|
# FIXME : il faut faire quelque chose de propre ici,
|
||||||
# par exemple écrire un mail générique pour
|
# par exemple écrire un mail générique pour
|
||||||
# l'inscription aux événements et/ou donner la
|
# l'inscription aux événements et/ou donner la
|
||||||
# possibilité d'associer un mail aux événements
|
# possibilité d'associer un mail aux événements
|
||||||
# send_custom_mail(member, "mega",
|
# send_custom_mail(member, "mega",
|
||||||
# {"remarques": comments})
|
# {"remarques": comments})
|
||||||
# Enregistrement des inscriptions aux clubs
|
# Enregistrement des inscriptions aux clubs
|
||||||
member.clubs.clear()
|
member.clubs.clear()
|
||||||
for club in clubs_form.cleaned_data['clubs']:
|
for club in clubs_form.cleaned_data['clubs']:
|
||||||
|
|
Loading…
Reference in a new issue