diff --git a/app/db_mgr.py b/app/db_mgr.py index 4ccd8d1..e131c24 100644 --- a/app/db_mgr.py +++ b/app/db_mgr.py @@ -10,7 +10,13 @@ charge_unit = 100 def projects(): """ - Build the list of all agents, with their charges for the current period + Build the list of all projects, with their charges for the current period + + Returns a table with headers in the first line: + Id, Project name, Category_1, ... , Category_n, Total_Charge_for_the_period + + The category cells embed the list of the labels of the project for that category. + :return: """ current_period_id = get_current_period() @@ -26,21 +32,26 @@ def projects(): 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(): + # Add all categories as next table titles + # will then look like [["Id", "Projet", "Domaine", "Pôle"]] + categories = Category.query.all() + for c in categories: all_projects[0].append(c.name) + # the add charge title to become [["Id", "Projet", "Domaine", "Pôle", "Charge"]] all_projects[0].append("Charge") # Build the table row by row - for pc in projects_charges: - p_id = pc[0] + 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 + # adding 2 first columns: id, name 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]) + # then labels, many for each category + for category in categories: + # we build the labels.name list of the intersection of that category labels with projects labels + labels = [_cl.label.name for _cl in category.labels if _cl.label in [_pl.label for _pl in p.labels]] + project_row.append(labels) + # then add total charge + project_row.append(_pc[1]) all_projects.append(project_row) return all_projects diff --git a/app/main/routes.py b/app/main/routes.py index 1431089..4e57fdc 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -91,7 +91,7 @@ def project(project_id): this_project = Project.query.get(int(project_id)) charges_table = db_mgr.charges_by_project(project_id) return render_template('project.html', - project=this_project, + project=this_project.to_struct(), charges=charges_table, subtitle="{}".format(this_project.name)) diff --git a/app/main/templates/project.html b/app/main/templates/project.html index 563ce03..a1edf1b 100644 --- a/app/main/templates/project.html +++ b/app/main/templates/project.html @@ -15,10 +15,10 @@
ID :
-
{{project.id}}
- {% for pl in project.labels %} -
{{pl.label.category.name}} :
-
{{pl.label.name}}
+
{{project['id']}}
+ {% for category, labels in project['labels'].items() %} +
{{category}} :
+
{{labels|join(",")}}
{% endfor %}
Etat :
diff --git a/app/main/templates/projects.html b/app/main/templates/projects.html index 34792b8..2fc7c9e 100644 --- a/app/main/templates/projects.html +++ b/app/main/templates/projects.html @@ -18,8 +18,9 @@ {{ project[1] }} + {#the category cells#} {% for c in project[2:-1] %} - {{c}} + {{c|join(',')}} {% endfor %} {{ project[-1] /100}} -- libgit2 0.21.2