Fewer requests on descriptions and catalogue views

This commit is contained in:
Aurélien Delobelle 2017-04-08 13:44:21 +02:00
parent 98f355ed20
commit bbe6f41962

View file

@ -710,7 +710,11 @@ def send_rappel(request, spectacle_id):
def descriptions_spectacles(request, tirage_id): def descriptions_spectacles(request, tirage_id):
tirage = get_object_or_404(Tirage, id=tirage_id) tirage = get_object_or_404(Tirage, id=tirage_id)
shows_qs = tirage.spectacle_set shows_qs = (
tirage.spectacle_set
.select_related('location')
.prefetch_related('quote_set')
)
category_name = request.GET.get('category', '') category_name = request.GET.get('category', '')
location_id = request.GET.get('location', '') location_id = request.GET.get('location', '')
if category_name: if category_name:
@ -721,7 +725,7 @@ def descriptions_spectacles(request, tirage_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})
def catalogue(request, request_type): def catalogue(request, request_type):
@ -794,7 +798,11 @@ def catalogue(request, request_type):
) )
tirage = get_object_or_404(Tirage, id=tirage_id) tirage = get_object_or_404(Tirage, id=tirage_id)
shows_qs = tirage.spectacle_set shows_qs = (
tirage.spectacle_set
.select_related('location')
.prefetch_related('quote_set')
)
if categories_id: if categories_id:
shows_qs = shows_qs.filter(category__id__in=categories_id) shows_qs = shows_qs.filter(category__id__in=categories_id)
if locations_id: if locations_id:
@ -813,14 +821,15 @@ 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': list(Quote.objects.filter(spectacle=spectacle).values( 'quotes': [dict(author=quote.author,
'author', 'text')), text=quote.text)
for quote in spectacle.quote_set.all()],
'image': spectacle.getImgUrl(), 'image': spectacle.getImgUrl(),
'ext_link': spectacle.ext_link, 'ext_link': spectacle.ext_link,
'price': spectacle.price, 'price': spectacle.price,
'slots': spectacle.slots 'slots': spectacle.slots
} }
for spectacle in shows_qs.all() for spectacle in shows_qs
] ]
return JsonResponse(data_return, safe=False) return JsonResponse(data_return, safe=False)
# Si la requête n'est pas de la forme attendue, on quitte avec une erreur # Si la requête n'est pas de la forme attendue, on quitte avec une erreur