From 3edad3976d0de66ee216acf00b20e18284ae343c Mon Sep 17 00:00:00 2001 From: David Larlet Date: Wed, 14 Jun 2023 09:58:48 -0400 Subject: [PATCH] Display the number of maps on search results page --- umap/templates/umap/search.html | 17 ++++++++++++----- umap/views.py | 4 +++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/umap/templates/umap/search.html b/umap/templates/umap/search.html index 074c54c6..98af8429 100644 --- a/umap/templates/umap/search.html +++ b/umap/templates/umap/search.html @@ -7,11 +7,18 @@ {% if q %}
- {% if maps %} - {% include "umap/map_list.html" with prefix='search_map' %} - {% else %} - {% trans "Not map found." %} - {% endif %} + {% if maps %} +

+ {% blocktranslate count counter=count %} + {{ count }} map found: + {% plural %} + {{ count }} maps found: + {% endblocktranslate %} +

+ {% include "umap/map_list.html" with prefix='search_map' %} + {% else %} +

{% trans "No map found." %}

+ {% endif %}
{% endif %} diff --git a/umap/views.py b/umap/views.py index 29006252..9485a2b9 100644 --- a/umap/views.py +++ b/umap/views.py @@ -212,6 +212,7 @@ class Search(TemplateView, PaginatorMixin): def get_context_data(self, **kwargs): q = self.request.GET.get("q") + qs_count = 0 results = [] if q: vector = SearchVector("name", config=settings.UMAP_SEARCH_CONFIGURATION) @@ -220,8 +221,9 @@ class Search(TemplateView, PaginatorMixin): ) qs = Map.objects.annotate(search=vector).filter(search=query) qs = qs.filter(share_status=Map.PUBLIC).order_by("-modified_at") + qs_count = qs.count() results = self.paginate(qs) - kwargs.update({"maps": results, "q": q}) + kwargs.update({"maps": results, "count": qs_count, "q": q}) return kwargs def get_template_names(self):