Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / config / middleware.py @ 046c501b

History | View | Annotate | Download (3.25 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
from repoze.who.plugins.testutil import make_middleware_with_config \
30
                                    as make_who_with_config
31
from logging import getLogger
32

    
33
__all__ = ['make_app']
34

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

    
39

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

45
    This is the PasteDeploy factory for the vigiboard application.
46

47
    C{app_conf} contains all the application-specific settings (those defined
48
    under ``[app:main]``).
49

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

    
60
    # Ajout du middleware d'authentification.
61
    app = make_who_with_config(
62
        app, global_conf,
63
        app_conf.get('auth.config', 'who.ini'),
64
        None,
65
        None,
66
        app_conf.get('skip_authentication')
67
    )
68
    # On force l'utilisation d'un logger nommé "auth"
69
    # pour la compatibilité avec TurboGears.
70
    app.logger = getLogger('auth')
71

    
72
    # On définit 2 middlewares pour fichiers statiques qui cherchent
73
    # les fichiers dans le thème actuellement chargé.
74
    # Le premier va les chercher dans le dossier des fichiers spécifiques
75
    # à l'application, le second cherche dans les fichiers communs.
76
    app_static = StaticURLParser(resource_filename(
77
        'vigilo.themes.public', 'vigiboard'))
78
    common_static = StaticURLParser(resource_filename(
79
        'vigilo.themes.public', 'common'))
80
    local_static = StaticURLParser(resource_filename(
81
        'vigiboard', 'public'))
82
    app = Cascade([app_static, common_static, local_static, app])
83
    return app