annals.bulk#
Bulk actions: one action over a selection of items, in one request.
Every single-item action on a document has a batch form here (anything done to one item can
be done to a selection), so the page sends one request per
action and gets one answer, never N requests and N toasts. Each function answers
{"done": [...], "refused": [{"id" or "key", "why"}]}: an item that cannot take the
action is refused with a reason and the rest go ahead, and done says what actually
changed, which is exactly what an Undo takes back.
edit_tags(): add and remove tags, per item, atomically (opsmay differ per item, so an Undo can take back only what each item gained or lost).trash()andrestore(): move to and from the recycle bin (each the other’s Undo); one already where it was asked to go is listed inalready, notdone.purge(): delete forever, only what is already in the bin. Irreversible: the page asks first (with the count; typed above a threshold).
A selection larger than max_items is refused whole (ValueError): the page says so
rather than starting a request that could time out half way.
>>> from annals.store import DocStore
>>> import tempfile
>>> store = DocStore(tempfile.mkdtemp())
>>> a = store.publish(text="# A", title="A", filename="a.md")["id"]
>>> trash(store, [a, "nope"])["refused"]
[{'id': 'nope', 'why': 'no such document'}]
>>> restore(store, [a])["done"] == [a]
True
Functions
|
Apply |
|
Delete each document forever, only those in the bin (the ids the person confirmed, never "everything in the bin now": one binned since from another tab survives). |
|
Bring each document back from the recycle bin (already out counts as done). |
|
Move each document to the recycle bin (already there counts as done). |
- annals.bulk.edit_tags(catalog, ops, *, max_items=500)[source]#
Apply
[{"key", "add": [...], "remove": [...]}, ...], each item on its own, in one write of the tag store.donelists{"key", "added", "removed", "tags"}for each item that changed or was already as asked;refusednames the rest (no such item, an invalid tag).- Return type:
- annals.bulk.purge(store, catalog, ids, *, max_items=500)[source]#
Delete each document forever, only those in the bin (the ids the person confirmed, never “everything in the bin now”: one binned since from another tab survives).
- Return type: