vigiboard / vigiboard / config / middleware.py @ b82c4c03
History | View | Annotate | Download (3.41 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
# vim: set fileencoding=utf-8 sw=4 ts=4 et :
|
3 |
################################################################################
|
4 |
#
|
5 |
# Copyright (C) 2007-2015 CS-SI
|
6 |
#
|
7 |
# This program is free software; you can redistribute it and/or modify
|
8 |
# it under the terms of the GNU General Public License version 2 as
|
9 |
# published by the Free Software Foundation.
|
10 |
#
|
11 |
# This program is distributed in the hope that it will be useful,
|
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
# GNU General Public License for more details.
|
15 |
#
|
16 |
# You should have received a copy of the GNU General Public License
|
17 |
# along with this program; if not, write to the Free Software
|
18 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
19 |
################################################################################
|
20 |
|
21 |
"""WSGI middleware initialization for the vigiboard application."""
|
22 |
|
23 |
import imp |
24 |
import os.path |
25 |
from pkg_resources import resource_filename |
26 |
from paste.cascade import Cascade |
27 |
from paste.urlparser import StaticURLParser |
28 |
|
29 |
__all__ = ['make_app']
|
30 |
|
31 |
|
32 |
def make_app(global_conf, full_stack=True, **app_conf): |
33 |
"""
|
34 |
Set vigiboard up with the settings found in the PasteDeploy configuration
|
35 |
file used.
|
36 |
|
37 |
This is the PasteDeploy factory for the vigiboard application.
|
38 |
|
39 |
C{app_conf} contains all the application-specific settings (those defined
|
40 |
under ``[app:main]``).
|
41 |
|
42 |
@param global_conf: The global settings for vigiboard (those
|
43 |
defined under the ``[DEFAULT]`` section).
|
44 |
@type global_conf: C{dict}
|
45 |
@param full_stack: Should the whole TG2 stack be set up?
|
46 |
@type full_stack: C{str} or C{bool}
|
47 |
@return: The vigiboard application with all the relevant middleware
|
48 |
loaded.
|
49 |
"""
|
50 |
# Charge le fichier "app_cfg.py" se trouvant aux côtés de "settings.ini".
|
51 |
mod_info = imp.find_module('app_cfg', [ global_conf['here'] ]) |
52 |
app_cfg = imp.load_module('vigiboard.config.app_cfg', *mod_info)
|
53 |
base_config = app_cfg.base_config |
54 |
|
55 |
# Initialisation de l'application et de son environnement d'exécution.
|
56 |
load_environment = base_config.make_load_environment() |
57 |
make_base_app = base_config.setup_tg_wsgi_app(load_environment) |
58 |
app = make_base_app(global_conf, full_stack=True, **app_conf)
|
59 |
|
60 |
max_age = app_conf.get("cache_max_age")
|
61 |
try:
|
62 |
max_age = int(max_age)
|
63 |
except (ValueError, TypeError): |
64 |
max_age = None
|
65 |
|
66 |
# Personalisation des fichiers statiques via un dossier public/
|
67 |
# dans le répertoire contenant le fichier settings.ini chargé.
|
68 |
custom_static = StaticURLParser(os.path.join(global_conf['here'], 'public'), |
69 |
cache_max_age=max_age) |
70 |
|
71 |
# On définit 2 middlewares pour fichiers statiques qui cherchent
|
72 |
# les fichiers dans le thème actuellement chargé.
|
73 |
# Le premier va les chercher dans le dossier des fichiers spécifiques
|
74 |
# à l'application, le second cherche dans les fichiers communs.
|
75 |
app_static = StaticURLParser( |
76 |
resource_filename('vigilo.themes.public', 'vigiboard'), |
77 |
cache_max_age=max_age) |
78 |
common_static = StaticURLParser( |
79 |
resource_filename('vigilo.themes.public', 'common'), |
80 |
cache_max_age=max_age) |
81 |
local_static = StaticURLParser( |
82 |
resource_filename('vigiboard', 'public'), |
83 |
cache_max_age=max_age) |
84 |
app = Cascade([custom_static, app_static, common_static, local_static, app]) |
85 |
return app
|