Merge pull request #1138 from umap-project/search-count
Display the number of maps on search results page
This commit is contained in:
commit
186480ea01
2 changed files with 15 additions and 6 deletions
|
@ -8,9 +8,16 @@
|
|||
<div class="wrapper">
|
||||
<div class="map_list row">
|
||||
{% 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 %}
|
||||
{% trans "Not map found." %}
|
||||
<h2>{% trans "No map found." %}</h2>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue