X-Git-Url: https://plomlompom.com/repos/feed.xml?a=blobdiff_plain;f=plomtask%2Fhttp.py;fp=plomtask%2Fhttp.py;h=c16fddd0e0926f4c97454f0e755c9e3b17319513;hb=a58f0f088ef7bed064a7752aeebb03498b692e8b;hp=d5da1d7e4d914a17b2a27a67e80db762e83f8403;hpb=ce9b74158c87750ccf1c8f363a59c0465e4b1277;p=plomtask diff --git a/plomtask/http.py b/plomtask/http.py index d5da1d7..c16fddd 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -147,7 +147,17 @@ class TaskHandler(BaseHTTPRequestHandler): def do_GET_conditions(self) -> dict[str, object]: """Show all Conditions.""" - return {'conditions': Condition.all(self.conn)} + conditions = Condition.all(self.conn) + sort_by = self.params.get_str('sort_by') + if sort_by == 'is_active': + conditions.sort(key=lambda c: c.is_active) + elif sort_by == '-is_active': + conditions.sort(key=lambda c: c.is_active, reverse=True) + elif sort_by == '-title': + conditions.sort(key=lambda c: c.title.newest, reverse=True) + else: + conditions.sort(key=lambda c: c.title.newest) + return {'conditions': conditions, 'sort_by': sort_by} def do_GET_condition(self) -> dict[str, object]: """Show Condition of ?id=.""" @@ -196,7 +206,17 @@ class TaskHandler(BaseHTTPRequestHandler): def do_GET_processes(self) -> dict[str, object]: """Show all Processes.""" - return {'processes': Process.all(self.conn)} + processes = Process.all(self.conn) + sort_by = self.params.get_str('sort_by') + if sort_by == 'steps': + processes.sort(key=lambda c: len(c.explicit_steps)) + elif sort_by == '-steps': + processes.sort(key=lambda c: len(c.explicit_steps), reverse=True) + elif sort_by == '-title': + processes.sort(key=lambda c: c.title.newest, reverse=True) + else: + processes.sort(key=lambda c: c.title.newest) + return {'processes': processes, 'sort_by': sort_by} def do_POST(self) -> None: """Handle any POST request."""