From 02118cc944b163f0fb1c8264c89e89b5c5b1dd9d Mon Sep 17 00:00:00 2001 From: Richard Hitier Date: Mon, 3 May 2021 16:38:13 +0200 Subject: [PATCH] Show projects category/labels in table --- app/db_mgr.py | 24 +++++++++++++++++++++--- app/main/templates/projects.html | 16 ++++++++++------ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/app/db_mgr.py b/app/db_mgr.py index 1a58398..4ccd8d1 100644 --- a/app/db_mgr.py +++ b/app/db_mgr.py @@ -1,4 +1,4 @@ -from app.models import db, Period +from app.models import db, Period, Project, Category # TODO: make this configurable, and choose another place to use it, # in 'routes.py' maybe @@ -15,7 +15,7 @@ def projects(): """ current_period_id = get_current_period() sql_txt = """ - select p.id, p.name, IFNULL(sum(tc.charge_rate), 0) as total_charge + select p.id, IFNULL(sum(tc.charge_rate), 0) as total_charge from project as p left join ( select c.project_id, c.charge_rate from charge c where c.period_id = {}) tc @@ -23,7 +23,25 @@ def projects(): group by p.id order by total_charge desc; """.format(current_period_id) - all_projects = db.session.execute(sql_txt).fetchall() + projects_charges = db.session.execute(sql_txt).fetchall() + # First row is table titles + all_projects = [["Id", "Projet"]] + # Add all categories as last table titles + for c in Category.query.all(): + all_projects[0].append(c.name) + all_projects[0].append("Charge") + # Build the table row by row + for pc in projects_charges: + p_id = pc[0] + p = Project.query.get(int(p_id)) + p_labels = p.labels + # adding 3 first columns: id, name and total charge + project_row = [p.id, p.name] + # then labels, one for each category + for pl in p_labels: + project_row.append(pl.label.name) + project_row.append(pc[1]) + all_projects.append(project_row) return all_projects diff --git a/app/main/templates/projects.html b/app/main/templates/projects.html index 92eb582..a2a37a7 100644 --- a/app/main/templates/projects.html +++ b/app/main/templates/projects.html @@ -7,17 +7,21 @@ - - + {% for c_title in projects[0][1:] %} + + {% endfor %} - {% for project in projects %} + {% for project in projects[1:] %} - - + {% for c in project[2:-1] %} + + {% endfor %} + {% endfor %} -- libgit2 0.21.2
ProjetCharge{{c_title}}
- {{ project.name }} + + {{ project[1] }} {{ project.total_charge }} % {{c}}{{ project[-1] }} %