diff --git a/app/db_mgr.py b/app/db_mgr.py index a3bfa2c..28a6812 100644 --- a/app/db_mgr.py +++ b/app/db_mgr.py @@ -9,7 +9,8 @@ def agents(): def charges_by_agent(agent_id): # all_charges = db.session.query(Charge).all() sql_txt = "select sum(charge_rate), p.name from charge inner join period p on charge.period_id = p.id\ - where agent_id={} group by period_id order by p.name"\ - .format(agent_id) + where agent_id={} group by period_id order by p.name" \ + .format(agent_id) request = db.session.execute(sql_txt) - return request.fetchall() + all_charges = [[period, rate] for (rate, period) in request.fetchall()] + return all_charges diff --git a/app/main/routes.py b/app/main/routes.py index 7f15c40..d2d8f74 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -1,8 +1,11 @@ -from flask import render_template +import json + +from flask import render_template, make_response from . import bp from app.models import Agent, Project, Service, Capacity, Period +from .. import db_mgr @bp.route('/') @@ -59,4 +62,11 @@ def periods(): @bp.route('/charge/add') def charge_add(): - return render_template('charge.html', subtitle="Affecter un agent") \ No newline at end of file + return render_template('charge.html', subtitle="Affecter un agent") + + +@bp.route('/charge/agent/') +def charge_user(agent_id): + resp = make_response(json.dumps(db_mgr.charges_by_agent(agent_id))) + resp.headers['Content-Type'] = 'application/json' + return resp -- libgit2 0.21.2