format and lint orm
This commit is contained in:
@@ -7,36 +7,44 @@ from orm.topic import TopicFollower
|
||||
from orm.user import AuthorFollower
|
||||
from typing import List
|
||||
|
||||
|
||||
@query.field("shoutsForFeed")
|
||||
@login_required
|
||||
def get_user_feed(_, info, page, size) -> List[Shout]:
|
||||
user = info.context["request"].user
|
||||
shouts = []
|
||||
with local_session() as session:
|
||||
shouts = session.query(Shout).\
|
||||
join(ShoutAuthor).\
|
||||
join(AuthorFollower).\
|
||||
where(AuthorFollower.follower == user.slug).\
|
||||
order_by(desc(Shout.createdAt))
|
||||
topicrows = session.query(Shout).\
|
||||
join(ShoutTopic).\
|
||||
join(TopicFollower).\
|
||||
where(TopicFollower.follower == user.slug).\
|
||||
order_by(desc(Shout.createdAt))
|
||||
shouts = shouts.union(topicrows).limit(size).offset(page * size).all()
|
||||
return shouts
|
||||
user = info.context["request"].user
|
||||
shouts = []
|
||||
with local_session() as session:
|
||||
shouts = (
|
||||
session.query(Shout)
|
||||
.join(ShoutAuthor)
|
||||
.join(AuthorFollower)
|
||||
.where(AuthorFollower.follower == user.slug)
|
||||
.order_by(desc(Shout.createdAt))
|
||||
)
|
||||
topicrows = (
|
||||
session.query(Shout)
|
||||
.join(ShoutTopic)
|
||||
.join(TopicFollower)
|
||||
.where(TopicFollower.follower == user.slug)
|
||||
.order_by(desc(Shout.createdAt))
|
||||
)
|
||||
shouts = shouts.union(topicrows).limit(size).offset(page * size).all()
|
||||
return shouts
|
||||
|
||||
|
||||
@query.field("myCandidates")
|
||||
@login_required
|
||||
async def user_unpublished_shouts(_, info, page = 1, size = 10) -> List[Shout]:
|
||||
user = info.context["request"].user
|
||||
shouts = []
|
||||
with local_session() as session:
|
||||
shouts = session.query(Shout).\
|
||||
join(ShoutAuthor).\
|
||||
where(and_(Shout.publishedAt == None, ShoutAuthor.user == user.slug)).\
|
||||
order_by(desc(Shout.createdAt)).\
|
||||
limit(size).\
|
||||
offset( page * size).\
|
||||
all()
|
||||
return shouts
|
||||
async def user_unpublished_shouts(_, info, page=1, size=10) -> List[Shout]:
|
||||
user = info.context["request"].user
|
||||
shouts = []
|
||||
with local_session() as session:
|
||||
shouts = (
|
||||
session.query(Shout)
|
||||
.join(ShoutAuthor)
|
||||
.where(and_(Shout.publishedAt == None, ShoutAuthor.user == user.slug))
|
||||
.order_by(desc(Shout.createdAt))
|
||||
.limit(size)
|
||||
.offset(page * size)
|
||||
.all()
|
||||
)
|
||||
return shouts
|
||||
|
Reference in New Issue
Block a user