This commit is contained in:
parent
52b608da99
commit
1585e55342
2
cache/triggers.py
vendored
2
cache/triggers.py
vendored
|
@ -50,7 +50,7 @@ def after_shout_handler(mapper, connection, target):
|
|||
return
|
||||
|
||||
# Проверяем изменение статуса публикации
|
||||
was_published = target.published_at is not None and target.deleted_at is None
|
||||
# was_published = target.published_at is not None and target.deleted_at is None
|
||||
|
||||
# Всегда обновляем счетчики для авторов и тем при любом изменении поста
|
||||
for author in target.authors:
|
||||
|
|
|
@ -129,4 +129,5 @@ __all__ = [
|
|||
"publish_draft",
|
||||
"publish_shout",
|
||||
"unpublish_shout",
|
||||
"unpublish_draft",
|
||||
]
|
||||
|
|
|
@ -106,7 +106,6 @@ async def update_draft(_, info, draft_input):
|
|||
@mutation.field("delete_draft")
|
||||
@login_required
|
||||
async def delete_draft(_, info, draft_id: int):
|
||||
user_id = info.context.get("user_id")
|
||||
author_dict = info.context.get("author", {})
|
||||
author_id = author_dict.get("id")
|
||||
|
||||
|
@ -182,8 +181,8 @@ async def publish_shout(_, info, shout_id: int):
|
|||
shout = session.query(Shout).filter(Shout.id == shout_id).first()
|
||||
if not shout:
|
||||
return {"error": "Shout not found"}
|
||||
was_published = shout and shout.published_at is not None
|
||||
draft = draft or session.query(Draft).where(Draft.id == shout.draft).first()
|
||||
was_published = shout.published_at is not None
|
||||
draft = session.query(Draft).where(Draft.id == shout.draft).first()
|
||||
if not draft:
|
||||
return {"error": "Draft not found"}
|
||||
# Находим черновик если не передан
|
||||
|
@ -207,10 +206,9 @@ async def publish_shout(_, info, shout_id: int):
|
|||
shout.seo = draft.seo
|
||||
|
||||
draft.updated_at = now
|
||||
draft.published_at = now
|
||||
shout.updated_at = now
|
||||
# Устанавливаем published_at только если это новая публикация
|
||||
# или публикация была ранее снята с публикации
|
||||
|
||||
# Устанавливаем published_at только если была ранее снята с публикации
|
||||
if not was_published:
|
||||
shout.published_at = now
|
||||
|
||||
|
|
|
@ -651,10 +651,22 @@ def get_main_topic_slug(topics):
|
|||
topics: List of ShoutTopic objects
|
||||
|
||||
Returns:
|
||||
str: Slug of the main topic, or None if no main topic found
|
||||
dict: Topic dictionary with slug, title and id
|
||||
"""
|
||||
if not topics:
|
||||
return None
|
||||
return {"slug": "notopic", "title": "no topic", "id": 0}
|
||||
|
||||
main_topic = next((t for t in topics.reverse() if t.main), None)
|
||||
return main_topic.topic.slug if main_topic else { "slug": "notopic", "title": "no topic", "id": 0 }
|
||||
# Convert to list if it's not already and reverse
|
||||
topics_list = list(topics)
|
||||
topics_list.reverse()
|
||||
|
||||
main_topic = next((t for t in topics_list if t.main), None)
|
||||
if main_topic:
|
||||
return {
|
||||
"slug": main_topic.topic.slug,
|
||||
"title": main_topic.topic.title,
|
||||
"id": main_topic.topic.id
|
||||
}
|
||||
|
||||
# If no main topic found, return default
|
||||
return {"slug": "notopic", "title": "no topic", "id": 0}
|
||||
|
|
|
@ -191,7 +191,7 @@ 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}")
|
||||
# logger.info(f"get shouts query: {q}")
|
||||
|
||||
with local_session() as session:
|
||||
shouts_result = session.execute(q).all()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from dataclasses import dataclass
|
||||
from typing import Any, Dict, List, Optional
|
||||
from typing import List, Optional
|
||||
|
||||
from orm.author import Author
|
||||
from orm.community import Community
|
||||
|
@ -23,32 +23,3 @@ class CommonResult:
|
|||
community: Optional[Community] = None
|
||||
communities: Optional[List[Community]] = None
|
||||
|
||||
@classmethod
|
||||
def ok(cls, data: Dict[str, Any]) -> "CommonResult":
|
||||
"""
|
||||
Создает успешный результат.
|
||||
|
||||
Args:
|
||||
data: Словарь с данными для включения в результат.
|
||||
|
||||
Returns:
|
||||
CommonResult: Экземпляр с предоставленными данными.
|
||||
"""
|
||||
result = cls()
|
||||
for key, value in data.items():
|
||||
if hasattr(result, key):
|
||||
setattr(result, key, value)
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def error(cls, message: str):
|
||||
"""
|
||||
Create an error result.
|
||||
|
||||
Args:
|
||||
message: The error message.
|
||||
|
||||
Returns:
|
||||
CommonResult: An instance with the error message.
|
||||
"""
|
||||
return cls(error=message)
|
||||
|
|
Loading…
Reference in New Issue
Block a user