unpublish-fix7
This commit is contained in:
parent
d2a8c23076
commit
32cb810f51
|
@ -651,17 +651,55 @@ def get_main_topic(topics):
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Topics data: {[(t.slug, getattr(t, 'main', False)) for t in topics] if topics else []}"
|
f"Topics data: {[(t.slug, getattr(t, 'main', False)) for t in topics] if topics else []}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if not topics:
|
if not topics:
|
||||||
logger.warning("No topics provided to get_main_topic")
|
logger.warning("No topics provided to get_main_topic")
|
||||||
return
|
return {"id": 0, "title": "no topic", "slug": "notopic", "is_main": True}
|
||||||
|
|
||||||
|
# Проверяем, является ли topics списком объектов ShoutTopic или Topic
|
||||||
|
if hasattr(topics[0], 'topic') and topics[0].topic:
|
||||||
|
# Для ShoutTopic объектов (старый формат)
|
||||||
|
# Find first main topic in original order
|
||||||
|
main_topic_rel = next((st for st in topics if getattr(st, 'main', False)), None)
|
||||||
|
logger.debug(
|
||||||
|
f"Found main topic relation: {main_topic_rel.topic.slug if main_topic_rel and main_topic_rel.topic else None}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if main_topic_rel and main_topic_rel.topic:
|
||||||
|
result = {
|
||||||
|
"slug": main_topic_rel.topic.slug,
|
||||||
|
"title": main_topic_rel.topic.title,
|
||||||
|
"id": main_topic_rel.topic.id,
|
||||||
|
"is_main": True,
|
||||||
|
}
|
||||||
|
logger.info(f"Returning main topic: {result}")
|
||||||
|
return result
|
||||||
|
|
||||||
|
# If no main found but topics exist, return first
|
||||||
|
if topics and topics[0].topic:
|
||||||
|
logger.info(f"No main topic found, using first topic: {topics[0].topic.slug}")
|
||||||
|
result = {
|
||||||
|
"slug": topics[0].topic.slug,
|
||||||
|
"title": topics[0].topic.title,
|
||||||
|
"id": topics[0].topic.id,
|
||||||
|
"is_main": True,
|
||||||
|
}
|
||||||
|
return result
|
||||||
else:
|
else:
|
||||||
logger.info(f"Using first topic as main: {topics[0].slug}")
|
# Для Topic объектов (новый формат из selectinload)
|
||||||
return {
|
# После смены на selectinload у нас просто список Topic объектов
|
||||||
"slug": topics[0].slug,
|
if topics:
|
||||||
"title": topics[0].title,
|
logger.info(f"Using first topic as main: {topics[0].slug}")
|
||||||
"id": topics[0].id,
|
result = {
|
||||||
"is_main": True,
|
"slug": topics[0].slug,
|
||||||
}
|
"title": topics[0].title,
|
||||||
|
"id": topics[0].id,
|
||||||
|
"is_main": True,
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
|
||||||
|
logger.warning("No valid topics found, returning default")
|
||||||
|
return {"slug": "notopic", "title": "no topic", "id": 0, "is_main": True}
|
||||||
|
|
||||||
@mutation.field("unpublish_shout")
|
@mutation.field("unpublish_shout")
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -745,7 +783,9 @@ async def unpublish_shout(_, info, shout_id: int):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Добавляем main_topic
|
# Добавляем main_topic
|
||||||
shout_dict["main_topic"] = get_main_topic(shout.topics)
|
main_topic = get_main_topic(shout.topics)
|
||||||
|
if main_topic["id"]:
|
||||||
|
shout_dict["main_topic"] = main_topic
|
||||||
|
|
||||||
# Добавляем авторов
|
# Добавляем авторов
|
||||||
shout_dict["authors"] = (
|
shout_dict["authors"] = (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user