home · contact · privacy
Minor reorganization of GET handlers code.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 21 Jun 2024 21:46:25 +0000 (23:46 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 21 Jun 2024 21:46:25 +0000 (23:46 +0200)
plomtask/http.py

index 27066036b2c300e23f41f7d348e5090905c9f2f8..0f5e88e570ed7eb74ea3e17fde16da13822b488a 100644 (file)
@@ -424,8 +424,8 @@ class TaskHandler(BaseHTTPRequestHandler):
     def do_GET_conditions(self) -> dict[str, object]:
         """Show all Conditions."""
         pattern = self._params.get_str('pattern')
-        conditions = Condition.matching(self.conn, pattern)
         sort_by = self._params.get_str('sort_by')
+        conditions = Condition.matching(self.conn, pattern)
         if sort_by == 'is_active':
             conditions.sort(key=lambda c: c.is_active)
         elif sort_by == '-is_active':
@@ -462,15 +462,17 @@ class TaskHandler(BaseHTTPRequestHandler):
     @_get_item(Process)
     def do_GET_process(self, process: Process) -> dict[str, object]:
         """Show Process of ?id=."""
+        owner_ids = self._params.get_all_int('step_to')
+        owned_ids = self._params.get_all_int('has_step')
         title_64 = self._params.get_str('title_b64')
         if title_64:
             title = b64decode(title_64.encode()).decode()
             process.title.set(title)
         owners = process.used_as_step_by(self.conn)
-        for step_id in self._params.get_all_int('step_to'):
+        for step_id in owner_ids:
             owners += [Process.by_id(self.conn, step_id)]
         preset_top_step = None
-        for process_id in self._params.get_all_int('has_step'):
+        for process_id in owned_ids:
             preset_top_step = process_id
         return {'process': process, 'is_new': process.id_ is None,
                 'preset_top_step': preset_top_step,
@@ -497,8 +499,8 @@ class TaskHandler(BaseHTTPRequestHandler):
     def do_GET_processes(self) -> dict[str, object]:
         """Show all Processes."""
         pattern = self._params.get_str('pattern')
-        processes = Process.matching(self.conn, pattern)
         sort_by = self._params.get_str('sort_by')
+        processes = Process.matching(self.conn, pattern)
         if sort_by == 'steps':
             processes.sort(key=lambda p: len(p.explicit_steps))
         elif sort_by == '-steps':