Amélioration de la présentation de la recherche
This commit is contained in:
parent
371e6cc9a1
commit
5d095af291
@ -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">« 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 »</a>
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
{% else %}
|
||||||
|
Page 1 sur 1
|
||||||
|
{% endif %}
|
||||||
|
|
@ -3,6 +3,7 @@
|
|||||||
{% block title %}Rechercher un événement{% endblock %}
|
{% block title %}Rechercher un événement{% endblock %}
|
||||||
|
|
||||||
{% load utils_extra %}
|
{% load utils_extra %}
|
||||||
|
{% load tag_extra %}
|
||||||
|
|
||||||
{% load cat_extra %}
|
{% load cat_extra %}
|
||||||
{% block entete_header %}
|
{% block entete_header %}
|
||||||
@ -27,8 +28,48 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% if has_results %}
|
|
||||||
|
{% if has_results or categories %}
|
||||||
<div id="results">
|
<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>
|
<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>
|
<div>
|
||||||
{% for obj in paginator_filter %}
|
{% for obj in paginator_filter %}
|
||||||
|
@ -175,6 +175,13 @@ def small_cat(category, url=None, contrast=True, selected=True, recurrence=False
|
|||||||
def small_cat_no_selected(category, url=None):
|
def small_cat_no_selected(category, url=None):
|
||||||
return small_cat(category, url=url, selected=False)
|
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
|
@register.filter
|
||||||
def small_cat_recurrent(category, recurrence=False):
|
def small_cat_recurrent(category, recurrence=False):
|
||||||
|
@ -5,13 +5,12 @@ from django.urls import reverse_lazy
|
|||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
def t_button(tag, url, strike):
|
||||||
def tag_button(tag, link=False, strike=False):
|
|
||||||
strike_class = " strike" if strike else ""
|
strike_class = " strike" if strike else ""
|
||||||
if link:
|
if not url is None:
|
||||||
return mark_safe(
|
return mark_safe(
|
||||||
'<a href="'
|
'<a href="'
|
||||||
+ reverse_lazy("view_tag", {"tag": tag})
|
+ url
|
||||||
+ '" role="button" class="small-cat'
|
+ '" role="button" class="small-cat'
|
||||||
+ strike_class
|
+ strike_class
|
||||||
+ '">'
|
+ '">'
|
||||||
@ -27,7 +26,15 @@ def tag_button(tag, link=False, strike=False):
|
|||||||
+ "</span>"
|
+ "</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
|
@register.filter
|
||||||
def tag_button_strike(tag, link=False):
|
def tag_button_strike(tag, link=False):
|
||||||
return tag_button(tag, link, strike=True)
|
return tag_button(tag, link, strike=True)
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def tag_button_link(tag):
|
||||||
|
return t_button(tag, '/?tags=' + tag, False)
|
@ -794,10 +794,12 @@ class SimpleSearchEventFilter(django_filters.FilterSet):
|
|||||||
search_query = SearchQuery(value, config="french")
|
search_query = SearchQuery(value, config="french")
|
||||||
qs = queryset.filter(
|
qs = queryset.filter(
|
||||||
Q(title__icontains=value)
|
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)
|
| Q(description__icontains=value)
|
||||||
)
|
)
|
||||||
for f in ["title", "location", "description"]:
|
for f in ["title", "category__name", "exact_location__name", "description"]:
|
||||||
params = {
|
params = {
|
||||||
f
|
f
|
||||||
+ "_hl": SearchHeadline(
|
+ "_hl": SearchHeadline(
|
||||||
@ -875,6 +877,10 @@ class SearchEventFilter(django_filters.FilterSet):
|
|||||||
|
|
||||||
|
|
||||||
def event_search(request, full=False):
|
def event_search(request, full=False):
|
||||||
|
categories = None
|
||||||
|
tags = None
|
||||||
|
places = None
|
||||||
|
|
||||||
if full:
|
if full:
|
||||||
filter = SearchEventFilter(
|
filter = SearchEventFilter(
|
||||||
request.GET,
|
request.GET,
|
||||||
@ -887,10 +893,15 @@ def event_search(request, full=False):
|
|||||||
queryset=get_event_qs(request).order_by("-start_day"),
|
queryset=get_event_qs(request).order_by("-start_day"),
|
||||||
request=request,
|
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)
|
paginator = PaginatorFilter(filter, 10, request)
|
||||||
page = request.GET.get("page")
|
page = request.GET.get("page")
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = paginator.page(page)
|
response = paginator.page(page)
|
||||||
except PageNotAnInteger:
|
except PageNotAnInteger:
|
||||||
@ -903,6 +914,9 @@ def event_search(request, full=False):
|
|||||||
"agenda_culturel/search.html",
|
"agenda_culturel/search.html",
|
||||||
{
|
{
|
||||||
"filter": filter,
|
"filter": filter,
|
||||||
|
"categories": categories,
|
||||||
|
"tags": tags,
|
||||||
|
"places": places,
|
||||||
"has_results": len(request.GET) != 0
|
"has_results": len(request.GET) != 0
|
||||||
or (len(request.GET) > 1 and "page" in request.GET),
|
or (len(request.GET) > 1 and "page" in request.GET),
|
||||||
"paginator_filter": response,
|
"paginator_filter": response,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user