diff --git a/bda/views.py b/bda/views.py index 486de3f2..cee53085 100644 --- a/bda/views.py +++ b/bda/views.py @@ -3,6 +3,7 @@ import random import hashlib import time +import json from datetime import timedelta from custommail.shortcuts import ( send_mass_custom_mail, send_custom_mail, render_custom_mail @@ -663,31 +664,30 @@ def catalogue(request, request_type): categories = list( CategorieSpectacle.objects.filter( spectacle__in=tirage.spectacle_set.all()) - .distinct()) + .distinct().values('id', 'name')) locations = list( Salle.objects.filter( spectacle__in=tirage.spectacle_set.all()) - .distinct().values_list('name', flat=True)) - data_return = [{'categories': categories, 'locations': locations}] + .distinct().values('id', 'name')) + data_return = {'categories': categories, 'locations': locations} return JsonResponse(data_return, safe=False) if request_type == "descriptions": # Ici on retourne les descriptions correspondant à la catégorie et # à la salle spécifiées - locations = {} - for salle in Salle.objects.all(): - locations[salle.name] = salle.id + try: tirage_id = request.GET.get('id', '') - category_name = request.GET.get('category', '') - location_name = request.GET.get('location', '') + category_id = json.loads(request.GET.get('category', '[0]')) + location_id = json.loads(request.GET.get('location', '[0]')) tirage = get_object_or_404(Tirage, id=tirage_id) shows_qs = tirage.spectacle_set - if category_name: - shows_qs = shows_qs.filter(category__name=category_name) - if location_name: + if not(0 in category_id): shows_qs = shows_qs.filter( - location__id=locations[location_name]) + category__id__in=category_id) + if not(0 in location_id): + shows_qs = shows_qs.filter( + location__id__in=location_id) except ValueError: return HttpResponseBadRequest( "Impossible de trouver des résultats correspondant \