feat(админка): экран жалоб v2
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""Жалобы v2: разбор в два клика, без потери старых NULL."""
|
||||
from __future__ import annotations
|
||||
|
||||
STATUSES = {"new", "resolved", "deferred", "ignored"}
|
||||
CATEGORIES = {"wrong_answer", "off_topic", "failure", "praise"}
|
||||
|
||||
|
||||
def listing(status: str = "", category: str = "", page: int = 1,
|
||||
per_page: int = 50) -> dict:
|
||||
import db
|
||||
status = (status or "").strip()
|
||||
category = (category or "").strip()
|
||||
page = max(1, int(page)); per_page = max(1, min(int(per_page), 200))
|
||||
where, args = [], []
|
||||
if status:
|
||||
where.append("status = ?"); args.append(status)
|
||||
if category:
|
||||
where.append("category = ?"); args.append(category)
|
||||
sql = (" WHERE " + " AND ".join(where)) if where else ""
|
||||
with db._conn() as conn:
|
||||
total = conn.execute(f"SELECT COUNT(*) AS n FROM feedback{sql}", args).fetchone()["n"]
|
||||
rows = conn.execute(
|
||||
"SELECT id, timestamp, username, tab_id, comment, answer, category, source, status "
|
||||
f"FROM feedback{sql} ORDER BY id DESC LIMIT ? OFFSET ?",
|
||||
args + [per_page, (page - 1) * per_page]).fetchall()
|
||||
return {"items": [dict(r) for r in rows], "total": total, "page": page,
|
||||
"per_page": per_page}
|
||||
|
||||
|
||||
def set_status(feedback_id: int, status: str) -> bool:
|
||||
import db
|
||||
if status not in STATUSES:
|
||||
raise ValueError("неизвестный статус")
|
||||
return db.set_feedback_status(feedback_id, status)
|
||||
Reference in New Issue
Block a user