diff --git a/tildes/tildes/models/pagination.py b/tildes/tildes/models/pagination.py index cf46fc6..df66a95 100644 --- a/tildes/tildes/models/pagination.py +++ b/tildes/tildes/models/pagination.py @@ -113,6 +113,13 @@ class PaginatedQuery(ModelQuery): return self + def remove_before_after(self) -> PaginatedQuery: + """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 @@ -232,6 +239,13 @@ class PaginatedResults: self.has_next_page = False self.has_prev_page = False + # fetch total number of results without pagination + self.total_count = ( + query.request.db_session.query(func.count()) + .select_from(query.remove_before_after().statement) + .scalar() + ) + def __iter__(self) -> Iterator[Any]: """Iterate over the results.""" return iter(self.results) diff --git a/tildes/tildes/templates/search.jinja2 b/tildes/tildes/templates/search.jinja2 index 721b0f9..d16642d 100644 --- a/tildes/tildes/templates/search.jinja2 +++ b/tildes/tildes/templates/search.jinja2 @@ -5,6 +5,7 @@ {% from 'macros/forms.jinja2' import search_form %} {% from 'macros/links.jinja2' import link_to_group with context %} +{% from 'macros/utils.jinja2' import pluralize %} {% block title %}Search results: {{ search }}{% endblock %} @@ -29,7 +30,7 @@ {% block sidebar %} {{ search_form(search, group) }} -

Search results

+

Found {{ pluralize(topics.total_count, "result") }}

Back to home page

diff --git a/tildes/tildes/templates/topic_listing.jinja2 b/tildes/tildes/templates/topic_listing.jinja2 index 6e6461f..122ba35 100644 --- a/tildes/tildes/templates/topic_listing.jinja2 +++ b/tildes/tildes/templates/topic_listing.jinja2 @@ -123,7 +123,7 @@
{% if tag %} {% if is_single_group %} - Showing only topics in {{ link_to_group(group) }} with the tag "{{ tag|replace('_', ' ') }}". + Showing only topics in {{ link_to_group(group) }} with the tag "{{ tag|replace('_', ' ') }}" ({{ topics.total_count }} total). Back to normal view / {% if request.user %} @@ -133,7 +133,7 @@ {% endif %} {% else %} - Showing only topics with the tag "{{ tag|replace('_', ' ') }}". + Showing only topics with the tag "{{ tag|replace('_', ' ') }}" ({{ topics.total_count }} total). Back to normal view {% endif %}