Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (2.72 KB)

1
# -*- coding: utf-8 -*-
2
# vim: set fileencoding=utf-8 sw=4 ts=4 et :
3
# Copyright (C) 2007-2020 CS GROUP - France
4
# License: GNU GPL v2 <http://www.gnu.org/licenses/gpl-2.0.html>
5

    
6
"""WSGI middleware initialization for the vigiboard application."""
7

    
8
import imp
9
import os.path
10
from pkg_resources import resource_filename
11
from paste.cascade import Cascade
12
from paste.urlparser import StaticURLParser
13

    
14
__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

22
    This is the PasteDeploy factory for the vigiboard application.
23

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

27
    @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
    """
35
    # 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

    
45
    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
    # 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
                                    cache_max_age=max_age)
55

    
56
    # 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
    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
    app = Cascade([custom_static, app_static, common_static, local_static, app])
70
    return app