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 @@
Projet | -Charge | + {% for c_title in projects[0][1:] %} +{{c_title}} | + {% endfor %}||
---|---|---|---|---|
- {{ project.name }} + | + {{ project[1] }} | -{{ project.total_charge }} % | + {% for c in project[2:-1] %} +{{c}} | + {% endfor %} +{{ project[-1] }} % |