schema-fix
All checks were successful
Deploy on push / deploy (push) Successful in 6s

This commit is contained in:
2025-06-30 22:43:32 +03:00
parent 41395eb7c6
commit ab65fd4fd8
7 changed files with 163 additions and 86 deletions

View File

@@ -59,7 +59,10 @@ async def admin_get_users(
# Вычисляем информацию о пагинации
per_page = limit
total_pages = ceil(total_count / per_page)
if total_count is None or per_page in (None, 0):
total_pages = 1
else:
total_pages = ceil(total_count / per_page)
current_page = (offset // per_page) + 1 if per_page > 0 else 1
# Применяем пагинацию
@@ -420,7 +423,10 @@ async def admin_get_shouts(
# Вычисляем информацию о пагинации
per_page = limit
total_pages = ceil(total_count / per_page)
if total_count is None or per_page in (None, 0):
total_pages = 1
else:
total_pages = ceil(total_count / per_page)
current_page = (offset // per_page) + 1 if per_page > 0 else 1
# Применяем пагинацию и сортировку (новые сверху)
@@ -430,12 +436,20 @@ async def admin_get_shouts(
if status == "all":
# Для статуса "all" используем простой запрос без статистики
q = q.limit(limit).offset(offset)
shouts_result = session.execute(q).unique().all()
shouts_result: list[Any] = session.execute(q).unique().all()
shouts_data = []
for row in shouts_result:
# Get the Shout object from the row
shout = row[0] if isinstance(row, tuple) else row.Shout if hasattr(row, "Shout") else row
if isinstance(row, tuple):
shout = row[0]
elif hasattr(row, "Shout"):
shout = row.Shout
elif isinstance(row, dict) and "id" in row:
shout = row
else:
shout = row
# Обрабатываем поле media
media_data = []
if hasattr(shout, "media") and shout.media:
@@ -452,49 +466,90 @@ async def admin_get_shouts(
media_data = [shout.media]
shout_dict = {
"id": shout.id,
"title": shout.title,
"slug": shout.slug,
"body": shout.body,
"lead": shout.lead,
"subtitle": shout.subtitle,
"layout": shout.layout,
"lang": shout.lang,
"cover": shout.cover,
"cover_caption": shout.cover_caption,
"id": getattr(shout, "id", None) if not isinstance(shout, dict) else shout.get("id"),
"title": getattr(shout, "title", None) if not isinstance(shout, dict) else shout.get("title"),
"slug": getattr(shout, "slug", None) if not isinstance(shout, dict) else shout.get("slug"),
"body": getattr(shout, "body", None) if not isinstance(shout, dict) else shout.get("body"),
"lead": getattr(shout, "lead", None) if not isinstance(shout, dict) else shout.get("lead"),
"subtitle": getattr(shout, "subtitle", None)
if not isinstance(shout, dict)
else shout.get("subtitle"),
"layout": getattr(shout, "layout", None)
if not isinstance(shout, dict)
else shout.get("layout"),
"lang": getattr(shout, "lang", None) if not isinstance(shout, dict) else shout.get("lang"),
"cover": getattr(shout, "cover", None) if not isinstance(shout, dict) else shout.get("cover"),
"cover_caption": getattr(shout, "cover_caption", None)
if not isinstance(shout, dict)
else shout.get("cover_caption"),
"media": media_data,
"seo": shout.seo,
"created_at": shout.created_at,
"updated_at": shout.updated_at,
"published_at": shout.published_at,
"featured_at": shout.featured_at,
"deleted_at": shout.deleted_at,
"seo": getattr(shout, "seo", None) if not isinstance(shout, dict) else shout.get("seo"),
"created_at": getattr(shout, "created_at", None)
if not isinstance(shout, dict)
else shout.get("created_at"),
"updated_at": getattr(shout, "updated_at", None)
if not isinstance(shout, dict)
else shout.get("updated_at"),
"published_at": getattr(shout, "published_at", None)
if not isinstance(shout, dict)
else shout.get("published_at"),
"featured_at": getattr(shout, "featured_at", None)
if not isinstance(shout, dict)
else shout.get("featured_at"),
"deleted_at": getattr(shout, "deleted_at", None)
if not isinstance(shout, dict)
else shout.get("deleted_at"),
"created_by": {
"id": shout.created_by,
"id": getattr(shout, "created_by", None)
if not isinstance(shout, dict)
else shout.get("created_by"),
"email": "unknown", # Заполним при необходимости
"name": "unknown",
},
"updated_by": None, # Заполним при необходимости
"deleted_by": None, # Заполним при необходимости
"community": {
"id": shout.community,
"id": getattr(shout, "community", None)
if not isinstance(shout, dict)
else shout.get("community"),
"name": "unknown", # Заполним при необходимости
},
"authors": [
{"id": author.id, "email": author.email, "name": author.name, "slug": author.slug}
for author in (shout.authors or [])
{
"id": getattr(author, "id", None),
"email": getattr(author, "email", None),
"name": getattr(author, "name", None),
"slug": getattr(author, "slug", None),
}
for author in (
getattr(shout, "authors", [])
if not isinstance(shout, dict)
else shout.get("authors", [])
)
],
"topics": [
{"id": topic.id, "title": topic.title, "slug": topic.slug} for topic in (shout.topics or [])
{
"id": getattr(topic, "id", None),
"title": getattr(topic, "title", None),
"slug": getattr(topic, "slug", None),
}
for topic in (
getattr(shout, "topics", []) if not isinstance(shout, dict) else shout.get("topics", [])
)
],
"version_of": shout.version_of,
"draft": shout.draft,
"version_of": getattr(shout, "version_of", None)
if not isinstance(shout, dict)
else shout.get("version_of"),
"draft": getattr(shout, "draft", None) if not isinstance(shout, dict) else shout.get("draft"),
"stat": None, # Заполним при необходимости
}
shouts_data.append(shout_dict)
else:
# Используем существующую функцию для получения публикаций со статистикой
shouts_data = get_shouts_with_links(info, q, limit, offset)
shouts_result = get_shouts_with_links(info, q, limit, offset)
shouts_data = [
s.dict() if hasattr(s, "dict") else dict(s) if hasattr(s, "_mapping") else s for s in shouts_result
]
return {
"shouts": shouts_data,
@@ -702,7 +757,10 @@ async def admin_get_invites(
# Вычисляем информацию о пагинации
per_page = limit
total_pages = ceil(total_count / per_page)
if total_count is None or per_page in (None, 0):
total_pages = 1
else:
total_pages = ceil(total_count / per_page)
current_page = (offset // per_page) + 1 if per_page > 0 else 1
# Применяем пагинацию и сортировку (по ID приглашающего, затем автора, затем публикации)

View File

@@ -143,7 +143,7 @@ async def get_authors_with_stats(
default_sort_applied = True
else:
# If order is not a stats field, treat it as a regular field
column = getattr(Author, order_value, None)
column = getattr(Author, order_value or "", "")
if column:
base_query = base_query.order_by(sql_desc(column))
logger.debug(f"Applying sorting by column: {order_value}")
@@ -153,9 +153,11 @@ async def get_authors_with_stats(
else:
# Regular sorting by fields
for field, direction in by.items():
if field is None:
continue
column = getattr(Author, field, None)
if column:
if direction.lower() == "desc":
if isinstance(direction, str) and direction.lower() == "desc":
base_query = base_query.order_by(sql_desc(column))
else:
base_query = base_query.order_by(column)

View File

@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, Optional
from graphql import GraphQLResolveInfo
@@ -211,8 +211,8 @@ async def delete_collection(_: None, info: GraphQLResolveInfo, slug: str) -> dic
@type_collection.field("created_by")
def resolve_collection_created_by(obj: Collection, *_: Any) -> Author:
"""Резолвер для поля created_by коллекции"""
def resolve_collection_created_by(obj: Collection, *_: Any) -> Optional[Author]:
"""Резолвер для поля created_by коллекции (может вернуть None)"""
with local_session() as session:
if hasattr(obj, "created_by_author") and obj.created_by_author:
return obj.created_by_author