forked from DGNum/gestioCOF
Simplification du code avec des méthodes de Django
This commit is contained in:
parent
a9c8de7544
commit
f3b9266e35
2 changed files with 14 additions and 24 deletions
37
bda/views.py
37
bda/views.py
|
@ -3,12 +3,10 @@
|
||||||
import random
|
import random
|
||||||
import hashlib
|
import hashlib
|
||||||
import time
|
import time
|
||||||
import json
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from custommail.shortcuts import (
|
from custommail.shortcuts import (
|
||||||
send_mass_custom_mail, send_custom_mail, render_custom_mail
|
send_mass_custom_mail, send_custom_mail, render_custom_mail
|
||||||
)
|
)
|
||||||
from more_itertools import unique_everseen
|
|
||||||
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
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
@ -17,7 +15,7 @@ from django.core import serializers
|
||||||
from django.db.models import Count, Q, Sum
|
from django.db.models import Count, Q, Sum
|
||||||
from django.forms.models import inlineformset_factory
|
from django.forms.models import inlineformset_factory
|
||||||
from django.http import HttpResponseBadRequest, HttpResponseRedirect,\
|
from django.http import HttpResponseBadRequest, HttpResponseRedirect,\
|
||||||
JsonResponse, HttpResponse
|
JsonResponse
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils import timezone, formats
|
from django.utils import timezone, formats
|
||||||
|
@ -25,7 +23,7 @@ from django.views.generic.list import ListView
|
||||||
|
|
||||||
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, Salle, Quote
|
Tirage, SpectacleRevente, Salle, Quote, CategorieSpectacle
|
||||||
from bda.algorithm import Algorithm
|
from bda.algorithm import Algorithm
|
||||||
from bda.forms import BaseBdaFormSet, TokenForm, ResellForm, AnnulForm,\
|
from bda.forms import BaseBdaFormSet, TokenForm, ResellForm, AnnulForm,\
|
||||||
InscriptionReventeForm, SoldForm
|
InscriptionReventeForm, SoldForm
|
||||||
|
@ -652,10 +650,8 @@ def catalogue(request, request_type):
|
||||||
"""
|
"""
|
||||||
if request_type == "list":
|
if request_type == "list":
|
||||||
# Dans ce cas on retourne la liste des tirages et de leur id en JSON
|
# Dans ce cas on retourne la liste des tirages et de leur id en JSON
|
||||||
data_return = [
|
data_return = list(
|
||||||
{'id': tirage.id, 'title': tirage.title}
|
Tirage.objects.filter(appear_catalogue=True).values('id', 'title'))
|
||||||
for tirage in Tirage.objects.filter(appear_catalogue=True).all()
|
|
||||||
]
|
|
||||||
return JsonResponse(data_return, safe=False)
|
return JsonResponse(data_return, safe=False)
|
||||||
if request_type == "details":
|
if request_type == "details":
|
||||||
# Dans ce cas on retourne une liste des catégories et des salles
|
# Dans ce cas on retourne une liste des catégories et des salles
|
||||||
|
@ -664,15 +660,14 @@ def catalogue(request, request_type):
|
||||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||||
except:
|
except:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
categories = list(unique_everseen([
|
categories = list(
|
||||||
str(spectacle.category)
|
CategorieSpectacle.objects.filter(
|
||||||
for spectacle in tirage.spectacle_set.all()
|
spectacle__in=tirage.spectacle_set.all())
|
||||||
]))
|
.distinct())
|
||||||
categories.remove('None')
|
locations = list(
|
||||||
locations = list(unique_everseen([
|
Salle.objects.filter(
|
||||||
str(spectacle.location)
|
spectacle__in=tirage.spectacle_set.all())
|
||||||
for spectacle in tirage.spectacle_set.all()
|
.distinct().values_list('name', flat=True))
|
||||||
]))
|
|
||||||
data_return = [{'categories': categories, 'locations': locations}]
|
data_return = [{'categories': categories, 'locations': locations}]
|
||||||
return JsonResponse(data_return, safe=False)
|
return JsonResponse(data_return, safe=False)
|
||||||
if request_type == "descriptions":
|
if request_type == "descriptions":
|
||||||
|
@ -707,11 +702,6 @@ def catalogue(request, request_type):
|
||||||
except:
|
except:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def specquotes(spectacle): [
|
|
||||||
{'author': str(quote.author), 'text': str(quote.text)}
|
|
||||||
for quote in Quote.objects.filter(spectacle = spectacle).all()
|
|
||||||
]
|
|
||||||
|
|
||||||
# On convertit les descriptions à envoyer en une liste facilement
|
# On convertit les descriptions à envoyer en une liste facilement
|
||||||
# JSONifiable (il devrait y avoir un moyen plus efficace en
|
# JSONifiable (il devrait y avoir un moyen plus efficace en
|
||||||
# redéfinissant le serializer de JSON)
|
# redéfinissant le serializer de JSON)
|
||||||
|
@ -725,7 +715,8 @@ def catalogue(request, request_type):
|
||||||
'vips': spectacle.vips,
|
'vips': spectacle.vips,
|
||||||
'description': spectacle.description,
|
'description': spectacle.description,
|
||||||
'slots_description': spectacle.slots_description,
|
'slots_description': spectacle.slots_description,
|
||||||
'quotes': specquotes(spectacle),
|
'quotes': list(Quote.objects.filter(spectacle=spectacle).values(
|
||||||
|
'author', 'text')),
|
||||||
'image': getImgUrl(spectacle),
|
'image': getImgUrl(spectacle),
|
||||||
'ext_link': spectacle.ext_link,
|
'ext_link': spectacle.ext_link,
|
||||||
'price': spectacle.price,
|
'price': spectacle.price,
|
||||||
|
|
|
@ -11,7 +11,6 @@ DBPASSWD="4KZt3nGPLVeWSvtBZPSM3fSzXpzEU4"
|
||||||
apt-get update && apt-get install -y python3-pip python3-dev python3-venv \
|
apt-get update && apt-get install -y python3-pip python3-dev python3-venv \
|
||||||
libmysqlclient-dev libjpeg-dev git redis-server
|
libmysqlclient-dev libjpeg-dev git redis-server
|
||||||
pip install -U pip
|
pip install -U pip
|
||||||
pip install more_itertools
|
|
||||||
|
|
||||||
# Configuration et installation de mysql. Le mot de passe root est le même que
|
# Configuration et installation de mysql. Le mot de passe root est le même que
|
||||||
# le mot de passe pour l'utilisateur local - pour rappel, ceci est une instance
|
# le mot de passe pour l'utilisateur local - pour rappel, ceci est une instance
|
||||||
|
|
Loading…
Reference in a new issue