Fix editor action updates

This commit is contained in:
Your Name
2026-07-28 12:52:24 +05:00
parent 3ab8a7b4f2
commit 89adc6852d
5 changed files with 105 additions and 70 deletions
+52 -21
View File
@@ -2709,6 +2709,30 @@ async def fetch_single_editor_row(pool, post_id: int):
post_id
)
async def editor_post_update_response(
request: Request,
user: dict,
pool,
post_id: int,
action_message: str = "",
action_tone: str = "info",
):
row = await fetch_single_editor_row(pool, post_id)
if not row:
return HTMLResponse("", status_code=204)
return templates.TemplateResponse(
"editor_post_update.html",
base_context(
request,
user,
p=prepare_editor_post(row),
action_message=action_message,
action_tone=action_tone,
),
)
@app.get("/editor", response_class=HTMLResponse)
async def editor_feed(
request: Request,
@@ -2926,13 +2950,7 @@ async def editor_accept(request: Request, post_id: int, csrf_token: str = Form(.
)
await audit(user["id"], "editor.accept", "raw_post", post_id)
if request.headers.get("hx-request"):
row = await fetch_single_editor_row(pool, post_id)
if row:
categories = await writer_category_options()
return templates.TemplateResponse(
"editor_post.html",
base_context(request, user, p=prepare_editor_post(row), categories=categories)
)
return await editor_post_update_response(request, user, pool, post_id, "Принято к публикации", "success")
return redirect("/editor")
@@ -2959,13 +2977,31 @@ async def editor_reject(request: Request, post_id: int, csrf_token: str = Form(.
)
await audit(user["id"], "editor.reject", "raw_post", post_id)
if request.headers.get("hx-request"):
row = await fetch_single_editor_row(pool, post_id)
if row:
categories = await writer_category_options()
return templates.TemplateResponse(
"editor_post.html",
base_context(request, user, p=prepare_editor_post(row), categories=categories)
)
return await editor_post_update_response(request, user, pool, post_id, "Отклонено", "error")
return redirect("/editor")
@app.post("/editor/{post_id}/return")
async def editor_return_to_review(request: Request, post_id: int, csrf_token: str = Form(...)):
user = await get_current_user(request)
if not user:
return redirect("/login")
require_csrf(user, csrf_token)
pool = await get_pool()
await pool.execute(
"""
UPDATE raw_posts
SET editorial_status=NULL,
reviewed_by=NULL,
reviewed_at=NULL,
updated_at=NOW()
WHERE id=$1 AND rewrite_status='ready'
""",
post_id,
)
await audit(user["id"], "editor.return_to_review", "raw_post", post_id)
if request.headers.get("hx-request"):
return await editor_post_update_response(request, user, pool, post_id, "Возвращено на проверку", "warning")
return redirect("/editor")
@@ -3094,13 +3130,8 @@ async def editor_save(
)
await audit(user["id"], "editor.save" if status_value == "edited" else "editor.save_accept", "raw_post", post_id)
if request.headers.get("hx-request"):
row = await fetch_single_editor_row(pool, post_id)
if row:
categories = await writer_category_options()
return templates.TemplateResponse(
"editor_post.html",
base_context(request, user, p=prepare_editor_post(row), categories=categories)
)
message = "Принято к публикации" if status_value == "accepted" else "Сохранено как черновик"
return await editor_post_update_response(request, user, pool, post_id, message, "success")
return redirect("/editor")