Save multi-position norm drafts and open public catalog

This commit is contained in:
anor
2026-12-04 05:54:55 +10:00
parent b062214336
commit 7ad5ac0531
10 changed files with 779 additions and 28 deletions
+31
View File
@@ -702,6 +702,37 @@ def replace_scoped_norm_quote(username: str, tab_id: str, quote_id: int,
return cursor.rowcount == 1
def get_scoped_norm_draft(username: str, tab_id: str, draft_id: int) -> dict | None:
"""Return a finder collection only to the same user and dialog."""
import json
with _conn() as conn:
row = conn.execute(
"SELECT content FROM messages WHERE id=? AND username=? AND tab_id=? "
"AND role='norm_draft'", (draft_id, username, tab_id),
).fetchone()
if row is None:
return None
try:
data = json.loads(row["content"])
except (ValueError, TypeError):
return None
return {"raw": row["content"], "data": data}
def replace_scoped_norm_draft(username: str, tab_id: str, draft_id: int,
old_content: str, new_content: str) -> bool:
"""Compare and swap one finder collection; reject concurrent edits."""
with _conn() as conn:
conn.execute("BEGIN IMMEDIATE")
cursor = conn.execute(
"UPDATE messages SET content=? WHERE id=? AND username=? AND tab_id=? "
"AND role='norm_draft' AND content=?",
(new_content, draft_id, username, tab_id, old_content),
)
return cursor.rowcount == 1
def get_linked_file_compare(username: str, tab_id: str, compare_id: int) -> dict | None:
"""Return a saved file comparison only with its answer in the same dialog."""
import json