Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / config / middleware.py @ ddbaec88

History | View | Annotate | Download (2.74 KB)

1
# -*- coding: utf-8 -*-
2
# vim: set fileencoding=utf-8 sw=4 ts=4 et :
3
################################################################################
4
#
5
# Copyright (C) 2007-2011 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
from vigiboard.config.app_cfg import base_config
24
from vigiboard.config.environment import load_environment
25

    
26
from pkg_resources import resource_filename
27
from paste.cascade import Cascade
28
from paste.urlparser import StaticURLParser
29

    
30
__all__ = ['make_app']
31

    
32
# Use base_config to setup the necessary PasteDeploy application factory.
33
# make_base_app will wrap the TG2 app with all the middleware it needs.
34
make_base_app = base_config.setup_tg_wsgi_app(load_environment)
35

    
36

    
37
def make_app(global_conf, full_stack=True, **app_conf):
38
    """
39
    Set vigiboard up with the settings found in the PasteDeploy configuration
40
    file used.
41

42
    This is the PasteDeploy factory for the vigiboard application.
43

44
    C{app_conf} contains all the application-specific settings (those defined
45
    under ``[app:main]``).
46

47
    @param global_conf: The global settings for vigiboard (those
48
        defined under the ``[DEFAULT]`` section).
49
    @type global_conf: C{dict}
50
    @param full_stack: Should the whole TG2 stack be set up?
51
    @type full_stack: C{str} or C{bool}
52
    @return: The vigiboard application with all the relevant middleware
53
        loaded.
54
    """
55
    app = make_base_app(global_conf, full_stack=full_stack, **app_conf)
56

    
57
    # On définit 2 middlewares pour fichiers statiques qui cherchent
58
    # les fichiers dans le thème actuellement chargé.
59
    # Le premier va les chercher dans le dossier des fichiers spécifiques
60
    # à l'application, le second cherche dans les fichiers communs.
61
    app_static = StaticURLParser(resource_filename(
62
        'vigilo.themes.public', 'vigiboard'))
63
    common_static = StaticURLParser(resource_filename(
64
        'vigilo.themes.public', 'common'))
65
    local_static = StaticURLParser(resource_filename(
66
        'vigiboard', 'public'))
67
    app = Cascade([app_static, common_static, local_static, app])
68
    return app