[#4773] Lien vers chercheurs et ressources similaire
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / sitotheque / views.py
CommitLineData
01a9197e 1# -*- encoding: utf-8 -*-
d7073c74 2from django.shortcuts import render, get_object_or_404, redirect
116db1fd 3
5212238e 4from savoirs.lib.recherche import excerpt_function
2b564f72 5from sitotheque.models import Site
5749dcb6
EMS
6from sitotheque.forms import SiteSearchForm
7
54ab837c 8
f0692c02
EMS
9def index(request):
10 search_form = SiteSearchForm(request.GET)
d7073c74
EMS
11 if search_form.is_valid():
12 sites = search_form.save(commit=False).run()
13 excerpt = excerpt_function(Site.objects, search_form.cleaned_data['q'])
14 nb_sites = sites.count()
15 return render(request, "sites/index.html", {
16 'sites': sites, 'search_form': search_form, 'excerpt': excerpt,
17 'nb_sites': nb_sites
18 })
19 else:
20 return redirect('sites')
5749dcb6
EMS
21
22
f0692c02 23def retrieve(request, id):
6e001443 24 """Fiche du site"""
cb1068e9 25 site = get_object_or_404(Site, id=id)
5749dcb6
EMS
26 return render(request, "sites/retrieve.html", {'site': site})
27
fc2908e4
EMS
28
29def config_google(request):
30 """Fichier de configuration pour la recherche Google"""
31 sites = Site.objects.filter(recherche_google=True)
5749dcb6 32 return render(request, "sites/google.xml", {'sites': sites})