create-shout-fix
This commit is contained in:
parent
ff6637a51e
commit
f67ef7dd05
|
@ -44,10 +44,9 @@ async def create_shout(_, info, inp):
|
||||||
author = session.query(Author).filter(Author.user == user_id).first()
|
author = session.query(Author).filter(Author.user == user_id).first()
|
||||||
shout_dict = None
|
shout_dict = None
|
||||||
if author:
|
if author:
|
||||||
topics = session.query(Topic).filter(Topic.slug.in_(inp.get("topics", []))).all()
|
|
||||||
current_time = int(time.time())
|
current_time = int(time.time())
|
||||||
new_shout = Shout(
|
slug = inp.get("slug") or f"draft-{current_time}"
|
||||||
**{
|
shout_dict = {
|
||||||
"title": inp.get("title", ""),
|
"title": inp.get("title", ""),
|
||||||
"subtitle": inp.get("subtitle", ""),
|
"subtitle": inp.get("subtitle", ""),
|
||||||
"lead": inp.get("lead", ""),
|
"lead": inp.get("lead", ""),
|
||||||
|
@ -56,23 +55,30 @@ async def create_shout(_, info, inp):
|
||||||
"layout": inp.get("layout", "article"),
|
"layout": inp.get("layout", "article"),
|
||||||
"created_by": author.id,
|
"created_by": author.id,
|
||||||
"authors": [],
|
"authors": [],
|
||||||
"slug": inp.get("slug") or f"draft-{time.time()}",
|
"slug": slug,
|
||||||
"topics": inp.get("topics", []),
|
"topics": inp.get("topics", []),
|
||||||
"visibility": ShoutVisibility.AUTHORS.value,
|
"visibility": ShoutVisibility.AUTHORS.value,
|
||||||
"created_at": current_time, # Set created_at as Unix timestamp
|
"created_at": current_time, # Set created_at as Unix timestamp
|
||||||
}
|
}
|
||||||
)
|
|
||||||
for topic in topics:
|
new_shout = Shout(**shout_dict)
|
||||||
t = ShoutTopic(topic=topic.id, shout=new_shout.id)
|
|
||||||
session.add(t)
|
|
||||||
# NOTE: shout made by one author
|
|
||||||
sa = ShoutAuthor(shout=new_shout.id, author=author.id)
|
|
||||||
session.add(sa)
|
|
||||||
shout_dict = new_shout.dict()
|
|
||||||
session.add(new_shout)
|
session.add(new_shout)
|
||||||
reactions_follow(author.id, new_shout.id, True)
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
# NOTE: shout made by one author
|
||||||
|
shout = session.query(Shout).where(Shout.slug == slug).first()
|
||||||
|
if shout:
|
||||||
|
shout_dict = shout.dict()
|
||||||
|
sa = ShoutAuthor(shout=shout.id, author=author.id)
|
||||||
|
session.add(sa)
|
||||||
|
|
||||||
|
topics = session.query(Topic).filter(Topic.slug.in_(inp.get("topics", []))).all()
|
||||||
|
for topic in topics:
|
||||||
|
t = ShoutTopic(topic=topic.id, shout=shout.id)
|
||||||
|
session.add(t)
|
||||||
|
|
||||||
|
reactions_follow(author.id, shout.id, True)
|
||||||
|
|
||||||
await notify_shout(shout_dict, "create")
|
await notify_shout(shout_dict, "create")
|
||||||
return {"shout": shout_dict}
|
return {"shout": shout_dict}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user