Commit 71b91c223b43cd6865bafcf3a8db1869d9f65a1e
1 parent
1aeda847
Exists in
master
and in
4 other branches
New json route for agent charge
Showing
2 changed files
with
16 additions
and
5 deletions
Show diff stats
app/db_mgr.py
... | ... | @@ -9,7 +9,8 @@ def agents(): |
9 | 9 | def charges_by_agent(agent_id): |
10 | 10 | # all_charges = db.session.query(Charge).all() |
11 | 11 | sql_txt = "select sum(charge_rate), p.name from charge inner join period p on charge.period_id = p.id\ |
12 | - where agent_id={} group by period_id order by p.name"\ | |
13 | - .format(agent_id) | |
12 | + where agent_id={} group by period_id order by p.name" \ | |
13 | + .format(agent_id) | |
14 | 14 | request = db.session.execute(sql_txt) |
15 | - return request.fetchall() | |
15 | + all_charges = [[period, rate] for (rate, period) in request.fetchall()] | |
16 | + return all_charges | ... | ... |
app/main/routes.py
1 | -from flask import render_template | |
1 | +import json | |
2 | + | |
3 | +from flask import render_template, make_response | |
2 | 4 | |
3 | 5 | from . import bp |
4 | 6 | |
5 | 7 | from app.models import Agent, Project, Service, Capacity, Period |
8 | +from .. import db_mgr | |
6 | 9 | |
7 | 10 | |
8 | 11 | @bp.route('/') |
... | ... | @@ -59,4 +62,11 @@ def periods(): |
59 | 62 | |
60 | 63 | @bp.route('/charge/add') |
61 | 64 | def charge_add(): |
62 | - return render_template('charge.html', subtitle="Affecter un agent") | |
63 | 65 | \ No newline at end of file |
66 | + return render_template('charge.html', subtitle="Affecter un agent") | |
67 | + | |
68 | + | |
69 | +@bp.route('/charge/agent/<agent_id>') | |
70 | +def charge_user(agent_id): | |
71 | + resp = make_response(json.dumps(db_mgr.charges_by_agent(agent_id))) | |
72 | + resp.headers['Content-Type'] = 'application/json' | |
73 | + return resp | ... | ... |