Amélioration de la présentation de la recherche

This commit is contained in:
Jean-Marie Favreau 2024-07-07 18:19:08 +02:00
parent 371e6cc9a1
commit 5d095af291
5 changed files with 96 additions and 7 deletions

View File

@ -0,0 +1,20 @@
{% if paginator_filter.paginator.num_pages != 1 %}
<span>
{% if paginator_filter.has_previous %}
<a href="{{ paginator_filter.paginator.url_first_page }}" role="button">&laquo; premier</a>
<a href="{{ paginator_filter.url_previous_page }}" role="button">précédent</a>
{% endif %}
<span>
Page {{ paginator_filter.number }} sur {{ paginator_filter.paginator.num_pages }}
</span>
{% if paginator_filter.has_next %}
<a href="{{ paginator_filter.url_next_page }}" role="button">suivant</a>
<a href="{{ paginator_filter.paginator.url_last_page }}" role="button">dernier &raquo;</a>
{% endif %}
</span>
{% else %}
Page 1 sur 1
{% endif %}

View File

@ -3,6 +3,7 @@
{% block title %}Rechercher un événement{% endblock %}
{% load utils_extra %}
{% load tag_extra %}
{% load cat_extra %}
{% block entete_header %}
@ -27,8 +28,48 @@
{% endif %}
</form>
{% if has_results %}
{% if has_results or categories %}
<div id="results">
{% if categories %}
<div class="message info">
{% if categories.count > 1 %}
Retrouvez les événements correspondant aux catégories
{% else %}
Retrouvez les événements correspondant à la catégorie
{% endif %}
{% for c in categories %}
{{ c | small_cat_no_contrast }}
{% endfor %}
</div>
{% endif %}
{% if tags %}
<div class="message info">
{% if tags.count > 1 %}
Retrouvez les événements correspondant aux étiquettes
{% else %}
Retrouvez les événements correspondant à l'étiquette
{% endif %}
{% for t in tags %}
{{ t | tag_button_link }}
{% endfor %}
</div>
{% endif %}
{% if places %}
<div class="message info">
{% if places.count > 1 %}
Retrouvez les événements se déroulant dans les lieux
{% else %}
Retrouvez les événements se déroulant dans le lieu
{% endif %}
{% for p in places %}
<a href="{{ p.get_absolute_url }}">{{ p.name }}</a>{% if not forloop.last %},{% endif %}
{% endfor %}
</div>
{% endif %}
<p>{{ paginator_filter.paginator.count }} événement{{paginator_filter.object_list.count | pluralize }} correspond{{paginator_filter.object_list.count | pluralize:"ent" }} à la recherche.</p>
<div>
{% for obj in paginator_filter %}

View File

@ -175,6 +175,13 @@ def small_cat(category, url=None, contrast=True, selected=True, recurrence=False
def small_cat_no_selected(category, url=None):
return small_cat(category, url=url, selected=False)
@register.filter
def small_cat_no_contrast(category, url=None):
if url is None:
url = "/?category=" + str(category.pk)
return small_cat(category, url=url, contrast=False)
@register.filter
def small_cat_recurrent(category, recurrence=False):

View File

@ -5,13 +5,12 @@ from django.urls import reverse_lazy
register = template.Library()
@register.filter
def tag_button(tag, link=False, strike=False):
def t_button(tag, url, strike):
strike_class = " strike" if strike else ""
if link:
if not url is None:
return mark_safe(
'<a href="'
+ reverse_lazy("view_tag", {"tag": tag})
+ url
+ '" role="button" class="small-cat'
+ strike_class
+ '">'
@ -27,7 +26,15 @@ def tag_button(tag, link=False, strike=False):
+ "</span>"
)
@register.filter
def tag_button(tag, link=False, strike=False):
return t_button(tag, reverse_lazy("view_tag", {"tag": tag}) if link else None, strike)
@register.filter
def tag_button_strike(tag, link=False):
return tag_button(tag, link, strike=True)
@register.filter
def tag_button_link(tag):
return t_button(tag, '/?tags=' + tag, False)

View File

@ -794,10 +794,12 @@ class SimpleSearchEventFilter(django_filters.FilterSet):
search_query = SearchQuery(value, config="french")
qs = queryset.filter(
Q(title__icontains=value)
| Q(location__icontains=value)
| Q(category__name__icontains=value)
| Q(tags__icontains=[value])
| Q(exact_location__name__icontains=value)
| Q(description__icontains=value)
)
for f in ["title", "location", "description"]:
for f in ["title", "category__name", "exact_location__name", "description"]:
params = {
f
+ "_hl": SearchHeadline(
@ -875,6 +877,10 @@ class SearchEventFilter(django_filters.FilterSet):
def event_search(request, full=False):
categories = None
tags = None
places = None
if full:
filter = SearchEventFilter(
request.GET,
@ -887,10 +893,15 @@ def event_search(request, full=False):
queryset=get_event_qs(request).order_by("-start_day"),
request=request,
)
if 'q' in request.GET:
categories = Category.objects.filter(name__icontains=request.GET['q'])
tags = [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]
places = Place.objects.filter(Q(name__icontains=request.GET['q']))
paginator = PaginatorFilter(filter, 10, request)
page = request.GET.get("page")
try:
response = paginator.page(page)
except PageNotAnInteger:
@ -903,6 +914,9 @@ def event_search(request, full=False):
"agenda_culturel/search.html",
{
"filter": filter,
"categories": categories,
"tags": tags,
"places": places,
"has_results": len(request.GET) != 0
or (len(request.GET) > 1 and "page" in request.GET),
"paginator_filter": response,