Commit 40126f91dd9eaf926616322b12c068b27aca2af5

Authored by hitier
1 parent a53e2fff

Update project routes and templates with models

with latest db export methods updates.
@@ -10,7 +10,13 @@ charge_unit = 100 @@ -10,7 +10,13 @@ charge_unit = 100
10 10
11 def projects(): 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 :return: 20 :return:
15 """ 21 """
16 current_period_id = get_current_period() 22 current_period_id = get_current_period()
@@ -26,21 +32,26 @@ def projects(): @@ -26,21 +32,26 @@ def projects():
26 projects_charges = db.session.execute(sql_txt).fetchall() 32 projects_charges = db.session.execute(sql_txt).fetchall()
27 # First row is table titles 33 # First row is table titles
28 all_projects = [["Id", "Projet"]] 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 all_projects[0].append(c.name) 39 all_projects[0].append(c.name)
  40 + # the add charge title to become [["Id", "Projet", "Domaine", "Pôle", "Charge"]]
32 all_projects[0].append("Charge") 41 all_projects[0].append("Charge")
33 # Build the table row by row 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 p = Project.query.get(int(p_id)) 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 project_row = [p.id, p.name] 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 all_projects.append(project_row) 55 all_projects.append(project_row)
45 return all_projects 56 return all_projects
46 57
app/main/routes.py
@@ -91,7 +91,7 @@ def project(project_id): @@ -91,7 +91,7 @@ def project(project_id):
91 this_project = Project.query.get(int(project_id)) 91 this_project = Project.query.get(int(project_id))
92 charges_table = db_mgr.charges_by_project(project_id) 92 charges_table = db_mgr.charges_by_project(project_id)
93 return render_template('project.html', 93 return render_template('project.html',
94 - project=this_project, 94 + project=this_project.to_struct(),
95 charges=charges_table, 95 charges=charges_table,
96 subtitle="{}".format(this_project.name)) 96 subtitle="{}".format(this_project.name))
97 97
app/main/templates/project.html
@@ -15,10 +15,10 @@ @@ -15,10 +15,10 @@
15 <div class="card-body"> 15 <div class="card-body">
16 <dl class="row"> 16 <dl class="row">
17 <dt class="col-sm-2 text-right">ID :</dt> 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 {% endfor %} 22 {% endfor %}
23 <dt class="col-sm-2 text-right">Etat :</dt> 23 <dt class="col-sm-2 text-right">Etat :</dt>
24 <dd class="col-sm-10 text-left"></dd> 24 <dd class="col-sm-10 text-left"></dd>
app/main/templates/projects.html
@@ -18,8 +18,9 @@ @@ -18,8 +18,9 @@
18 <td><a href="{{url_for('main.project', project_id=project[0])}}"> 18 <td><a href="{{url_for('main.project', project_id=project[0])}}">
19 {{ project[1] }}</a> 19 {{ project[1] }}</a>
20 </td> 20 </td>
  21 + {#the category cells#}
21 {% for c in project[2:-1] %} 22 {% for c in project[2:-1] %}
22 - <td>{{c}}</td> 23 + <td>{{c|join(',')}}</td>
23 {% endfor %} 24 {% endfor %}
24 <td>{{ project[-1] /100}}</td> 25 <td>{{ project[-1] /100}}</td>
25 </tr> 26 </tr>