main_topic-fix
All checks were successful
deploy / deploy (push) Successful in 1m28s

This commit is contained in:
2023-12-09 19:45:02 +03:00
parent 724e9bd5a0
commit 3acedcc7d6
2 changed files with 18 additions and 14 deletions

View File

@@ -141,6 +141,21 @@ async def update_shout(_, info, shout_id, shout_input=None, publish=False):
shout_input["updated_at"] = current_time # Set updated_at as Unix timestamp
Shout.update(shout, shout_input)
session.add(shout)
# main topic
# TODO: test main_topic update
if "main_topic" in shout_input:
old_main_topic = session.query(ShoutTopic).filter(and_(ShoutTopic.shout == shout.id, ShoutTopic.main == True)).first()
main_topic = session.query(Topic).filter(Topic.slug == shout_input["main_topic"]).first()
new_main_topic = session.query(ShoutTopic).filter(and_(ShoutTopic.shout == shout.id, ShoutTopic.topic == main_topic.id)).first()
if old_main_topic is not new_main_topic:
old_main_topic.main = False
new_main_topic.main = True
session.add(old_main_topic)
session.add(new_main_topic)
session.commit()
if publish:
if shout.visibility is ShoutVisibility.AUTHORS.value:
shout_dict = shout.dict()