Correction des messages d'erreur et de la gestion des exceptions
This commit is contained in:
parent
67b4421933
commit
6b8001db56
1 changed files with 27 additions and 10 deletions
37
bda/views.py
37
bda/views.py
|
@ -22,7 +22,7 @@ from django.core.urlresolvers import reverse
|
|||
from django.conf import settings
|
||||
from django.utils import timezone, formats
|
||||
from django.views.generic.list import ListView
|
||||
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from gestioncof.decorators import cof_required, buro_required
|
||||
from bda.models import (
|
||||
Spectacle, Participant, ChoixSpectacle, Attribution, Tirage,
|
||||
|
@ -661,11 +661,17 @@ def catalogue(request, request_type):
|
|||
return JsonResponse(data_return, safe=False)
|
||||
if request_type == "details":
|
||||
# Dans ce cas on retourne une liste des catégories et des salles
|
||||
tirage_id = request.GET.get('id', '')
|
||||
try:
|
||||
tirage_id = request.GET.get('id', '')
|
||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||
tirage = Tirage.objects.get(id=tirage_id)
|
||||
except ObjectDoesNotExist:
|
||||
return HttpResponseBadRequest(
|
||||
"Aucun tirage correspondant à l'id "
|
||||
+ tirage_id)
|
||||
except ValueError:
|
||||
return HttpResponseBadRequest("Pas de tirage pour cet id")
|
||||
return HttpResponseBadRequest(
|
||||
"Mauvais format d'identifiant : "
|
||||
+ tirage_id)
|
||||
categories = list(
|
||||
CategorieSpectacle.objects.filter(
|
||||
spectacle__in=tirage.spectacle_set.all())
|
||||
|
@ -680,11 +686,13 @@ def catalogue(request, request_type):
|
|||
# Ici on retourne les descriptions correspondant à la catégorie et
|
||||
# à la salle spécifiées
|
||||
|
||||
tirage_id = request.GET.get('id', '')
|
||||
categories = request.GET.get('category', '[0]')
|
||||
locations = request.GET.get('location', '[0]')
|
||||
try:
|
||||
tirage_id = request.GET.get('id', '')
|
||||
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)
|
||||
category_id = json.loads(categories)
|
||||
location_id = json.loads(locations)
|
||||
tirage = Tirage.objects.get(id=tirage_id)
|
||||
|
||||
shows_qs = tirage.spectacle_set
|
||||
if not(0 in category_id):
|
||||
|
@ -693,10 +701,19 @@ def catalogue(request, request_type):
|
|||
if not(0 in location_id):
|
||||
shows_qs = shows_qs.filter(
|
||||
location__id__in=location_id)
|
||||
except ValueError:
|
||||
except ObjectDoesNotExist:
|
||||
return HttpResponseBadRequest(
|
||||
"Impossible de trouver des résultats correspondant "
|
||||
"à ces caractéristiques")
|
||||
"à ces caractéristiques : "
|
||||
+ "id = " + tirage_id
|
||||
+ ", catégories = " + categories
|
||||
+ ", salles = " + locations)
|
||||
except ValueError: # Contient JSONDecodeError
|
||||
return HttpResponseBadRequest(
|
||||
"Impossible de parser les paramètres donnés : "
|
||||
+ "id = " + request.GET.get('id', '')
|
||||
+ ", catégories = " + request.GET.get('category', '[0]')
|
||||
+ ", salles = " + request.GET.get('location', '[0]'))
|
||||
|
||||
# On convertit les descriptions à envoyer en une liste facilement
|
||||
# JSONifiable (il devrait y avoir un moyen plus efficace en
|
||||
|
|
Loading…
Reference in a new issue