vigiboard / vigiboard / config / middleware.py @ 2e753457
History | View | Annotate | Download (2.26 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
# vim: set fileencoding=utf-8 sw=4 ts=4 et :
|
3 |
"""WSGI middleware initialization for the vigiboard application."""
|
4 |
|
5 |
from vigiboard.config.app_cfg import base_config |
6 |
from vigiboard.config.environment import load_environment |
7 |
|
8 |
from pkg_resources import resource_filename |
9 |
from paste.cascade import Cascade |
10 |
from paste.urlparser import StaticURLParser |
11 |
from repoze.who.config import make_middleware_with_config \ |
12 |
as make_who_with_config
|
13 |
|
14 |
__all__ = ['make_app']
|
15 |
|
16 |
# Use base_config to setup the necessary PasteDeploy application factory.
|
17 |
# make_base_app will wrap the TG2 app with all the middleware it needs.
|
18 |
make_base_app = base_config.setup_tg_wsgi_app(load_environment) |
19 |
|
20 |
|
21 |
def make_app(global_conf, full_stack=True, **app_conf): |
22 |
"""
|
23 |
Set vigiboard up with the settings found in the PasteDeploy configuration
|
24 |
file used.
|
25 |
|
26 |
This is the PasteDeploy factory for the vigiboard application.
|
27 |
|
28 |
C{app_conf} contains all the application-specific settings (those defined
|
29 |
under ``[app:main]``).
|
30 |
|
31 |
@param global_conf: The global settings for vigiboard (those
|
32 |
defined under the ``[DEFAULT]`` section).
|
33 |
@type global_conf: C{dict}
|
34 |
@param full_stack: Should the whole TG2 stack be set up?
|
35 |
@type full_stack: C{str} or C{bool}
|
36 |
@return: The vigiboard application with all the relevant middleware
|
37 |
loaded.
|
38 |
"""
|
39 |
app = make_base_app(global_conf, full_stack=full_stack, **app_conf) |
40 |
|
41 |
# On définit 2 middlewares pour fichiers statiques qui cherchent
|
42 |
# les fichiers dans le thème actuellement chargé.
|
43 |
# Le premier va les chercher dans le dossier des fichiers spécifiques
|
44 |
# à l'application, le second cherche dans les fichiers communs.
|
45 |
app_static = StaticURLParser(resource_filename( |
46 |
'vigilo.themes.public', 'vigiboard')) |
47 |
common_static = StaticURLParser(resource_filename( |
48 |
'vigilo.themes.public', 'common')) |
49 |
local_static = StaticURLParser(resource_filename( |
50 |
'vigiboard', 'public')) |
51 |
app = Cascade([app_static, common_static, local_static, app]) |
52 |
|
53 |
app = make_who_with_config( |
54 |
app, global_conf, |
55 |
app_conf.get('auth.config', 'who.ini'), |
56 |
app_conf.get('auth.log_file', 'stdout'), |
57 |
app_conf.get('auth.log_level', 'debug'), |
58 |
) |
59 |
return app
|