This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user