def recherche(request, discipline=None, region=None): query = request.GET.get("q", "") if not query.strip(): # Si on n'a pas de recherche par mots-clés, on redirige vers # l'accueil. kwargs = {} if discipline: kwargs['discipline'] = discipline if region: kwargs['region'] = region return redirect('savoirs.views.index', **kwargs) # Effectuer la recherche discipline_obj = discipline and \ get_object_or_404(Discipline, pk=discipline) region_obj = region and get_object_or_404(Region, pk=region) search = Search(q=query, discipline=discipline_obj, region=region_obj) results = search.run() # Bâtissons une query string pour les liens vers les briques params = {} if query: params['q'] = query if discipline: params['discipline'] = unicode(discipline) if region: params['region'] = unicode(region) if params: briques_query_string = mark_safe( '?' + '&'.join(k + '=' + v.replace('"', '"') for (k, v) in params.iteritems()) ) else: briques_query_string = None excerpt = excerpt_function(Record.objects, query) return render(request, "savoirs/recherche.html", { 'q': query, 'excerpt': excerpt, 'ressources': results.ressources[0:5], 'total_ressources': results.ressources.count(), 'evenements': results.evenements[0:5], 'total_evenements': results.evenements.count(), 'chercheurs': results.chercheurs[0:10], 'total_chercheurs': results.chercheurs.count(), 'groupes': results.groupes[0:10], 'total_groupes': results.groupes.count(), 'actualites': results.actualites[0:5], 'total_actualites': results.actualites.count(), 'appels': results.appels[0:5], 'total_appels': results.appels.count(), 'sites': results.sites[0:5], 'total_sites': results.sites.count(), 'sites_auf': results.sites_auf[0:5], 'briques_query_string': briques_query_string })
def index(request, discipline=None, region=None): """Page d'accueil""" discipline_obj = discipline and get_object_or_404( Discipline, pk=discipline ) region_obj = region and get_object_or_404(Region, pk=region) search = Search(discipline=discipline_obj, region=region_obj) results = search.run() today = datetime.date.today() return render(request, "savoirs/index.html", { 'actualites': results.actualites[0:4], 'appels': results.appels[0:4], 'evenements': results.evenements.filter_debut(min=today) .order_by('debut')[0:4], 'ressources': results.ressources[0:4], 'chercheurs': results.chercheurs[0:10], 'sites': results.sites[0:4], 'caldav_url': configuration['calendrier_publique'] })