old naming
This commit is contained in:
@@ -68,7 +68,7 @@ async def load_shout(_, info, slug):
|
||||
|
||||
for author_caption in session.query(ShoutAuthor).join(Shout).where(Shout.slug == slug):
|
||||
for author in shout.authors:
|
||||
if author.id == author_caption.userId:
|
||||
if author.id == author_caption.user:
|
||||
author.caption = author_caption.caption
|
||||
|
||||
return shout
|
||||
|
@@ -23,19 +23,19 @@ def add_author_stat_columns(q):
|
||||
user_rating_aliased = aliased(UserRating)
|
||||
|
||||
q = q.outerjoin(shout_author_aliased).add_columns(
|
||||
func.count(distinct(shout_author_aliased.shoutId)).label('shouts_stat')
|
||||
func.count(distinct(shout_author_aliased.shout)).label('shouts_stat')
|
||||
)
|
||||
q = q.outerjoin(author_followers, author_followers.authorId == User.id).add_columns(
|
||||
func.count(distinct(author_followers.followerId)).label('followers_stat')
|
||||
q = q.outerjoin(author_followers, author_followers.author == User.id).add_columns(
|
||||
func.count(distinct(author_followers.follower)).label('followers_stat')
|
||||
)
|
||||
|
||||
q = q.outerjoin(author_following, author_following.followerId == User.id).add_columns(
|
||||
func.count(distinct(author_following.authorId)).label('followings_stat')
|
||||
q = q.outerjoin(author_following, author_following.follower == User.id).add_columns(
|
||||
func.count(distinct(author_following.author)).label('followings_stat')
|
||||
)
|
||||
|
||||
q = q.add_columns(literal(0).label('rating_stat'))
|
||||
# FIXME
|
||||
# q = q.outerjoin(user_rating_aliased, user_rating_aliased.userId == User.id).add_columns(
|
||||
# q = q.outerjoin(user_rating_aliased, user_rating_aliased.user == User.id).add_columns(
|
||||
# # TODO: check
|
||||
# func.sum(user_rating_aliased.value).label('rating_stat')
|
||||
# )
|
||||
@@ -120,7 +120,7 @@ async def get_followed_authors(_, _info, slug) -> List[User]:
|
||||
async def followed_authors(slug) -> List[User]:
|
||||
q = select(User)
|
||||
q = add_author_stat_columns(q)
|
||||
q = q.join(AuthorFollower).join(User, User.id == AuthorFollower.followerId).where(User.slug == slug)
|
||||
q = q.join(AuthorFollower).join(User, User.id == AuthorFollower.follower).where(User.slug == slug)
|
||||
|
||||
return get_authors_from_query(q)
|
||||
|
||||
@@ -132,7 +132,7 @@ async def user_followers(_, _info, slug) -> List[User]:
|
||||
|
||||
aliased_user = aliased(User)
|
||||
q = q.join(AuthorFollower).join(
|
||||
aliased_user, aliased_user.id == AuthorFollower.authorId
|
||||
aliased_user, aliased_user.id == AuthorFollower.author
|
||||
).where(
|
||||
aliased_user.slug == slug
|
||||
)
|
||||
@@ -147,7 +147,7 @@ async def get_user_roles(slug):
|
||||
session.query(Role)
|
||||
.options(joinedload(Role.permissions))
|
||||
.join(UserRole)
|
||||
.where(UserRole.userId == user.id)
|
||||
.where(UserRole.user == user.id)
|
||||
.all()
|
||||
)
|
||||
|
||||
@@ -193,7 +193,7 @@ async def rate_user(_, info, rated_userslug, value):
|
||||
def author_follow(user, slug):
|
||||
with local_session() as session:
|
||||
author = session.query(User).where(User.slug == slug).one()
|
||||
af = AuthorFollower.create(followerId=user.id, authorId=author.id)
|
||||
af = AuthorFollower.create(follower=user.id, author=author.id)
|
||||
session.add(af)
|
||||
session.commit()
|
||||
|
||||
@@ -204,9 +204,9 @@ def author_unfollow(user, slug):
|
||||
flw = (
|
||||
session.query(
|
||||
AuthorFollower
|
||||
).join(User, User.id == AuthorFollower.authorId).filter(
|
||||
).join(User, User.id == AuthorFollower.author).filter(
|
||||
and_(
|
||||
AuthorFollower.followerId == user.id, User.slug == slug
|
||||
AuthorFollower.follower == user.id, User.slug == slug
|
||||
)
|
||||
).first()
|
||||
)
|
||||
@@ -221,7 +221,7 @@ def author_unfollow(user, slug):
|
||||
async def get_authors_all(_, _info):
|
||||
q = select(User)
|
||||
q = add_author_stat_columns(q)
|
||||
q = q.join(ShoutAuthor, User.id == ShoutAuthor.userId)
|
||||
q = q.join(ShoutAuthor, User.id == ShoutAuthor.user)
|
||||
|
||||
return get_authors_from_query(q)
|
||||
|
||||
|
@@ -20,15 +20,15 @@ def reactions_follow(user: User, slug: str, auto=False):
|
||||
|
||||
following = (
|
||||
session.query(ShoutReactionsFollower).where(and_(
|
||||
ShoutReactionsFollower.followerId == user.id,
|
||||
ShoutReactionsFollower.shoutId == shout.id,
|
||||
ShoutReactionsFollower.follower == user.id,
|
||||
ShoutReactionsFollower.shout == shout.id,
|
||||
)).first()
|
||||
)
|
||||
|
||||
if not following:
|
||||
following = ShoutReactionsFollower.create(
|
||||
followerId=user.id,
|
||||
shoutId=shout.id,
|
||||
follower=user.id,
|
||||
shout=shout.id,
|
||||
auto=auto
|
||||
)
|
||||
session.add(following)
|
||||
@@ -41,8 +41,8 @@ def reactions_unfollow(user, slug):
|
||||
|
||||
following = (
|
||||
session.query(ShoutReactionsFollower).where(and_(
|
||||
ShoutReactionsFollower.followerId == user.id,
|
||||
ShoutReactionsFollower.shoutId == shout.id
|
||||
ShoutReactionsFollower.follower == user.id,
|
||||
ShoutReactionsFollower.shout == shout.id
|
||||
)).first()
|
||||
)
|
||||
|
||||
@@ -74,7 +74,7 @@ def check_to_publish(session, user, reaction):
|
||||
]:
|
||||
if is_published_author(user):
|
||||
# now count how many approvers are voted already
|
||||
approvers_reactions = session.query(Reaction).where(Reaction.shoutId == reaction.shoutId).all()
|
||||
approvers_reactions = session.query(Reaction).where(Reaction.shout == reaction.shout).all()
|
||||
approvers = [user.slug, ]
|
||||
for ar in approvers_reactions:
|
||||
a = ar.createdBy
|
||||
@@ -93,7 +93,7 @@ def check_to_hide(session, user, reaction):
|
||||
ReactionKind.UNPROOF
|
||||
]:
|
||||
# if is_published_author(user):
|
||||
approvers_reactions = session.query(Reaction).where(Reaction.shoutId == reaction.shoutId).all()
|
||||
approvers_reactions = session.query(Reaction).where(Reaction.shout == reaction.shout).all()
|
||||
declines = 0
|
||||
for r in approvers_reactions:
|
||||
if r.kind in [
|
||||
@@ -232,7 +232,7 @@ async def load_reactions_by(_, _info, by, limit=50, offset=0):
|
||||
).join(
|
||||
CreatedByUser, Reaction.createdBy == CreatedByUser.id
|
||||
).join(
|
||||
ReactedShout, Reaction.shoutId == ReactedShout.id
|
||||
ReactedShout, Reaction.shout == ReactedShout.id
|
||||
)
|
||||
|
||||
if by.get("shout"):
|
||||
|
@@ -8,16 +8,16 @@ from orm import Shout, User
|
||||
|
||||
|
||||
def add_topic_stat_columns(q):
|
||||
q = q.outerjoin(ShoutTopic, Topic.id == ShoutTopic.topicId).add_columns(
|
||||
func.count(distinct(ShoutTopic.shoutId)).label('shouts_stat')
|
||||
).outerjoin(ShoutAuthor, ShoutTopic.shoutId == ShoutAuthor.shoutId).add_columns(
|
||||
func.count(distinct(ShoutAuthor.userId)).label('authors_stat')
|
||||
q = q.outerjoin(ShoutTopic, Topic.id == ShoutTopic.topic).add_columns(
|
||||
func.count(distinct(ShoutTopic.shout)).label('shouts_stat')
|
||||
).outerjoin(ShoutAuthor, ShoutTopic.shout == ShoutAuthor.shout).add_columns(
|
||||
func.count(distinct(ShoutAuthor.user)).label('authors_stat')
|
||||
).outerjoin(TopicFollower,
|
||||
and_(
|
||||
TopicFollower.topicId == Topic.id,
|
||||
TopicFollower.followerId == ShoutAuthor.id
|
||||
TopicFollower.topic == Topic.id,
|
||||
TopicFollower.follower == ShoutAuthor.id
|
||||
)).add_columns(
|
||||
func.count(distinct(TopicFollower.followerId)).label('followers_stat')
|
||||
func.count(distinct(TopicFollower.follower)).label('followers_stat')
|
||||
)
|
||||
|
||||
q = q.group_by(Topic.id)
|
||||
@@ -119,7 +119,7 @@ async def topic_follow(user, slug):
|
||||
with local_session() as session:
|
||||
topic = session.query(Topic).where(Topic.slug == slug).one()
|
||||
|
||||
following = TopicFollower.create(topicId=topic.id, followerId=user.id)
|
||||
following = TopicFollower.create(topic=topic.id, follower=user.id)
|
||||
session.add(following)
|
||||
session.commit()
|
||||
|
||||
@@ -129,7 +129,7 @@ async def topic_unfollow(user, slug):
|
||||
sub = (
|
||||
session.query(TopicFollower).join(Topic).filter(
|
||||
and_(
|
||||
TopicFollower.followerId == user.id,
|
||||
TopicFollower.follower == user.id,
|
||||
Topic.slug == slug
|
||||
)
|
||||
).first()
|
||||
@@ -145,7 +145,7 @@ async def topic_unfollow(user, slug):
|
||||
async def topics_random(_, info, amount=12):
|
||||
q = select(Topic)
|
||||
q = add_topic_stat_columns(q)
|
||||
q = q.join(Shout, ShoutTopic.shoutId == Shout.id).group_by(Topic.id).having(func.count(Shout.id) > 2)
|
||||
q = q.join(Shout, ShoutTopic.shout == Shout.id).group_by(Topic.id).having(func.count(Shout.id) > 2)
|
||||
q = q.order_by(func.random()).limit(amount)
|
||||
|
||||
return get_topics_from_query(q)
|
||||
|
Reference in New Issue
Block a user