Merge branch 'main' of https://github.com/Discours/discours-backend
This commit is contained in:
commit
6dfec6714a
|
@ -37,11 +37,12 @@ def migrate(entry):
|
|||
slug = re.sub('[^0-9a-zA-Z]+', '-', slug).strip()
|
||||
user_dict["slug"] = slug
|
||||
bio = (entry.get("profile", {"bio": ""}).get("bio") or "").replace('\(', '(').replace('\)', ')')
|
||||
bio_html = BeautifulSoup(bio, features="lxml").text
|
||||
if bio == bio_html:
|
||||
user_dict["bio"] = bio
|
||||
bio_text = BeautifulSoup(bio, features="lxml").text
|
||||
|
||||
if len(bio_text) > 120:
|
||||
user_dict["about"] = bio_text
|
||||
else:
|
||||
user_dict["about"] = bio
|
||||
user_dict["bio"] = bio_text
|
||||
|
||||
# userpic
|
||||
try:
|
||||
|
|
|
@ -60,6 +60,8 @@ def apply_filters(q, filters, user_id=None):
|
|||
|
||||
if filters.get("layout"):
|
||||
q = q.filter(Shout.layout == filters.get("layout"))
|
||||
if filters.get('excludeLayout'):
|
||||
q = q.filter(Shout.layout != filters.get("excludeLayout"))
|
||||
if filters.get("author"):
|
||||
q = q.filter(Shout.authors.any(slug=filters.get("author")))
|
||||
if filters.get("topic"):
|
||||
|
@ -123,6 +125,7 @@ async def load_shouts_by(_, info, options):
|
|||
:param options: {
|
||||
filters: {
|
||||
layout: 'audio',
|
||||
excludeLayout: 'article',
|
||||
visibility: "public",
|
||||
author: 'discours',
|
||||
topic: 'culture',
|
||||
|
@ -143,7 +146,10 @@ async def load_shouts_by(_, info, options):
|
|||
joinedload(Shout.authors),
|
||||
joinedload(Shout.topics),
|
||||
).where(
|
||||
Shout.deletedAt.is_(None)
|
||||
and_(
|
||||
Shout.deletedAt.is_(None),
|
||||
Shout.layout.is_not(None)
|
||||
)
|
||||
)
|
||||
|
||||
q = add_stat_columns(q)
|
||||
|
|
|
@ -17,11 +17,10 @@ from resolvers.inbox.unread import get_total_unread_counter
|
|||
from resolvers.zine.topics import followed_by_user
|
||||
|
||||
|
||||
def add_author_stat_columns(q):
|
||||
def add_author_stat_columns(q, include_heavy_stat=False):
|
||||
author_followers = aliased(AuthorFollower)
|
||||
author_following = aliased(AuthorFollower)
|
||||
shout_author_aliased = aliased(ShoutAuthor)
|
||||
# user_rating_aliased = aliased(UserRating)
|
||||
|
||||
q = q.outerjoin(shout_author_aliased).add_columns(
|
||||
func.count(distinct(shout_author_aliased.shout)).label('shouts_stat')
|
||||
|
@ -34,17 +33,26 @@ def add_author_stat_columns(q):
|
|||
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.user == User.id).add_columns(
|
||||
# # TODO: check
|
||||
# func.sum(user_rating_aliased.value).label('rating_stat')
|
||||
# )
|
||||
if include_heavy_stat:
|
||||
user_rating_aliased = aliased(UserRating)
|
||||
q = q.outerjoin(user_rating_aliased, user_rating_aliased.user == User.id).add_columns(
|
||||
func.sum(user_rating_aliased.value).label('rating_stat')
|
||||
)
|
||||
|
||||
q = q.add_columns(literal(0).label('commented_stat'))
|
||||
# q = q.outerjoin(Reaction, and_(Reaction.createdBy == User.id, Reaction.body.is_not(None))).add_columns(
|
||||
# func.count(distinct(Reaction.id)).label('commented_stat')
|
||||
# )
|
||||
else:
|
||||
q = q.add_columns(literal(-1).label('rating_stat'))
|
||||
|
||||
if include_heavy_stat:
|
||||
q = q.outerjoin(
|
||||
Reaction,
|
||||
and_(
|
||||
Reaction.createdBy == User.id,
|
||||
Reaction.body.is_not(None)
|
||||
)).add_columns(
|
||||
func.count(distinct(Reaction.id)).label('commented_stat')
|
||||
)
|
||||
else:
|
||||
q = q.add_columns(literal(-1).label('commented_stat'))
|
||||
|
||||
q = q.group_by(User.id)
|
||||
|
||||
|
@ -101,6 +109,7 @@ async def followed_reactions(user_id):
|
|||
Reaction.createdAt > user.lastSeen
|
||||
).all()
|
||||
|
||||
|
||||
# dufok mod (^*^') :
|
||||
@query.field("userFollowedTopics")
|
||||
async def get_followed_topics(_, info, slug) -> List[Topic]:
|
||||
|
@ -117,6 +126,7 @@ async def get_followed_topics(_, info, slug) -> List[Topic]:
|
|||
async def followed_topics(user_id):
|
||||
return followed_by_user(user_id)
|
||||
|
||||
|
||||
# dufok mod (^*^') :
|
||||
@query.field("userFollowedAuthors")
|
||||
async def get_followed_authors(_, _info, slug) -> List[User]:
|
||||
|
@ -256,7 +266,7 @@ async def get_authors_all(_, _info):
|
|||
@query.field("getAuthor")
|
||||
async def get_author(_, _info, slug):
|
||||
q = select(User).where(User.slug == slug)
|
||||
q = add_author_stat_columns(q)
|
||||
q = add_author_stat_columns(q, True)
|
||||
|
||||
authors = get_authors_from_query(q)
|
||||
return authors[0]
|
||||
|
|
|
@ -56,6 +56,7 @@ type Author {
|
|||
stat: AuthorStat
|
||||
roles: [Role] # in different communities
|
||||
lastSeen: DateTime
|
||||
createdAt: DateTime
|
||||
}
|
||||
|
||||
type Result {
|
||||
|
@ -217,26 +218,13 @@ input AuthorsBy {
|
|||
stat: String
|
||||
}
|
||||
|
||||
input ShoutsFilterBy {
|
||||
slug: String
|
||||
title: String
|
||||
body: String
|
||||
topic: String
|
||||
topics: [String]
|
||||
author: String
|
||||
authors: [String]
|
||||
layout: String
|
||||
visibility: String
|
||||
days: Int
|
||||
stat: String
|
||||
}
|
||||
|
||||
input LoadShoutsFilters {
|
||||
title: String
|
||||
body: String
|
||||
topic: String
|
||||
author: String
|
||||
layout: String
|
||||
excludeLayout: String
|
||||
visibility: String
|
||||
days: Int
|
||||
reacted: Boolean
|
||||
|
|
Loading…
Reference in New Issue
Block a user