Browse Source

Merge branch 'tag-filters-viewing-single-tag' into 'master'

Apply topic tag filters when viewing a single tag

Closes #136

See merge request tildes/tildes!110
merge-requests/110/merge
talklittle 5 years ago
parent
commit
9a0d797e43
  1. 2
      tildes/tildes/templates/home.jinja2
  2. 5
      tildes/tildes/templates/topic_listing.jinja2
  3. 16
      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">

5
tildes/tildes/templates/topic_listing.jinja2

@ -112,6 +112,11 @@
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>

16
tildes/tildes/views/topic.py

@ -213,11 +213,21 @@ 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
if tag:
filtered_topic_tags = [
ft
for ft in filtered_topic_tags
if ft != tag.path and not tag.path.startswith(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