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=."""
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."""