Chercheurs + sitotheque
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / sitotheque / views.py
1 # -*- encoding: utf-8 -*-
2 from django.shortcuts import render_to_response
3 from django.template import Context, RequestContext
4 from django.db.models import Q
5
6 from models import Site
7 from forms import SiteSearchForm
8
9 def search_queryset(request):
10 list = Site.objects.order_by("titre")
11 pays = ""
12
13 simpleForm = SiteSearchForm(request.GET)
14 if simpleForm.is_valid ():
15 pays = simpleForm.cleaned_data["pays"]
16 if pays:
17 list = list.filter(pays = pays.pk)
18 discipline = simpleForm.cleaned_data["discipline"]
19 if discipline:
20 list = list.filter(discipline=discipline)
21 thematique = simpleForm.cleaned_data["thematique"]
22 if thematique:
23 list = list.filter(thematique=thematique)
24
25 mots_cles = simpleForm.cleaned_data["mots_cles"]
26 if mots_cles:
27 list = list.filter( Q(titre__icontains=mots_cles)
28 | Q(description__icontains=mots_cles)
29 | Q(editeur__icontains=mots_cles)
30 | Q(auteur__icontains=mots_cles)
31 | Q(mots_cles__icontains=mots_cles) )
32 return list
33
34
35 def index(request):
36 sites = search_queryset(request)
37 site_form = SiteSearchForm(request.GET)
38 nb_sites = sites.count()
39 variables = { 'sites': sites,
40 'site_form': site_form,
41 'nb_sites': nb_sites,
42 }
43 return render_to_response ("sites/index.html", \
44 Context(variables),
45 context_instance = RequestContext(request))
46
47 def retrieve(request, id):
48 """Fiche du site"""
49 site = Site.objects.get(id=id)
50 variables = { 'site': site,
51 }
52 return render_to_response ("sites/retrieve.html", \
53 Context (variables),
54 context_instance = RequestContext(request))