From b3f7e944c347a22ef436b56e871bd9e9095ed55a Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Sat, 9 Oct 2021 11:52:20 +0200 Subject: [PATCH] =?UTF-8?q?On=20corrige=20la=20recherche=20pour=20filtrer?= =?UTF-8?q?=20sur=20les=20promotions=20et=20les=20d=C3=A9partements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fiches/urls.py | 7 ++++--- fiches/views.py | 18 +++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/fiches/urls.py b/fiches/urls.py index c25c6ea..0f97223 100644 --- a/fiches/urls.py +++ b/fiches/urls.py @@ -1,10 +1,11 @@ from django.urls import path + from . import views urlpatterns = [ path("", views.HomeView.as_view(), name="home"), - path("fiche/edit", views.EditView.as_view(), name="fiche_modif"), - path("fiche/reset", views.ResetView.as_view(), name="fiche_reset"), - path("fiche/", views.FicheView.as_view(), name="fiche"), + path("fiche/_edit", views.EditView.as_view(), name="fiche_modif"), + path("fiche/_reset", views.ResetView.as_view(), name="fiche_reset"), + path("fiche/", views.FicheView.as_view(), name="fiche"), path("birthday", views.BirthdayView.as_view(), name="birthday"), ] diff --git a/fiches/views.py b/fiches/views.py index 6e061a6..6483193 100644 --- a/fiches/views.py +++ b/fiches/views.py @@ -4,7 +4,6 @@ from django.contrib.auth.decorators import login_required from django.core.mail import send_mail from django.db.models import DateTimeField, Q, Value from django.http import HttpResponseRedirect -from django.shortcuts import get_object_or_404 from django.template.loader import render_to_string from django.urls import reverse, reverse_lazy from django.utils import timezone @@ -29,9 +28,7 @@ from fiches.utils import get_ldap_infos class FicheView(DetailView): model = Profile template_name = "fiches/fiche.html" - - def get_object(self): - return get_object_or_404(Profile, user__username=self.kwargs.get("user")) + slug_field = "user__username" @method_decorator(login_required, name="dispatch") @@ -131,10 +128,17 @@ class HomeView(FormView): form_class = SearchForm def form_valid(self, form): + name = form.cleaned_data["name"] + promotion = form.cleaned_data["year"] result = Profile.objects.filter( - Q(full_name__icontains=form.cleaned_data["name"]) - | Q(nickname__icontains=form.cleaned_data["name"]) - ) + Q(full_name__icontains=name) + | Q(nickname__icontains=name) + | Q(user__username__icontains=name) + ).filter(department__in=form.cleaned_data["department"]) + + if promotion is not None: + result = result.filter(promotion=promotion) + return self.render_to_response(self.get_context_data(result=result))