An aggressive revert function ; it rolls back all the documents to the revision that existed before the changeset was applied. Note this means that any edits made _after_ the given changeset will also be lost.
(changeset_ids: Iterable[int], comment: str)
| 100 | |
| 101 | |
| 102 | def revert_changesets(changeset_ids: Iterable[int], comment: str): |
| 103 | """ |
| 104 | An aggressive revert function ; it rolls back all the documents to |
| 105 | the revision that existed before the changeset was applied. |
| 106 | Note this means that any edits made _after_ the given changeset will |
| 107 | also be lost. |
| 108 | """ |
| 109 | |
| 110 | def get_doc(key: str, revision: int) -> dict: |
| 111 | if revision == 0: |
| 112 | return {"key": key, "type": {"key": "/type/delete"}} |
| 113 | else: |
| 114 | return web.ctx.site.get(key, revision).dict() |
| 115 | |
| 116 | site = web.ctx.site |
| 117 | docs = [get_doc(c["key"], c["revision"] - 1) for cid in changeset_ids for c in site.get_change(cid).changes] |
| 118 | docs = [doc for doc in docs if doc.get("type", {}).get("key") != "/type/delete"] |
| 119 | data = {"reverted_changesets": [str(cid) for cid in changeset_ids]} |
| 120 | manifest = web.ctx.site.save_many(docs, action="revert", data=data, comment=comment) |
| 121 | return manifest, len(docs) |
| 122 | |
| 123 | |
| 124 | class admin(delegate.page): |
no test coverage detected