Browse Source

Fix to display total number of results

merge-requests/142/head
kencx 2 years ago
parent
commit
cac110c2e5
  1. 10
      tildes/tildes/models/pagination.py
  2. 2
      tildes/tildes/templates/search.jinja2
  3. 4
      tildes/tildes/templates/topic_listing.jinja2

10
tildes/tildes/models/pagination.py

@ -112,6 +112,13 @@ class PaginatedQuery(ModelQuery):
return self
def remove_before_after(self):
"""Remove all before or after restrictions from query"""
self.before_id = None
self.after_id = None
return self
def _apply_before_or_after(self) -> PaginatedQuery:
"""Apply the "before" or "after" restrictions if necessary."""
# pylint: disable=assignment-from-no-return
@ -229,6 +236,9 @@ class PaginatedResults:
self.has_next_page = False
self.has_prev_page = False
# fetch total number of results without pagination
self.total_count = len(query.remove_before_after().all())
def __iter__(self) -> Iterator[Any]:
"""Iterate over the results."""
return iter(self.results)

2
tildes/tildes/templates/search.jinja2

@ -30,7 +30,7 @@
{% block sidebar %}
{{ search_form(search, group) }}
<h2>Found {{ pluralize(topics|length, "result") }}</h2>
<h2>Found {{ pluralize(topics.total_count, "result") }}</h2>
<p><a href="/">Back to home page</a></p>

4
tildes/tildes/templates/topic_listing.jinja2

@ -104,7 +104,7 @@
<div class="topic-listing-filter">
{% if tag %}
{% if is_single_group %}
Showing only topics in {{ link_to_group(group) }} with the tag "{{ tag|replace('_', ' ') }}" ({{ topics|length }} total).
Showing only topics in {{ link_to_group(group) }} with the tag "{{ tag|replace('_', ' ') }}" ({{ topics.total_count }} total).
<h2>{{ pluralize(topic.num_comments, "comment") }}</h2>
<a href="{{ request.current_listing_normal_url() }}">Back to normal view</a> /
<a href="{{ request.route_url("home", _query={"tag": tag}) }}">
@ -115,7 +115,7 @@
{% endif %}
</a>
{% else %}
Showing only topics with the tag "{{ tag|replace('_', ' ') }}" ({{ topics|length }} total).
Showing only topics with the tag "{{ tag|replace('_', ' ') }}" ({{ topics.total_count }} total).
<a href="{{ request.current_listing_normal_url() }}">Back to normal view</a>
{% endif %}

Loading…
Cancel
Save