Commit f8e1465ad62818b343d34a02e398b8157579c760
1 parent
70da5dd5
Exists in
master
and in
4 other branches
New projects list with total charge
calls new db_mgr accessor
Showing
3 changed files
with
25 additions
and
2 deletions
Show diff stats
app/db_mgr.py
1 | 1 | from app.models import db |
2 | 2 | |
3 | 3 | |
4 | +def projects(): | |
5 | + """ | |
6 | + Build the list of all agents, with their charges summed up in one total | |
7 | + :return: | |
8 | + """ | |
9 | + sql_txt = """ | |
10 | + select p.id, p.name, sum(tc.charge_rate) as total_charge | |
11 | + from project as p left join | |
12 | + ( select c.project_id, c.charge_rate from charge c ) | |
13 | + tc | |
14 | + on p.id = tc.project_id | |
15 | + group by p.id | |
16 | + order by total_charge desc; | |
17 | + """ | |
18 | + all_projects = db.session.execute(sql_txt).fetchall() | |
19 | + return all_projects | |
20 | + | |
4 | 21 | def agents(): |
5 | 22 | """ |
6 | 23 | Build the list of all agents, with their charges summed up in one total | ... | ... |
app/main/routes.py
... | ... | @@ -47,7 +47,7 @@ def services(): |
47 | 47 | @role_required('project') |
48 | 48 | def projects(): |
49 | 49 | # get projects list |
50 | - all_projects = Project.query.order_by(Project.name).all() | |
50 | + all_projects = db_mgr.projects() | |
51 | 51 | num_projects = len(all_projects) |
52 | 52 | # pass to template |
53 | 53 | return render_template('projects.html', subtitle="Liste des projets ({})".format(num_projects), | ... | ... |
app/main/templates/projects.html
... | ... | @@ -4,12 +4,18 @@ |
4 | 4 | <thead> |
5 | 5 | <tr> |
6 | 6 | <th scope="col">Projet</th> |
7 | + <th scope="col">Charge</th> | |
7 | 8 | </tr> |
8 | 9 | </thead> |
9 | 10 | <tbody> |
10 | 11 | {% for project in projects %} |
11 | 12 | <tr> |
12 | - <td>{{ project.name }}</td> | |
13 | + <td><a href="{{url_for('main.project', project_id=project.id)}}"> | |
14 | + {{ project.name }}</a> | |
15 | + </td> | |
16 | + <td> | |
17 | + {{ project.total_charge }}</a> | |
18 | + </td> | |
13 | 19 | </tr> |
14 | 20 | {% endfor %} |
15 | 21 | </tbody> | ... | ... |