Browse Source

Show topics from subscribed subgroups (toggleable)

Now that we have more subgroups, it was an issue that visiting a parent
group would always show the topics from all of the subgroups, regardless
of whether you were subscribed to them or not.

This changes it so that, by default, only topics from subgroups the user
is subscribed to will be shown. There is also a link at the top of the
listing to toggle to the other view (all subgroups or only subscribed
subgroups).
merge-requests/151/head
Deimos 10 months ago
parent
commit
11370abe7d
  1. 1
      tildes/tildes/schemas/listing.py
  2. 19
      tildes/tildes/templates/topic_listing.jinja2
  3. 11
      tildes/tildes/views/topic.py

1
tildes/tildes/schemas/listing.py

@ -35,6 +35,7 @@ class TopicListingSchema(PaginatedListingSchema):
order = Enum(TopicSortOption, missing=None)
tag = Ltree(missing=None)
unfiltered = Boolean(missing=False)
all_subgroups = Boolean(missing=False)
rank_start = Integer(data_key="n", validate=Range(min=1), missing=None)
@pre_load

19
tildes/tildes/templates/topic_listing.jinja2

@ -101,6 +101,25 @@
</div>
{% block filter_info %}
{% if request.context is group %}
{% set is_single_group = True %}
{% else %}
{% set is_single_group = False %}
{% endif %}
{% if is_single_group and subgroups %}
<div class="topic-listing-filter">
{% if all_subgroups %}
Includes topics from all subgroups.
<a href="{{ request.current_listing_normal_url() }}">View with only subscribed subgroups</a>
{% else %}
Includes topics from subscribed subgroups.
<a href="{{ request.current_listing_normal_url({'all_subgroups': 'true'}) }}">View with all subgroups</a>
{% endif %}
</div>
{% endif %}
<div class="topic-listing-filter">
{% if tag %}
{% if is_single_group %}

11
tildes/tildes/views/topic.py

@ -156,6 +156,7 @@ def get_group_topics( # noqa
per_page: int,
rank_start: Optional[int],
tag: Optional[Ltree],
all_subgroups: bool,
unfiltered: bool,
**kwargs: Any
) -> dict:
@ -181,6 +182,11 @@ def get_group_topics( # noqa
# otherwise, just topics from the single group that we're looking at
groups = [request.context]
groups.extend([
sub.group for sub in request.user.subscriptions
if sub.group.is_subgroup_of(request.context)
])
subgroups = (
request.query(Group)
.filter(
@ -207,7 +213,9 @@ def get_group_topics( # noqa
query = (
request.query(Topic)
.join_all_relationships()
.inside_groups(groups, include_subgroups=not is_home_page)
.inside_groups(
groups, include_subgroups=not is_home_page and all_subgroups
)
.exclude_ignored()
.apply_sort_option(order)
)
@ -315,6 +323,7 @@ def get_group_topics( # noqa
),
"rank_start": rank_start,
"tag": tag,
"all_subgroups": all_subgroups,
"unfiltered": unfiltered,
"wiki_pages": wiki_pages,
"wiki_has_index": wiki_has_index,

Loading…
Cancel
Save