home · contact · privacy
To Processes listing, add sortable column for number of owners.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 6 Jun 2024 04:23:57 +0000 (06:23 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 6 Jun 2024 04:23:57 +0000 (06:23 +0200)
plomtask/http.py
plomtask/processes.py
templates/processes.html

index 2b630a22376edf6f0a51c10a2de6a4fe4ae20ff6..886efa22c50a15c0384a541a701035e822c4e1ac 100644 (file)
@@ -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':
index 23da7c10f365539661fbf7cb5815f61158a6c923..8082c3cb1d412fa7aa7806735e20ee908f27c404 100644 (file)
@@ -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]:
index 42beafcdffce9458388b35f3cdbcda0bbee07224..c057890a9964ae317820cd4563277bcf31a3d89e 100644 (file)
 <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>