# coding: utf-8 from django.shortcuts import render, redirect, get_object_or_404 from django.contrib.auth.decorators import login_required from django import forms from avisstage.documents import StageDocument from avisstage.models import Stage # Recherche class SearchForm(forms.Form): generique = forms.CharField() def cherche(**kwargs): resultat = [] if "generique" in kwargs: resultat = StageDocument.search().filter( "match", _all={"query": kwargs["generique"], "fuzziness": "auto"}) return Stage.objects.filter(id__in=[s._id for s in resultat], public=True) @login_required def recherche(request): stages = [] if request.method == "GET": form = SearchForm(request.GET) if form.is_valid(): stages = cherche(**form.cleaned_data) else: form = SearchForm() return render(request, 'avisstage/liste/recherche_resultats.html', {"form": form, "stages":stages})