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
|
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:
|
for author in target.authors:
|
||||||
|
|
|
@ -129,4 +129,5 @@ __all__ = [
|
||||||
"publish_draft",
|
"publish_draft",
|
||||||
"publish_shout",
|
"publish_shout",
|
||||||
"unpublish_shout",
|
"unpublish_shout",
|
||||||
|
"unpublish_draft",
|
||||||
]
|
]
|
||||||
|
|
|
@ -106,7 +106,6 @@ async def update_draft(_, info, draft_input):
|
||||||
@mutation.field("delete_draft")
|
@mutation.field("delete_draft")
|
||||||
@login_required
|
@login_required
|
||||||
async def delete_draft(_, info, draft_id: int):
|
async def delete_draft(_, info, draft_id: int):
|
||||||
user_id = info.context.get("user_id")
|
|
||||||
author_dict = info.context.get("author", {})
|
author_dict = info.context.get("author", {})
|
||||||
author_id = author_dict.get("id")
|
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()
|
shout = session.query(Shout).filter(Shout.id == shout_id).first()
|
||||||
if not shout:
|
if not shout:
|
||||||
return {"error": "Shout not found"}
|
return {"error": "Shout not found"}
|
||||||
was_published = shout and shout.published_at is not None
|
was_published = shout.published_at is not None
|
||||||
draft = draft or session.query(Draft).where(Draft.id == shout.draft).first()
|
draft = session.query(Draft).where(Draft.id == shout.draft).first()
|
||||||
if not draft:
|
if not draft:
|
||||||
return {"error": "Draft not found"}
|
return {"error": "Draft not found"}
|
||||||
# Находим черновик если не передан
|
# Находим черновик если не передан
|
||||||
|
@ -207,10 +206,9 @@ async def publish_shout(_, info, shout_id: int):
|
||||||
shout.seo = draft.seo
|
shout.seo = draft.seo
|
||||||
|
|
||||||
draft.updated_at = now
|
draft.updated_at = now
|
||||||
draft.published_at = now
|
|
||||||
shout.updated_at = now
|
shout.updated_at = now
|
||||||
# Устанавливаем published_at только если это новая публикация
|
|
||||||
# или публикация была ранее снята с публикации
|
# Устанавливаем published_at только если была ранее снята с публикации
|
||||||
if not was_published:
|
if not was_published:
|
||||||
shout.published_at = now
|
shout.published_at = now
|
||||||
|
|
||||||
|
|
|
@ -651,10 +651,22 @@ def get_main_topic_slug(topics):
|
||||||
topics: List of ShoutTopic objects
|
topics: List of ShoutTopic objects
|
||||||
|
|
||||||
Returns:
|
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:
|
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)
|
# Convert to list if it's not already and reverse
|
||||||
return main_topic.topic.slug if main_topic else { "slug": "notopic", "title": "no topic", "id": 0 }
|
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:
|
try:
|
||||||
q = q.limit(limit).offset(offset)
|
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:
|
with local_session() as session:
|
||||||
shouts_result = session.execute(q).all()
|
shouts_result = session.execute(q).all()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from orm.author import Author
|
from orm.author import Author
|
||||||
from orm.community import Community
|
from orm.community import Community
|
||||||
|
@ -23,32 +23,3 @@ class CommonResult:
|
||||||
community: Optional[Community] = None
|
community: Optional[Community] = None
|
||||||
communities: Optional[List[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