vigiboard / vigiboard / config / middleware.py @ b82c4c03
History | View | Annotate | Download (3.41 KB)
1 | d3c47597 | Francois POIROTTE | # -*- coding: utf-8 -*-
|
---|---|---|---|
2 | 2e5394d8 | Gabriel DE PERTHUIS | # vim: set fileencoding=utf-8 sw=4 ts=4 et :
|
3 | a77de887 | Francois POIROTTE | ################################################################################
|
4 | #
|
||
5 | 8d647d93 | Francois POIROTTE | # Copyright (C) 2007-2015 CS-SI
|
6 | a77de887 | Francois POIROTTE | #
|
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 | 57f7cb3f | Gabriel DE PERTHUIS | """WSGI middleware initialization for the vigiboard application."""
|
22 | d3c47597 | Francois POIROTTE | |
23 | b82c4c03 | Francois POIROTTE | import imp |
24 | import os.path |
||
25 | 5f2cd70a | Francois POIROTTE | from pkg_resources import resource_filename |
26 | from paste.cascade import Cascade |
||
27 | from paste.urlparser import StaticURLParser |
||
28 | |||
29 | 57f7cb3f | Gabriel DE PERTHUIS | __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 | 2e753457 | Francois POIROTTE |
|
37 | 57f7cb3f | Gabriel DE PERTHUIS | This is the PasteDeploy factory for the vigiboard application.
|
38 | 2e753457 | Francois POIROTTE |
|
39 | 0f56fff9 | Francois POIROTTE | C{app_conf} contains all the application-specific settings (those defined
|
40 | under ``[app:main]``).
|
||
41 | 2e753457 | Francois POIROTTE |
|
42 | 0f56fff9 | Francois POIROTTE | @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 | 57f7cb3f | Gabriel DE PERTHUIS | """
|
50 | b82c4c03 | Francois POIROTTE | # 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 | 5f2cd70a | Francois POIROTTE | |
60 | a0b5aab0 | Francois POIROTTE | 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 | b82c4c03 | Francois POIROTTE | # 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 | a0b5aab0 | Francois POIROTTE | cache_max_age=max_age) |
70 | 283f0810 | Francois POIROTTE | |
71 | 5f2cd70a | Francois POIROTTE | # 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 | a0b5aab0 | Francois POIROTTE | 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 | 283f0810 | Francois POIROTTE | app = Cascade([custom_static, app_static, common_static, local_static, app]) |
85 | 57f7cb3f | Gabriel DE PERTHUIS | return app |