Browse Source

Minor style changes to API topic.py

merge-requests/167/head
Andrew Shu 2 months ago
committed by talklittle
parent
commit
82472b1950
  1. 26
      tildes/tildes/views/api/beta/topic.py

26
tildes/tildes/views/api/beta/topic.py

@ -60,8 +60,7 @@ def get_topics(request: Request) -> dict: # noqa
# Parse parameters where necessary
try:
period = ShortTimePeriod(allow_none=True)
period = period.deserialize(period_raw)
period = ShortTimePeriod(allow_none=True).deserialize(period_raw)
except ValidationError as exc:
return build_error_response(str(exc), field="period")
@ -128,11 +127,10 @@ def get_topic(request: Request) -> dict:
f"Invalid order value: {comment_order_raw}",
field="order",
)
elif request.user and request.user.comment_sort_order_default:
comment_order = request.user.comment_sort_order_default
else:
if request.user and request.user.comment_sort_order_default:
comment_order = request.user.comment_sort_order_default
else:
comment_order = CommentTreeSortOption.RELEVANCE
comment_order = CommentTreeSortOption.RELEVANCE
try:
topic_id = id36_to_id(topic_id36)
@ -157,15 +155,17 @@ def get_topic(request: Request) -> dict:
tree = CommentTree(comments, comment_order, request.user)
tree.collapse_from_labels()
if request.user:
# collapse old comments if the user has a previous visit to the topic
# (and doesn't have that behavior disabled)
if topic.last_visit_time and request.user.collapse_old_comments:
tree.uncollapse_new_comments(topic.last_visit_time)
tree.finalize_collapsing_maximized()
# collapse old comments if the user has a previous visit to the topic
# (and doesn't have that behavior disabled)
if request.user and topic.last_visit_time and request.user.collapse_old_comments:
tree.uncollapse_new_comments(topic.last_visit_time)
tree.finalize_collapsing_maximized()
commentsjson = comment_subtree_to_dict(request, tree.tree)
# Construct the final response JSON object
response = {"topic": topic_to_dict(topic), "comments": commentsjson}
response = {
"topic": topic_to_dict(topic),
"comments": commentsjson,
}
return response
Loading…
Cancel
Save