[#3466] Désactive 3 sources plus valide
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / sitotheque / views.py
1 # -*- encoding: utf-8 -*-
2 from django.shortcuts import render, get_object_or_404, redirect
3
4 from savoirs.lib.recherche import excerpt_function
5 from sitotheque.models import Site
6 from sitotheque.forms import SiteSearchForm
7
8
9 def index(request):
10 search_form = SiteSearchForm(request.GET)
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')
21
22
23 def retrieve(request, id):
24 """Fiche du site"""
25 site = get_object_or_404(Site, id=id)
26 return render(request, "sites/retrieve.html", {'site': site})
27
28
29 def config_google(request):
30 """Fichier de configuration pour la recherche Google"""
31 sites = Site.objects.filter(recherche_google=True)
32 return render(request, "sites/google.xml", {'sites': sites})