From: Christian Heller <c.heller@plomlompom.de> Date: Thu, 6 Jun 2024 04:23:57 +0000 (+0200) Subject: To Processes listing, add sortable column for number of owners. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%22https:/validator.w3.org/ledger?a=commitdiff_plain;h=80e2cf170d408e7d183301ea3fba0df65ec261d5;p=plomtask To Processes listing, add sortable column for number of owners. --- diff --git a/plomtask/http.py b/plomtask/http.py index 2b630a2..886efa2 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -280,6 +280,10 @@ class TaskHandler(BaseHTTPRequestHandler): processes.sort(key=lambda p: len(p.explicit_steps)) elif sort_by == '-steps': processes.sort(key=lambda p: len(p.explicit_steps), reverse=True) + if sort_by == 'owners': + processes.sort(key=lambda p: p.n_owners or 0) + elif sort_by == '-owners': + processes.sort(key=lambda p: p.n_owners or 0, reverse=True) elif sort_by == 'effort': processes.sort(key=lambda p: p.effort.newest) elif sort_by == '-effort': diff --git a/plomtask/processes.py b/plomtask/processes.py index 23da7c1..8082c3c 100644 --- a/plomtask/processes.py +++ b/plomtask/processes.py @@ -44,11 +44,13 @@ class Process(BaseModel[int], ConditionsRelations): self.explicit_steps: list[ProcessStep] = [] self.suppressed_steps: list[ProcessStep] = [] self.calendarize = calendarize + self.n_owners: int | None = None # only set by from_table_row @classmethod def from_table_row(cls, db_conn: DatabaseConnection, row: Row | list[Any]) -> Process: """Make from DB row, with dependencies.""" + # pylint: disable=no-member process = super().from_table_row(db_conn, row) assert isinstance(process.id_, int) for name in ('title', 'description', 'effort'): @@ -58,11 +60,11 @@ class Process(BaseModel[int], ConditionsRelations): for row_ in db_conn.row_where('process_steps', 'owner', process.id_): step = ProcessStep.from_table_row(db_conn, row_) - process.explicit_steps += [step] # pylint: disable=no-member + process.explicit_steps += [step] for row_ in db_conn.row_where('process_step_suppressions', 'process', process.id_): step = ProcessStep.by_id(db_conn, row_[1]) - process.suppressed_steps += [step] # pylint: disable=no-member + process.suppressed_steps += [step] for name in ('conditions', 'blockers', 'enables', 'disables'): table = f'process_{name}' assert isinstance(process.id_, int) @@ -70,6 +72,7 @@ class Process(BaseModel[int], ConditionsRelations): 'process', process.id_): target = getattr(process, name) target += [Condition.by_id(db_conn, c_id)] + process.n_owners = len(process.used_as_step_by(db_conn)) return process def used_as_step_by(self, db_conn: DatabaseConnection) -> list[Process]: diff --git a/templates/processes.html b/templates/processes.html index 42beafc..c057890 100644 --- a/templates/processes.html +++ b/templates/processes.html @@ -11,12 +11,14 @@ <table> <tr> <th><a href="?sort_by={% if sort_by == "steps" %}-{% endif %}steps">steps</a></th> +<th><a href="?sort_by={% if sort_by == "owners" %}-{% endif %}owners">owners</a></th> <th><a href="?sort_by={% if sort_by == "effort" %}-{% endif %}effort">effort</a></th> <th><a href="?sort_by={% if sort_by == "title" %}-{% endif %}title">title</a></th> </tr> {% for process in processes %} <tr> <td>{{ process.explicit_steps|count }}</td> +<td>{{ process.n_owners }}</td> <td>{{ process.effort.newest }}</td> <td><a href="process?id={{process.id_}}">{{process.title.newest}}</a></td> </tr>