This commit is contained in:
parent
91e4e751d8
commit
1c6678d55d
|
@ -249,33 +249,29 @@ def get_shouts_with_stats(q, limit=20, offset=0, author_id=None):
|
||||||
if author_id:
|
if author_id:
|
||||||
query = query.filter(Shout.created_by == author_id)
|
query = query.filter(Shout.created_by == author_id)
|
||||||
|
|
||||||
# Выполнение запроса и обработка результатов
|
|
||||||
with q.session as session:
|
|
||||||
results = session.execute(query).all()
|
|
||||||
|
|
||||||
# Формирование списка публикаций с их данными
|
# Формирование списка публикаций с их данными
|
||||||
shouts = []
|
shouts = []
|
||||||
|
with local_session() as session:
|
||||||
|
for row in session.execute(query).all() or []:
|
||||||
|
shout = row.Shout
|
||||||
|
comments_stat = row.comments_stat
|
||||||
|
rating_stat = row.rating_stat
|
||||||
|
last_reacted_at = row.last_reacted_at
|
||||||
|
authors_json = row.authors
|
||||||
|
topics_json = row.topics
|
||||||
|
main_topic_slug = row.main_topic_slug
|
||||||
|
|
||||||
for row in results:
|
# Преобразование JSON данных в объекты
|
||||||
shout = row.Shout
|
shout.authors = [Author(**author) for author in authors_json] if authors_json else []
|
||||||
comments_stat = row.comments_stat
|
shout.topics = [Topic(**topic) for topic in topics_json] if topics_json else []
|
||||||
rating_stat = row.rating_stat
|
shout.stat = {
|
||||||
last_reacted_at = row.last_reacted_at
|
"viewed": ViewedStorage.get_shout(shout.id),
|
||||||
authors_json = row.authors
|
"rating": rating_stat or 0,
|
||||||
topics_json = row.topics
|
"commented": comments_stat or 0,
|
||||||
main_topic_slug = row.main_topic_slug
|
"last_reacted_at": last_reacted_at,
|
||||||
|
}
|
||||||
# Преобразование JSON данных в объекты
|
shout.main_topic = main_topic_slug # Присваиваем основной топик
|
||||||
shout.authors = [Author(**author) for author in authors_json] if authors_json else []
|
shouts.append(shout)
|
||||||
shout.topics = [Topic(**topic) for topic in topics_json] if topics_json else []
|
|
||||||
shout.stat = {
|
|
||||||
"viewed": ViewedStorage.get_shout(shout.id),
|
|
||||||
"rating": rating_stat or 0,
|
|
||||||
"commented": comments_stat or 0,
|
|
||||||
"last_reacted_at": last_reacted_at,
|
|
||||||
}
|
|
||||||
shout.main_topic = main_topic_slug # Присваиваем основной топик
|
|
||||||
shouts.append(shout)
|
|
||||||
|
|
||||||
return shouts
|
return shouts
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user