Merge pull request #1138 from umap-project/search-count

Display the number of maps on search results page
This commit is contained in:
Yohan Boniface 2023-06-14 16:03:38 +02:00 committed by GitHub
commit 186480ea01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View file

@ -7,11 +7,18 @@
{% if q %}
<div class="wrapper">
<div class="map_list row">
{% if maps %}
{% include "umap/map_list.html" with prefix='search_map' %}
{% else %}
{% trans "Not map found." %}
{% endif %}
{% if maps %}
<h2>
{% blocktranslate count counter=count %}
{{ count }} map found:
{% plural %}
{{ count }} maps found:
{% endblocktranslate %}
</h2>
{% include "umap/map_list.html" with prefix='search_map' %}
{% else %}
<h2>{% trans "No map found." %}</h2>
{% endif %}
</div>
</div>
{% endif %}

View file

@ -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):