|
|
@ -158,7 +158,7 @@ def get_group_topics( # noqa |
|
|
|
tag: Optional[Ltree], |
|
|
|
all_subgroups: bool, |
|
|
|
unfiltered: bool, |
|
|
|
**kwargs: Any |
|
|
|
**kwargs: Any, |
|
|
|
) -> dict: |
|
|
|
"""Get a listing of topics in the group.""" |
|
|
|
# period needs special treatment so we can distinguish between missing and None |
|
|
@ -353,7 +353,7 @@ def get_search( |
|
|
|
before: Optional[str], |
|
|
|
per_page: int, |
|
|
|
search: str, |
|
|
|
**kwargs: Any |
|
|
|
**kwargs: Any, |
|
|
|
) -> dict: |
|
|
|
"""Get a list of search results.""" |
|
|
|
# period needs special treatment so we can distinguish between missing and None |
|
|
@ -411,6 +411,99 @@ def get_search( |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@view_config(route_name="advanced_search", renderer="search.jinja2") |
|
|
|
@use_kwargs( |
|
|
|
TopicListingSchema( |
|
|
|
only=( |
|
|
|
"after", |
|
|
|
"before", |
|
|
|
"order", |
|
|
|
"per_page", |
|
|
|
"period", |
|
|
|
"group_ids", |
|
|
|
"not_group_ids", |
|
|
|
"tags", |
|
|
|
"all_tags", |
|
|
|
"not_tags", |
|
|
|
"user_ids", |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
def get_advanced_search( # noqa |
|
|
|
request: Request, |
|
|
|
group_ids: Optional[list[int]], |
|
|
|
not_group_ids: Optional[list[int]], |
|
|
|
tags: Optional[list[str]], |
|
|
|
all_tags: Optional[list[str]], |
|
|
|
not_tags: Optional[list[str]], |
|
|
|
user_ids: Optional[list[int]], |
|
|
|
order: Optional[TopicSortOption], |
|
|
|
after: Optional[str], |
|
|
|
before: Optional[str], |
|
|
|
per_page: int, |
|
|
|
**kwargs: Any, |
|
|
|
) -> dict: |
|
|
|
"""Get a list of advanced search results.""" |
|
|
|
# period needs special treatment so we can distinguish between missing and None |
|
|
|
period = kwargs.get("period", missing) |
|
|
|
|
|
|
|
if not order: |
|
|
|
order = TopicSortOption.NEW |
|
|
|
|
|
|
|
if period is missing: |
|
|
|
period = None |
|
|
|
|
|
|
|
query = request.query(Topic).join_all_relationships().apply_sort_option(order) |
|
|
|
|
|
|
|
if group_ids: |
|
|
|
query = query.has_any_groups(group_ids) |
|
|
|
|
|
|
|
if not_group_ids: |
|
|
|
query = query.not_has_any_groups(not_group_ids) |
|
|
|
|
|
|
|
if tags: |
|
|
|
query = query.has_any_tags(tags) |
|
|
|
|
|
|
|
if all_tags: |
|
|
|
query = query.has_all_tags(all_tags) |
|
|
|
|
|
|
|
if not_tags: |
|
|
|
query = query.not_has_any_tags(not_tags) |
|
|
|
|
|
|
|
if user_ids: |
|
|
|
query = query.posted_by_any_users(user_ids) |
|
|
|
|
|
|
|
# restrict the time period, if not set to "all time" |
|
|
|
if period: |
|
|
|
query = query.inside_time_period(period) |
|
|
|
|
|
|
|
# apply before/after pagination restrictions if relevant |
|
|
|
if before: |
|
|
|
query = query.before_id36(before) |
|
|
|
|
|
|
|
if after: |
|
|
|
query = query.after_id36(after) |
|
|
|
|
|
|
|
topics = query.get_page(per_page) |
|
|
|
|
|
|
|
period_options = [SimpleHoursPeriod(hours) for hours in (1, 12, 24, 72)] |
|
|
|
|
|
|
|
# add the current period to the bottom of the dropdown if it's not one of the |
|
|
|
# "standard" ones |
|
|
|
if period and period not in period_options: |
|
|
|
period_options.append(period) |
|
|
|
|
|
|
|
return { |
|
|
|
"search": "", |
|
|
|
"topics": topics, |
|
|
|
"group": None, |
|
|
|
"order": order, |
|
|
|
"order_options": TopicSortOption, |
|
|
|
"period": period, |
|
|
|
"period_options": period_options, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@view_config( |
|
|
|
route_name="new_topic", renderer="new_topic.jinja2", permission="topic.post" |
|
|
|
) |
|
|
|