This commit is contained in:
parent
fe661a5008
commit
b011c0fd48
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -160,4 +160,5 @@ views.json
|
|||
*.pem
|
||||
*.key
|
||||
*.crt
|
||||
*cache.json
|
||||
*cache.json
|
||||
.cursor
|
|
@ -19,7 +19,6 @@ from resolvers.draft import (
|
|||
unpublish_draft,
|
||||
update_draft,
|
||||
)
|
||||
|
||||
from resolvers.feed import (
|
||||
load_shouts_coauthored,
|
||||
load_shouts_discussed,
|
||||
|
|
|
@ -207,7 +207,7 @@ async def publish_shout(_, info, shout_id: int):
|
|||
|
||||
draft.updated_at = now
|
||||
shout.updated_at = now
|
||||
|
||||
|
||||
# Устанавливаем published_at только если была ранее снята с публикации
|
||||
if not was_published:
|
||||
shout.published_at = now
|
||||
|
|
|
@ -562,10 +562,7 @@ async def update_shout(_, info, shout_id: int, shout_input=None, publish=False):
|
|||
# Получаем полные данные шаута со связями
|
||||
shout_with_relations = (
|
||||
session.query(Shout)
|
||||
.options(
|
||||
joinedload(Shout.topics).joinedload(ShoutTopic.topic),
|
||||
joinedload(Shout.authors)
|
||||
)
|
||||
.options(joinedload(Shout.topics).joinedload(ShoutTopic.topic), joinedload(Shout.authors))
|
||||
.filter(Shout.id == shout_id)
|
||||
.first()
|
||||
)
|
||||
|
@ -596,7 +593,9 @@ async def update_shout(_, info, shout_id: int, shout_input=None, publish=False):
|
|||
)
|
||||
|
||||
logger.info(f"Final shout data with relations: {shout_dict}")
|
||||
logger.debug(f"Loaded topics details: {[(t.topic.slug if t.topic else 'no-topic', t.main) for t in shout_with_relations.topics]}")
|
||||
logger.debug(
|
||||
f"Loaded topics details: {[(t.topic.slug if t.topic else 'no-topic', t.main) for t in shout_with_relations.topics]}"
|
||||
)
|
||||
return {"shout": shout_dict, "error": None}
|
||||
else:
|
||||
logger.warning(f"Access denied: author #{author_id} cannot edit shout#{shout_id}")
|
||||
|
@ -652,26 +651,22 @@ def get_main_topic_json(topics):
|
|||
"""Get the main topic from a list of ShoutTopic objects."""
|
||||
if not topics:
|
||||
return None
|
||||
|
||||
|
||||
# Find first main topic in original order
|
||||
main_topic_rel = next((st for st in topics if st.main), None)
|
||||
|
||||
|
||||
if main_topic_rel and main_topic_rel.topic:
|
||||
topic_dict = {
|
||||
"slug": main_topic_rel.topic.slug,
|
||||
"title": main_topic_rel.topic.title,
|
||||
"id": main_topic_rel.topic.id
|
||||
"id": main_topic_rel.topic.id,
|
||||
}
|
||||
# Convert to JSON string to match reader.py behavior
|
||||
return json.dumps(topic_dict)
|
||||
|
||||
|
||||
# If no main found but topics exist, return first
|
||||
if topics and topics[0].topic:
|
||||
topic_dict = {
|
||||
"slug": topics[0].topic.slug,
|
||||
"title": topics[0].topic.title,
|
||||
"id": topics[0].topic.id
|
||||
}
|
||||
topic_dict = {"slug": topics[0].topic.slug, "title": topics[0].topic.title, "id": topics[0].topic.id}
|
||||
return json.dumps(topic_dict)
|
||||
|
||||
|
||||
return json.dumps({"slug": "notopic", "title": "no topic", "id": 0})
|
||||
|
|
|
@ -190,8 +190,6 @@ def get_shouts_with_links(info, q, limit=20, offset=0):
|
|||
try:
|
||||
q = q.limit(limit).offset(offset)
|
||||
|
||||
# logger.info(f"get shouts query: {q}")
|
||||
|
||||
with local_session() as session:
|
||||
shouts_result = session.execute(q).all()
|
||||
|
||||
|
@ -226,16 +224,33 @@ def get_shouts_with_links(info, q, limit=20, offset=0):
|
|||
viewed = ViewedStorage.get_shout(shout_id=shout_id) or 0
|
||||
shout_dict["stat"] = {**stat, "viewed": viewed, "commented": stat.get("comments_count", 0)}
|
||||
|
||||
if has_field(info, "main_topic") and hasattr(row, "main_topic"):
|
||||
shout_dict["main_topic"] = (
|
||||
json.loads(row.main_topic) if isinstance(row.main_topic, str) else row.main_topic
|
||||
)
|
||||
# Обработка main_topic и topics
|
||||
topics = None
|
||||
if has_field(info, "topics") and hasattr(row, "topics"):
|
||||
topics = json.loads(row.topics) if isinstance(row.topics, str) else row.topics
|
||||
shout_dict["topics"] = topics
|
||||
|
||||
if has_field(info, "main_topic"):
|
||||
main_topic = None
|
||||
if hasattr(row, "main_topic"):
|
||||
main_topic = (
|
||||
json.loads(row.main_topic) if isinstance(row.main_topic, str) else row.main_topic
|
||||
)
|
||||
|
||||
# Если main_topic не определен, берем первый топик из списка
|
||||
if not main_topic and topics and len(topics) > 0:
|
||||
main_topic = {
|
||||
"id": topics[0]["id"],
|
||||
"title": topics[0]["title"],
|
||||
"slug": topics[0]["slug"],
|
||||
"is_main": True,
|
||||
}
|
||||
shout_dict["main_topic"] = main_topic
|
||||
|
||||
if has_field(info, "authors") and hasattr(row, "authors"):
|
||||
shout_dict["authors"] = (
|
||||
json.loads(row.authors) if isinstance(row.authors, str) else row.authors
|
||||
)
|
||||
if has_field(info, "topics") and hasattr(row, "topics"):
|
||||
shout_dict["topics"] = json.loads(row.topics) if isinstance(row.topics, str) else row.topics
|
||||
|
||||
if has_field(info, "media") and shout.media:
|
||||
# Обработка поля media
|
||||
|
|
|
@ -22,4 +22,3 @@ class CommonResult:
|
|||
topics: Optional[List[Topic]] = None
|
||||
community: Optional[Community] = None
|
||||
communities: Optional[List[Community]] = None
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user