This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import time
|
||||
from operator import or_
|
||||
|
||||
from sqlalchemy.sql import and_
|
||||
import trafilatura
|
||||
from sqlalchemy.sql import and_
|
||||
|
||||
from cache.cache import (
|
||||
cache_author,
|
||||
@@ -104,7 +104,7 @@ async def create_draft(_, info, draft_input):
|
||||
|
||||
if "title" not in draft_input or not draft_input["title"]:
|
||||
draft_input["title"] = "" # Пустая строка вместо NULL
|
||||
|
||||
|
||||
# Проверяем slug - он должен быть или не пустым, или не передаваться вообще
|
||||
if "slug" in draft_input and (draft_input["slug"] is None or draft_input["slug"] == ""):
|
||||
# При создании черновика удаляем пустой slug из входных данных
|
||||
@@ -115,9 +115,9 @@ async def create_draft(_, info, draft_input):
|
||||
# Remove id from input if present since it's auto-generated
|
||||
if "id" in draft_input:
|
||||
del draft_input["id"]
|
||||
|
||||
|
||||
if "seo" not in draft_input and not draft_input["seo"]:
|
||||
body_teaser = draft_input.get("body", "")[:300].split('\n')[:-1].join("\n")
|
||||
body_teaser = draft_input.get("body", "")[:300].split("\n")[:-1].join("\n")
|
||||
draft_input["seo"] = draft_input.get("lead", body_teaser)
|
||||
|
||||
# Добавляем текущее время создания
|
||||
@@ -164,13 +164,13 @@ async def update_draft(_, info, draft_id: int, draft_input):
|
||||
draft = session.query(Draft).filter(Draft.id == draft_id).first()
|
||||
if not draft:
|
||||
return {"error": "Draft not found"}
|
||||
|
||||
|
||||
if "seo" not in draft_input and not draft.seo:
|
||||
body_src = draft_input["body"] if "body" in draft_input else draft.body
|
||||
body_text = trafilatura.extract(body_src)
|
||||
lead_src = draft_input["lead"] if "lead" in draft_input else draft.lead
|
||||
lead_text = trafilatura.extract(lead_src)
|
||||
body_teaser = body_text[:300].split('. ')[:-1].join(".\n")
|
||||
body_teaser = body_text[:300].split(". ")[:-1].join(".\n")
|
||||
draft_input["seo"] = lead_text or body_teaser
|
||||
|
||||
Draft.update(draft, draft_input)
|
||||
@@ -178,7 +178,7 @@ async def update_draft(_, info, draft_id: int, draft_input):
|
||||
current_time = int(time.time())
|
||||
draft.updated_at = current_time
|
||||
draft.updated_by = author_id
|
||||
|
||||
|
||||
session.commit()
|
||||
return {"draft": draft}
|
||||
|
||||
|
Reference in New Issue
Block a user