user_topics: Refactor the construction loop for UserTopicDict.

This ensures type safety by not mutating the original queryset values,
that django-stubs to type as a TypedDict without total=False.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li 2022-08-10 14:48:11 -04:00 committed by Tim Abbott
parent 1d7abb3f5d
commit 4f4d61cb59
1 changed files with 10 additions and 4 deletions

View File

@ -43,11 +43,17 @@ def get_user_topics(
result = []
for row in rows:
if not include_stream_name:
del row["stream__name"]
user_topic_dict: UserTopicDict = {
"stream_id": row["stream_id"],
"topic_name": row["topic_name"],
"visibility_policy": row["visibility_policy"],
"last_updated": datetime_to_timestamp(row["last_updated"]),
}
row["last_updated"] = datetime_to_timestamp(row["last_updated"])
result.append(row)
if include_stream_name:
user_topic_dict["stream__name"] = row["stream__name"]
result.append(user_topic_dict)
return result