Implement source-backed norm finder and saved price previews
This commit is contained in:
@@ -671,6 +671,37 @@ def replace_scoped_assistant(username: str, tab_id: str, message_id: int,
|
||||
return cursor.rowcount == 1
|
||||
|
||||
|
||||
def get_scoped_norm_quote(username: str, tab_id: str, quote_id: int) -> dict | None:
|
||||
"""One saved finder result, never a quote from another user or dialog."""
|
||||
import json
|
||||
|
||||
with _conn() as conn:
|
||||
row = conn.execute(
|
||||
"SELECT content FROM messages WHERE id=? AND username=? AND tab_id=? "
|
||||
"AND role='norm_quote'", (quote_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_quote(username: str, tab_id: str, quote_id: int,
|
||||
old_content: str, new_content: str) -> bool:
|
||||
"""Compare and swap one finder result in the current dialog."""
|
||||
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_quote' AND content=?",
|
||||
(new_content, quote_id, username, tab_id, old_content),
|
||||
)
|
||||
return cursor.rowcount == 1
|
||||
|
||||
|
||||
def replace_linked_estimate(username: str, tab_id: str, estimate_id: int,
|
||||
expected_revision: int, data: dict, answer: str) -> str:
|
||||
"""Compare-and-swap answer and estimate in one SQLite transaction."""
|
||||
|
||||
Reference in New Issue
Block a user