Save multi-position norm drafts and open public catalog
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user