feat: add route state and merge patches
This commit is contained in:
parent
5b206635fb
commit
3d3b031332
7 changed files with 306 additions and 63 deletions
|
|
@ -135,16 +135,20 @@ def scene(request, pk):
|
|||
if (resp := _auth(request)):
|
||||
return resp
|
||||
p = _editable(request, pk)
|
||||
# A delta, not the whole scene: {changed: {gid: annotation}, deleted: [gid]}.
|
||||
# Merging per-id means two users editing different annotations both land
|
||||
# (no clobber); same-annotation edits are last-write-wins by arrival.
|
||||
# A delta, not the whole scene. `changed` values may be whole new
|
||||
# annotations or field patches for existing annotations. Merging per
|
||||
# field lets same-annotation edits to different fields both land.
|
||||
data = json.loads(request.body or "{}")
|
||||
changed = data.get("changed") or {}
|
||||
deleted = data.get("deleted") or []
|
||||
summary = None
|
||||
if changed or deleted:
|
||||
groups = dict((p.scene or {}).get("groups", {}))
|
||||
groups.update(changed)
|
||||
for gid, patch in changed.items():
|
||||
if isinstance(patch, dict) and isinstance(groups.get(gid), dict):
|
||||
groups[gid] = {**groups[gid], **patch}
|
||||
else:
|
||||
groups[gid] = patch
|
||||
for gid in deleted:
|
||||
groups.pop(gid, None)
|
||||
merged = dict(p.scene or {}, groups=groups)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue