feat: tasks-card-inline — toggle fix (reload), /api/tasks/reload, /api/tasks/new-form, update_task, /api/task/{uid}/update. fix: radicale update_task
This commit is contained in:
@@ -146,6 +146,57 @@ def toggle_task(uid: str) -> dict:
|
||||
return {"error": str(e)}
|
||||
|
||||
|
||||
def update_task(uid: str, summary: str, due_str: str = "") -> dict:
|
||||
"""Обновить SUMMARY и/или DUE VTODO."""
|
||||
url = f"{RADICALE_BASE}/{RADICALE_USER}/%D0%97%D0%B0%D0%B4%D0%B0%D1%87%D0%B8/{uid}.ics"
|
||||
try:
|
||||
with httpx.Client(auth=(RADICALE_USER, _password()), timeout=5.0) as c:
|
||||
r = c.get(url)
|
||||
if r.status_code == 404:
|
||||
return {"error": "Task not found"}
|
||||
r.raise_for_status()
|
||||
body = r.text
|
||||
old_etag = r.headers.get("etag", "").strip()
|
||||
# меняем SUMMARY
|
||||
new_body_lines = []
|
||||
for line in body.splitlines():
|
||||
if line.startswith("SUMMARY:"):
|
||||
new_body_lines.append(f"SUMMARY:{summary}")
|
||||
elif line.startswith("DUE:") and due_str:
|
||||
from datetime import datetime
|
||||
try:
|
||||
dt = datetime.strptime(due_str, "%Y-%m-%d").strftime("%Y%m%dT235959Z")
|
||||
new_body_lines.append(f"DUE:{dt}")
|
||||
except ValueError:
|
||||
new_body_lines.append(line)
|
||||
else:
|
||||
new_body_lines.append(line)
|
||||
# если due_str задан но DUE нет — добавить перед END:VTODO
|
||||
if due_str:
|
||||
try:
|
||||
from datetime import datetime
|
||||
dt = datetime.strptime(due_str, "%Y-%m-%d").strftime("%Y%m%dT235959Z")
|
||||
has_due = any(ln.startswith("DUE:") for ln in new_body_lines)
|
||||
if not has_due:
|
||||
for i, ln in enumerate(new_body_lines):
|
||||
if ln.strip() == "END:VTODO":
|
||||
new_body_lines.insert(i, f"DUE:{dt}")
|
||||
break
|
||||
except ValueError:
|
||||
pass
|
||||
new_body = "\r\n".join(new_body_lines)
|
||||
put_r = c.put(url, content=new_body,
|
||||
headers={"Content-Type": "text/calendar", "If-Match": old_etag})
|
||||
if put_r.status_code == 412:
|
||||
_CACHE.pop("Задачи:VTODO", None)
|
||||
return {"error": "conflict", "note": "etag mismatch; reload page"}
|
||||
put_r.raise_for_status()
|
||||
_CACHE.pop("Задачи:VTODO", None)
|
||||
return {"ok": True}
|
||||
except Exception as e:
|
||||
return {"error": str(e)}
|
||||
|
||||
|
||||
def _parse_vtodo(data: str, etag: str) -> dict[str, Any]:
|
||||
props: dict[str, str] = {}
|
||||
for line in data.splitlines():
|
||||
|
||||
Reference in New Issue
Block a user