forked from DGNum/gestioCOF
Ajoute des filtres sur la page description.
Les variables `GET` `location` et `category` permettent de filtrer sur les salles et catégories dans le résultats de `/bda/descriptions/<id>`
This commit is contained in:
parent
ab4e7ec084
commit
3bca778734
3 changed files with 20 additions and 6 deletions
15
bda/views.py
15
bda/views.py
|
@ -10,6 +10,7 @@ from django.db import models
|
|||
from django.db.models import Count
|
||||
from django.core import serializers
|
||||
from django.forms.models import inlineformset_factory
|
||||
from django.http import HttpResponseBadRequest
|
||||
import hashlib
|
||||
|
||||
from django.core.mail import send_mail
|
||||
|
@ -368,5 +369,15 @@ def send_rappel(request, spectacle_id):
|
|||
|
||||
def descriptions_spectacles(request, tirage_id):
|
||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||
shows = tirage.spectacle_set.all()
|
||||
return render(request, 'descriptions.html', {'shows': shows})
|
||||
shows_qs = tirage.spectacle_set
|
||||
category_name = request.GET.get('category', '')
|
||||
location_id = request.GET.get('location', '')
|
||||
if category_name:
|
||||
shows_qs = shows_qs.filter(category__name=category_name)
|
||||
if location_id:
|
||||
try:
|
||||
shows_qs = shows_qs.filter(location__id=int(location_id))
|
||||
except ValueError:
|
||||
return HttpResponseBadRequest(
|
||||
"La variable GET 'location' doit contenir un entier")
|
||||
return render(request, 'descriptions.html', {'shows': shows_qs.all()})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue