Browse Source

Apply topic tag filters when viewing a single tag

Includes HTML updates to let user click into unfiltered view, when
viewing a single tag.
merge-requests/126/merge
Andrew Shu 4 years ago
committed by Deimos
parent
commit
6fa7718e06
  1. 2
      tildes/tildes/templates/home.jinja2
  2. 6
      tildes/tildes/templates/topic_listing.jinja2
  3. 15
      tildes/tildes/views/topic.py

2
tildes/tildes/templates/home.jinja2

@ -71,7 +71,7 @@
<li>User settings</li>
<ul class="nav">
{% if not (tag or unfiltered) %}
{% if not unfiltered %}
<li><details>
<summary>Filtered topic tags ({{ request.user.filtered_topic_tags|length }})</summary>
<ul class="topic-tags">

6
tildes/tildes/templates/topic_listing.jinja2

@ -112,6 +112,12 @@
Showing only topics with the tag "{{ tag|replace('_', ' ') }}".
<a href="{{ request.current_listing_normal_url() }}">Back to normal view</a>
{% endif %}
{% if request.user.filtered_topic_tags and not unfiltered %}
<br>
Topic tag filters active (see sidebar).
<a href="{{ request.current_listing_normal_url({'tag': tag, 'unfiltered': 'true'}) }}">View unfiltered list</a>
{% endif %}
{% elif unfiltered %}
Showing unfiltered topic list.
<a href="{{ request.current_listing_normal_url() }}">Back to normal view</a>

15
tildes/tildes/views/topic.py

@ -213,11 +213,20 @@ def get_group_topics( # noqa
if after:
query = query.after_id36(after)
# apply topic tag filters unless they're disabled or viewing a single tag
if request.user and request.user.filtered_topic_tags and not (tag or unfiltered):
# apply topic tag filters unless they're disabled
if request.user and request.user.filtered_topic_tags and not unfiltered:
filtered_topic_tags = request.user.filtered_topic_tags
# if viewing single tag, don't filter that tag and its ancestors
# for example, if viewing "ask.survey", don't filter "ask.survey" or "ask"
if tag:
filtered_topic_tags = [
ft for ft in filtered_topic_tags if not tag.descendant_of(ft)
]
query = query.filter(
~Topic.tags.descendant_of( # type: ignore
any_(cast(request.user.filtered_topic_tags, TagList))
any_(cast(filtered_topic_tags, TagList))
)
)

Loading…
Cancel
Save