Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / config / middleware.py @ 011743be

History | View | Annotate | Download (2.72 KB)

1 d3c47597 Francois POIROTTE
# -*- coding: utf-8 -*-
2 2e5394d8 Gabriel DE PERTHUIS
# vim: set fileencoding=utf-8 sw=4 ts=4 et :
3 011743be Francois POIROTTE
# Copyright (C) 2007-2020 CS GROUP - France
4 9b8d9497 Francois POIROTTE
# License: GNU GPL v2 <http://www.gnu.org/licenses/gpl-2.0.html>
5 a77de887 Francois POIROTTE
6 57f7cb3f Gabriel DE PERTHUIS
"""WSGI middleware initialization for the vigiboard application."""
7 d3c47597 Francois POIROTTE
8 b82c4c03 Francois POIROTTE
import imp
9
import os.path
10 5f2cd70a Francois POIROTTE
from pkg_resources import resource_filename
11
from paste.cascade import Cascade
12
from paste.urlparser import StaticURLParser
13
14 57f7cb3f Gabriel DE PERTHUIS
__all__ = ['make_app']
15
16
17
def make_app(global_conf, full_stack=True, **app_conf):
18
    """
19
    Set vigiboard up with the settings found in the PasteDeploy configuration
20
    file used.
21 2e753457 Francois POIROTTE

22 57f7cb3f Gabriel DE PERTHUIS
    This is the PasteDeploy factory for the vigiboard application.
23 2e753457 Francois POIROTTE

24 0f56fff9 Francois POIROTTE
    C{app_conf} contains all the application-specific settings (those defined
25
    under ``[app:main]``).
26 2e753457 Francois POIROTTE

27 0f56fff9 Francois POIROTTE
    @param global_conf: The global settings for vigiboard (those
28
        defined under the ``[DEFAULT]`` section).
29
    @type global_conf: C{dict}
30
    @param full_stack: Should the whole TG2 stack be set up?
31
    @type full_stack: C{str} or C{bool}
32
    @return: The vigiboard application with all the relevant middleware
33
        loaded.
34 57f7cb3f Gabriel DE PERTHUIS
    """
35 b82c4c03 Francois POIROTTE
    # Charge le fichier "app_cfg.py" se trouvant aux côtés de "settings.ini".
36
    mod_info = imp.find_module('app_cfg', [ global_conf['here'] ])
37
    app_cfg = imp.load_module('vigiboard.config.app_cfg', *mod_info)
38
    base_config = app_cfg.base_config
39
40
    # Initialisation de l'application et de son environnement d'exécution.
41
    load_environment = base_config.make_load_environment()
42
    make_base_app = base_config.setup_tg_wsgi_app(load_environment)
43
    app = make_base_app(global_conf, full_stack=True, **app_conf)
44 5f2cd70a Francois POIROTTE
45 a0b5aab0 Francois POIROTTE
    max_age = app_conf.get("cache_max_age")
46
    try:
47
        max_age = int(max_age)
48
    except (ValueError, TypeError):
49
        max_age = None
50
51 b82c4c03 Francois POIROTTE
    # Personalisation des fichiers statiques via un dossier public/
52
    # dans le répertoire contenant le fichier settings.ini chargé.
53
    custom_static = StaticURLParser(os.path.join(global_conf['here'], 'public'),
54 a0b5aab0 Francois POIROTTE
                                    cache_max_age=max_age)
55 283f0810 Francois POIROTTE
56 5f2cd70a Francois POIROTTE
    # On définit 2 middlewares pour fichiers statiques qui cherchent
57
    # les fichiers dans le thème actuellement chargé.
58
    # Le premier va les chercher dans le dossier des fichiers spécifiques
59
    # à l'application, le second cherche dans les fichiers communs.
60 a0b5aab0 Francois POIROTTE
    app_static = StaticURLParser(
61
        resource_filename('vigilo.themes.public', 'vigiboard'),
62
        cache_max_age=max_age)
63
    common_static = StaticURLParser(
64
        resource_filename('vigilo.themes.public', 'common'),
65
        cache_max_age=max_age)
66
    local_static = StaticURLParser(
67
        resource_filename('vigiboard', 'public'),
68
        cache_max_age=max_age)
69 283f0810 Francois POIROTTE
    app = Cascade([custom_static, app_static, common_static, local_static, app])
70 57f7cb3f Gabriel DE PERTHUIS
    return app