From 11370abe7d4e57e39d73b20b64dc9352a3d4b2f2 Mon Sep 17 00:00:00 2001 From: Deimos Date: Mon, 10 Jul 2023 23:02:45 -0600 Subject: [PATCH] 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). --- tildes/tildes/schemas/listing.py | 1 + tildes/tildes/templates/topic_listing.jinja2 | 19 +++++++++++++++++++ tildes/tildes/views/topic.py | 11 ++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tildes/tildes/schemas/listing.py b/tildes/tildes/schemas/listing.py index c11508f..4cdc783 100644 --- a/tildes/tildes/schemas/listing.py +++ b/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 diff --git a/tildes/tildes/templates/topic_listing.jinja2 b/tildes/tildes/templates/topic_listing.jinja2 index 5d0a1c0..8d17477 100644 --- a/tildes/tildes/templates/topic_listing.jinja2 +++ b/tildes/tildes/templates/topic_listing.jinja2 @@ -101,6 +101,25 @@ {% 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 %} +
+ {% if all_subgroups %} + Includes topics from all subgroups. + View with only subscribed subgroups + {% else %} + Includes topics from subscribed subgroups. + View with all subgroups + {% endif %} +
+{% endif %} +
{% if tag %} {% if is_single_group %} diff --git a/tildes/tildes/views/topic.py b/tildes/tildes/views/topic.py index 0d59776..b6be6ff 100644 --- a/tildes/tildes/views/topic.py +++ b/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,