From: Christian Heller Date: Sat, 18 May 2024 04:00:36 +0000 (+0200) Subject: Add basic sorting features to Condition, Process table views. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/%27%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28escapeHTML%28span%5B2%5D%29%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28%27?a=commitdiff_plain;h=a58f0f088ef7bed064a7752aeebb03498b692e8b;p=plomtask Add basic sorting features to Condition, Process table views. --- 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.""" diff --git a/templates/conditions.html b/templates/conditions.html index 88d1cc7..e8e9fed 100644 --- a/templates/conditions.html +++ b/templates/conditions.html @@ -5,8 +5,8 @@ - - + + {% for condition in conditions %} diff --git a/templates/processes.html b/templates/processes.html index 5cd00b5..977ac40 100644 --- a/templates/processes.html +++ b/templates/processes.html @@ -5,8 +5,8 @@
activetitleactivetitle
- - + + {% for process in processes %}
stepstitlestepstitle