update-shout-fix-4
This commit is contained in:
parent
5943f9bf81
commit
78c7a41c46
|
@ -233,42 +233,43 @@ async def load_shouts_by(_, _info, options):
|
||||||
@login_required
|
@login_required
|
||||||
@query.field('load_shouts_drafts')
|
@query.field('load_shouts_drafts')
|
||||||
async def load_shouts_drafts(_, info):
|
async def load_shouts_drafts(_, info):
|
||||||
user_id = info.context['user_id']
|
user_id = info.context.get('user_id')
|
||||||
|
shouts = []
|
||||||
q = (
|
if user_id:
|
||||||
select(Shout)
|
q = (
|
||||||
.options(joinedload(Shout.authors), joinedload(Shout.topics))
|
select(Shout)
|
||||||
.filter(
|
.options(joinedload(Shout.authors), joinedload(Shout.topics))
|
||||||
and_(
|
.filter(
|
||||||
Shout.deleted_at.is_not(None),
|
and_(
|
||||||
Shout.published_at.is_(None)
|
Shout.deleted_at.is_not(None),
|
||||||
|
Shout.published_at.is_(None)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
shouts = []
|
shouts = []
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
reader = session.query(Author).filter(Author.user == user_id).first()
|
reader = session.query(Author).filter(Author.user == user_id).first()
|
||||||
if isinstance(reader, Author):
|
if isinstance(reader, Author):
|
||||||
q = q.filter(Shout.created_by == reader.id)
|
q = q.filter(Shout.created_by == reader.id)
|
||||||
q = q.group_by(Shout.id)
|
q = q.group_by(Shout.id)
|
||||||
for [shout] in session.execute(q).unique():
|
for [shout] in session.execute(q).unique():
|
||||||
main_topic = (
|
main_topic = (
|
||||||
session.query(Topic.slug)
|
session.query(Topic.slug)
|
||||||
.join(
|
.join(
|
||||||
ShoutTopic,
|
ShoutTopic,
|
||||||
and_(
|
and_(
|
||||||
ShoutTopic.topic == Topic.id,
|
ShoutTopic.topic == Topic.id,
|
||||||
ShoutTopic.shout == shout.id,
|
ShoutTopic.shout == shout.id,
|
||||||
ShoutTopic.main.is_(True),
|
ShoutTopic.main.is_(True),
|
||||||
),
|
),
|
||||||
|
)
|
||||||
|
.first()
|
||||||
)
|
)
|
||||||
.first()
|
|
||||||
)
|
|
||||||
|
|
||||||
if main_topic:
|
if main_topic:
|
||||||
shout.main_topic = main_topic[0]
|
shout.main_topic = main_topic[0]
|
||||||
shouts.append(shout)
|
shouts.append(shout)
|
||||||
|
|
||||||
return shouts
|
return shouts
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user