Blame view

app/main/routes.py 2.7 KB
71b91c22   hitier   New json route fo...
1
2
3
import json

from flask import render_template, make_response
8bd0f3cb   hitier   Fix #25: Flask Bl...
4
5
6

from . import bp

6cbf4b75   hitier   Periods list
7
from app.models import Agent, Project, Service, Capacity, Period
71b91c22   hitier   New json route fo...
8
from .. import db_mgr
d6836d5e   hitier   Agents list
9

8bd0f3cb   hitier   Fix #25: Flask Bl...
10
11
12

@bp.route('/')
def index():
a7e64a99   hitier   Services list
13
14
15
16
17
18
19
20
21
    return render_template('index.html', subtitle="Page d'accueil")


@bp.route('/services')
def services():
    # get services list
    all_services = Service.query.order_by(Service.name).all()
    num_services = len(all_services)
    # pass to template
6cbf4b75   hitier   Periods list
22
    return render_template('services.html', subtitle="Liste des services ({})".format(num_services),
a7e64a99   hitier   Services list
23
                           services=all_services)
d6836d5e   hitier   Agents list
24
25


3dae0d18   hitier   Projects list
26
27
28
29
30
31
@bp.route('/projects')
def projects():
    # get projects list
    all_projects = Project.query.order_by(Project.name).all()
    num_projects = len(all_projects)
    # pass to template
a7e64a99   hitier   Services list
32
    return render_template('projects.html', subtitle="Liste des projets ({})".format(num_projects),
3dae0d18   hitier   Projects list
33
34
                           projects=all_projects)

a7e64a99   hitier   Services list
35

d6836d5e   hitier   Agents list
36
37
38
39
40
41
@bp.route('/agents')
def agents():
    # get agents list
    all_agents = Agent.query.order_by(Agent.firstname).all()
    num_agents = len(all_agents)
    # pass to template
a7e64a99   hitier   Services list
42
    return render_template('agents.html', subtitle="Liste des agents ({})".format(num_agents),
d6836d5e   hitier   Agents list
43
                           agents=all_agents)
980708a2   hitier   Capacities list
44
45
46
47
48
49
50
51
52

@bp.route('/capacities')
def capacities():
    # get capacities list
    all_capacities = Capacity.query.order_by(Capacity.name).all()
    num_capacities = len(all_capacities)
    # pass to template
    return render_template('capacities.html', subtitle="Liste des fonctions ({})".format(num_capacities),
                           capacities=all_capacities)
6cbf4b75   hitier   Periods list
53
54
55
56
57
58
59
60
61

@bp.route('/periods')
def periods():
    # get capacities list
    all_periods = Period.query.order_by(Period.name).all()
    num_periods = len(all_periods)
    # pass to template
    return render_template('periods.html', subtitle="Liste des périodes ({})".format(num_periods),
                           periods=all_periods)
412b041b   hitier   Add charge
62

9183e41e   hitier   Change add charge...
63
64
@bp.route('/charge/add')
def charge_add():
71b91c22   hitier   New json route fo...
65
66
67
68
    return render_template('charge.html', subtitle="Affecter un agent")


@bp.route('/charge/agent/<agent_id>')
d9f5cfc9   hitier   New agent page dy...
69
def charge_agent(agent_id):
04e2a90d   hitier   Show agent charge...
70
71
72
73
74
    agent_charges = []
    for [period, charge] in db_mgr.charges_by_agent(agent_id):
        agent_charges.append({"charge": charge, "periode": period})
    # agent_charges = [["charge", "periode"]]+db_mgr.charges_by_agent(agent_id)#agent_charges
    resp = make_response(json.dumps(agent_charges))
71b91c22   hitier   New json route fo...
75
76
    resp.headers['Content-Type'] = 'application/json'
    return resp
d9f5cfc9   hitier   New agent page dy...
77
78
79
80
81
82

@bp.route('/agent/<agent_id>')
def agent(agent_id):
    agent = Agent.query.get(int(agent_id))
    return render_template('agent.html',
                           agent=agent,
04e2a90d   hitier   Show agent charge...
83
                           subtitle="{} {}".format(agent.firstname, agent.secondname))