Files
tsumugu/backend/app/order.py
T
LarsandCursor 52bda91aad
Deploy Development / deploy (push) Successful in 22s
Test Suite / pytest-backend (push) Successful in 51s
Test Suite / smoke-dev (push) Successful in 1s
Test Suite / frontend-build (push) Successful in 6s
Ordne Akten und Vorgaenge nach fachlichem Datum oder eigener Reihenfolge und mache den Inhalt zur Arbeitsansicht.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-17 09:36:48 +02:00

26 lines
1.2 KiB
Python

"""Display order for bindings. Stored positions stay intact when sorting by date."""
from __future__ import annotations
def arrange(items: list[dict], mode: str, direction: str) -> list[dict]:
"""Return a new list. Undated entries stay last in both date directions."""
if mode == "position":
ordered = sorted(items, key=lambda item: (item["_raw_position"], item["id"]))
else:
dated = [item for item in items if item.get("_document_on")]
undated = [item for item in items if not item.get("_document_on")]
if direction == "desc":
dated.sort(key=lambda item: (item["_raw_position"], item["id"]))
dated.sort(key=lambda item: item["_document_on"], reverse=True)
else:
dated.sort(key=lambda item: (item["_document_on"], item["_raw_position"], item["id"]))
undated.sort(key=lambda item: (item["_raw_position"], item["id"]))
ordered = dated + undated
result = []
for index, item in enumerate(ordered):
visible = {key: value for key, value in item.items() if not key.startswith("_")}
visible["position"] = index
result.append(visible)
return result