Commit 40126f91dd9eaf926616322b12c068b27aca2af5
1 parent
a53e2fff
Exists in
master
and in
4 other branches
Update project routes and templates with models
with latest db export methods updates.
Showing
4 changed files
with
29 additions
and
17 deletions
Show diff stats
app/db_mgr.py
... | ... | @@ -10,7 +10,13 @@ charge_unit = 100 |
10 | 10 | |
11 | 11 | def projects(): |
12 | 12 | """ |
13 | - Build the list of all agents, with their charges for the current period | |
13 | + Build the list of all projects, with their charges for the current period | |
14 | + | |
15 | + Returns a table with headers in the first line: | |
16 | + Id, Project name, Category_1, ... , Category_n, Total_Charge_for_the_period | |
17 | + | |
18 | + The category cells embed the list of the labels of the project for that category. | |
19 | + | |
14 | 20 | :return: |
15 | 21 | """ |
16 | 22 | current_period_id = get_current_period() |
... | ... | @@ -26,21 +32,26 @@ def projects(): |
26 | 32 | projects_charges = db.session.execute(sql_txt).fetchall() |
27 | 33 | # First row is table titles |
28 | 34 | all_projects = [["Id", "Projet"]] |
29 | - # Add all categories as last table titles | |
30 | - for c in Category.query.all(): | |
35 | + # Add all categories as next table titles | |
36 | + # will then look like [["Id", "Projet", "Domaine", "Pôle"]] | |
37 | + categories = Category.query.all() | |
38 | + for c in categories: | |
31 | 39 | all_projects[0].append(c.name) |
40 | + # the add charge title to become [["Id", "Projet", "Domaine", "Pôle", "Charge"]] | |
32 | 41 | all_projects[0].append("Charge") |
33 | 42 | # Build the table row by row |
34 | - for pc in projects_charges: | |
35 | - p_id = pc[0] | |
43 | + for _pc in projects_charges: | |
44 | + p_id = _pc[0] | |
36 | 45 | p = Project.query.get(int(p_id)) |
37 | - p_labels = p.labels | |
38 | - # adding 3 first columns: id, name and total charge | |
46 | + # adding 2 first columns: id, name | |
39 | 47 | project_row = [p.id, p.name] |
40 | - # then labels, one for each category | |
41 | - for pl in p_labels: | |
42 | - project_row.append(pl.label.name) | |
43 | - project_row.append(pc[1]) | |
48 | + # then labels, many for each category | |
49 | + for category in categories: | |
50 | + # we build the labels.name list of the intersection of that category labels with projects labels | |
51 | + labels = [_cl.label.name for _cl in category.labels if _cl.label in [_pl.label for _pl in p.labels]] | |
52 | + project_row.append(labels) | |
53 | + # then add total charge | |
54 | + project_row.append(_pc[1]) | |
44 | 55 | all_projects.append(project_row) |
45 | 56 | return all_projects |
46 | 57 | ... | ... |
app/main/routes.py
... | ... | @@ -91,7 +91,7 @@ def project(project_id): |
91 | 91 | this_project = Project.query.get(int(project_id)) |
92 | 92 | charges_table = db_mgr.charges_by_project(project_id) |
93 | 93 | return render_template('project.html', |
94 | - project=this_project, | |
94 | + project=this_project.to_struct(), | |
95 | 95 | charges=charges_table, |
96 | 96 | subtitle="{}".format(this_project.name)) |
97 | 97 | ... | ... |
app/main/templates/project.html
... | ... | @@ -15,10 +15,10 @@ |
15 | 15 | <div class="card-body"> |
16 | 16 | <dl class="row"> |
17 | 17 | <dt class="col-sm-2 text-right">ID :</dt> |
18 | - <dd class="col-sm-10 text-left">{{project.id}}</dd> | |
19 | - {% for pl in project.labels %} | |
20 | - <dt class="col-sm-2 text-right">{{pl.label.category.name}} :</dt> | |
21 | - <dd class="col-sm-10 text-left">{{pl.label.name}}</dd> | |
18 | + <dd class="col-sm-10 text-left">{{project['id']}}</dd> | |
19 | + {% for category, labels in project['labels'].items() %} | |
20 | + <dt class="col-sm-2 text-right">{{category}} :</dt> | |
21 | + <dd class="col-sm-10 text-left">{{labels|join(",")}}</dd> | |
22 | 22 | {% endfor %} |
23 | 23 | <dt class="col-sm-2 text-right">Etat :</dt> |
24 | 24 | <dd class="col-sm-10 text-left"></dd> | ... | ... |
app/main/templates/projects.html
... | ... | @@ -18,8 +18,9 @@ |
18 | 18 | <td><a href="{{url_for('main.project', project_id=project[0])}}"> |
19 | 19 | {{ project[1] }}</a> |
20 | 20 | </td> |
21 | + {#the category cells#} | |
21 | 22 | {% for c in project[2:-1] %} |
22 | - <td>{{c}}</td> | |
23 | + <td>{{c|join(',')}}</td> | |
23 | 24 | {% endfor %} |
24 | 25 | <td>{{ project[-1] /100}}</td> |
25 | 26 | </tr> | ... | ... |