|
@ -193,6 +193,14 @@ class TopicQuery(PaginatedQuery): |
|
|
|
|
|
|
|
|
return self.filter(Topic.group_id.in_(group_ids)) # type: ignore |
|
|
return self.filter(Topic.group_id.in_(group_ids)) # type: ignore |
|
|
|
|
|
|
|
|
|
|
|
def has_any_groups(self, group_ids: list[int]) -> TopicQuery: |
|
|
|
|
|
"""Restrict the topics to those with any of the given group IDs (generative).""" |
|
|
|
|
|
return self.filter(Topic.group_id.in_(group_ids)) # type: ignore |
|
|
|
|
|
|
|
|
|
|
|
def not_has_any_groups(self, group_ids: list[int]) -> TopicQuery: |
|
|
|
|
|
"""Restrict to topics those given group IDs (generative).""" |
|
|
|
|
|
return self.filter(~Topic.group_id.in_(group_ids)) # type: ignore |
|
|
|
|
|
|
|
|
def inside_time_period(self, period: SimpleHoursPeriod) -> TopicQuery: |
|
|
def inside_time_period(self, period: SimpleHoursPeriod) -> TopicQuery: |
|
|
"""Restrict the topics to inside a time period (generative).""" |
|
|
"""Restrict the topics to inside a time period (generative).""" |
|
|
# if the time period is too long, this will crash by creating a datetime outside |
|
|
# if the time period is too long, this will crash by creating a datetime outside |
|
@ -216,6 +224,40 @@ class TopicQuery(PaginatedQuery): |
|
|
# pylint: disable=protected-access |
|
|
# pylint: disable=protected-access |
|
|
return self.filter(Topic.tags.lquery(query)) # type: ignore |
|
|
return self.filter(Topic.tags.lquery(query)) # type: ignore |
|
|
|
|
|
|
|
|
|
|
|
def has_any_tags(self, tags: list[str]) -> TopicQuery: |
|
|
|
|
|
"""Restrict the topics to ones with any of the specified tags (generative). |
|
|
|
|
|
|
|
|
|
|
|
Tags can be any valid ltree, including wildcards, e.g. 'ask.*'. |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
return self.filter(Topic.tags.lquery(tags)) # type: ignore |
|
|
|
|
|
|
|
|
|
|
|
def has_all_tags(self, tags: list[str]) -> TopicQuery: |
|
|
|
|
|
"""Restrict the topics to ones with all of the specified tags (generative). |
|
|
|
|
|
|
|
|
|
|
|
Tags can be any valid ltree, including wildcards, e.g. 'ask.*'. |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
tag_queries = [Topic.tags.lquery(tag) for tag in tags] # type: ignore |
|
|
|
|
|
# For example, |
|
|
|
|
|
# ["ask.*", "japanese"] |
|
|
|
|
|
# produces (rough) SQL |
|
|
|
|
|
# (topics.tags ~ 'ask.*' AND topic.tags ~ 'japanese') |
|
|
|
|
|
return self.filter(and_(*tag_queries)) |
|
|
|
|
|
|
|
|
|
|
|
def not_has_any_tags(self, tags: list[str]) -> TopicQuery: |
|
|
|
|
|
"""Restrict the topics to ones without any of the specified tags (generative). |
|
|
|
|
|
|
|
|
|
|
|
Tags can be any valid ltree, including wildcards, e.g. 'ask.*'. |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
return self.filter(~Topic.tags.lquery(tags)) # type: ignore |
|
|
|
|
|
|
|
|
|
|
|
def posted_by_any_users(self, user_ids: list[int]) -> TopicQuery: |
|
|
|
|
|
"""Restrict the topics to ones posted by the specified user (generative).""" |
|
|
|
|
|
|
|
|
|
|
|
return self.filter(Topic.user_id.in_(user_ids)) # type: ignore |
|
|
|
|
|
|
|
|
def search(self, query: str) -> TopicQuery: |
|
|
def search(self, query: str) -> TopicQuery: |
|
|
"""Restrict the topics to ones that match a search query (generative).""" |
|
|
"""Restrict the topics to ones that match a search query (generative).""" |
|
|
# Replace "." with space, since tags are stored as space-separated strings |
|
|
# Replace "." with space, since tags are stored as space-separated strings |
|
|