Blame view

app/main/routes.py 6.07 KB
ca0797d6   hitier   New agent edit form
1
from flask import render_template, make_response, current_app, redirect, url_for, request, flash
3b0d5feb   hitier   New Site_Login ca...
2
from flask_login import login_required, current_user
8bd0f3cb   hitier   Fix #25: Flask Bl...
3
4
5

from . import bp

ac2fa9fd   hitier   Use select_option...
6
from app.models import Agent, Project, Service, Capacity, Period, db, Company, AgentGrade, AgentStatus, AgentBap
dcafa5d0   hitier   Protect routes by...
7
8
from app import db_mgr
from app.auth.routes import role_required
d6836d5e   hitier   Agents list
9

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

3b0d5feb   hitier   New Site_Login ca...
11
12
13
14
15
16
17
18
19
20
@bp.before_request
def site_login():
    try:
        if current_app.config['SITE_LOGIN'] \
                and not current_user.is_authenticated:
            return redirect(url_for('auth.login'))
    except KeyError:
        # no such config, juste ignore
        pass

1b604951   hitier   Rearrange code
21

3b0d5feb   hitier   New Site_Login ca...
22
23
@bp.before_request
def catch_all_route():
1b604951   hitier   Rearrange code
24
    current_app.logger.debug(f"{request.method} {request.path}")
3b0d5feb   hitier   New Site_Login ca...
25
26


8bd0f3cb   hitier   Fix #25: Flask Bl...
27
28
@bp.route('/')
def index():
a7e64a99   hitier   Services list
29
30
31
32
    return render_template('index.html', subtitle="Page d'accueil")


@bp.route('/services')
dcafa5d0   hitier   Protect routes by...
33
@role_required('service')
a7e64a99   hitier   Services list
34
35
36
37
38
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
39
    return render_template('services.html', subtitle="Liste des services ({})".format(num_services),
a7e64a99   hitier   Services list
40
                           services=all_services)
d6836d5e   hitier   Agents list
41
42


3dae0d18   hitier   Projects list
43
@bp.route('/projects')
dcafa5d0   hitier   Protect routes by...
44
@role_required('project')
3dae0d18   hitier   Projects list
45
46
def projects():
    # get projects list
f8e1465a   hitier   New projects list...
47
    all_projects = db_mgr.projects()
3dae0d18   hitier   Projects list
48
49
    num_projects = len(all_projects)
    # pass to template
a7e64a99   hitier   Services list
50
    return render_template('projects.html', subtitle="Liste des projets ({})".format(num_projects),
3dae0d18   hitier   Projects list
51
52
                           projects=all_projects)

a7e64a99   hitier   Services list
53

d6836d5e   hitier   Agents list
54
@bp.route('/agents')
dcafa5d0   hitier   Protect routes by...
55
@role_required('project')
d6836d5e   hitier   Agents list
56
def agents():
d6836d5e   hitier   Agents list
57
    # get agents list
2cb0a345   hitier   Add 2 columns in ...
58
    all_agents = db_mgr.agents()
d6836d5e   hitier   Agents list
59
60
    num_agents = len(all_agents)
    # pass to template
a7e64a99   hitier   Services list
61
    return render_template('agents.html', subtitle="Liste des agents ({})".format(num_agents),
d6836d5e   hitier &n