diff --git a/tildes/tildes/models/topic/topic_query.py b/tildes/tildes/models/topic/topic_query.py index d2f2f60..b3dc293 100644 --- a/tildes/tildes/models/topic/topic_query.py +++ b/tildes/tildes/models/topic/topic_query.py @@ -137,14 +137,19 @@ class TopicQuery(PaginatedQuery): return self - def inside_groups(self, groups: Sequence[Group]) -> "TopicQuery": + def inside_groups( + self, groups: Sequence[Group], include_subgroups: bool = True + ) -> "TopicQuery": """Restrict the topics to inside specific groups (generative).""" - query_paths = [group.path for group in groups] - subgroup_subquery = self.request.db_session.query(Group.group_id).filter( - Group.path.descendant_of(query_paths) - ) + if include_subgroups: + query_paths = [group.path for group in groups] + group_ids = self.request.db_session.query(Group.group_id).filter( + Group.path.descendant_of(query_paths) + ) + else: + group_ids = [group.group_id for group in groups] - return self.filter(Topic.group_id.in_(subgroup_subquery)) # type: ignore + return self.filter(Topic.group_id.in_(group_ids)) # type: ignore def inside_time_period(self, period: SimpleHoursPeriod) -> "TopicQuery": """Restrict the topics to inside a time period (generative).""" diff --git a/tildes/tildes/views/topic.py b/tildes/tildes/views/topic.py index d41c6fe..b6b96a6 100644 --- a/tildes/tildes/views/topic.py +++ b/tildes/tildes/views/topic.py @@ -146,7 +146,9 @@ def get_group_topics( ) -> dict: """Get a listing of topics in the group.""" # pylint: disable=too-many-arguments, too-many-branches, too-many-locals - if request.matched_route.name == "home": + is_home_page = request.matched_route.name == "home" + + if is_home_page: # on the home page, include topics from the user's subscribed groups # (or all groups, if logged-out) if request.user: @@ -171,7 +173,7 @@ def get_group_topics( query = ( request.query(Topic) .join_all_relationships() - .inside_groups(groups) + .inside_groups(groups, include_subgroups=not is_home_page) .apply_sort_option(order) )