From c3f6d6920ee919427d8815cc041495b5219035f6 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Sun, 17 Nov 2024 23:23:15 +0100 Subject: [PATCH] =?UTF-8?q?Correction=20r=C3=A9sultats=20recherche=20avec?= =?UTF-8?q?=20tags?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #203 --- src/agenda_culturel/views.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index 1ca4dac..7afdf39 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -65,7 +65,7 @@ from django.utils import timezone from django.utils.html import escape from datetime import date, timedelta from django.utils.timezone import datetime -from django.db.models import Q, Subquery, OuterRef, Count, F +from django.db.models import Q, Subquery, OuterRef, Count, F, Func from django.urls import reverse_lazy from django.utils.translation import gettext_lazy as _ @@ -926,8 +926,12 @@ def event_search(request, full=False): ) if 'q' in request.GET: categories = Category.objects.filter(name__icontains=request.GET['q']) - tags = list(set([item for row in Event.objects.extra(where=['%s ILIKE ANY (tags)'], params=[request.GET['q']]).values_list('tags', flat=True).distinct() for item in row])) - tags.sort(key=lambda x: remove_accents(x).lower()) + s_q = remove_accents(request.GET['q'].lower()) + tags = Event.objects.extra(where=['%s ILIKE ANY (tags)'], params=[request.GET['q']]).annotate(arr_tags=Func(F('tags'), function='unnest')).values_list('arr_tags', flat=True).distinct() + tags = [(t, remove_accents(t).lower()) for t in tags] + tags = [t for t in tags if s_q == t[1]] + tags.sort(key=lambda x: x[1]) + tags = [t[0] for t in tags] places = Place.objects.filter(Q(name__icontains=request.GET['q'])) paginator = PaginatorFilter(filter, 10, request)