Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / config / middleware.py @ 98760d1b

History | View | Annotate | Download (3.2 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 vigilo.turbogears.repoze_who import make_middleware_with_config
30
from logging import getLogger
31

    
32
__all__ = ['make_app']
33

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

    
38

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

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

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

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

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

    
71
    # 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
    app_static = StaticURLParser(resource_filename(
76
        'vigilo.themes.public', 'vigiboard'))
77
    common_static = StaticURLParser(resource_filename(
78
        'vigilo.themes.public', 'common'))
79
    local_static = StaticURLParser(resource_filename(
80
        'vigiboard', 'public'))
81
    app = Cascade([app_static, common_static, local_static, app])
82
    return app