source: cows_wps/trunk/cows_wps/wsgiapp.py @ 6955

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows_wps/trunk/cows_wps/wsgiapp.py@6955
Revision 6955, 3.6 KB checked in by astephen, 10 years ago (diff)

various fixes, got ui renderer working instead of html pages. fixes zoom
and center of the bounding box on submit page.

Line 
1"""The cows_wps WSGI application"""
2import os
3
4from beaker.middleware import CacheMiddleware, SessionMiddleware
5from routes.middleware import RoutesMiddleware
6
7from paste.cascade import Cascade
8from paste.registry import RegistryManager
9from paste.urlparser import StaticURLParser
10from paste.deploy.converters import asbool
11
12from pylons import config
13from pylons.error import error_template
14from pylons.middleware import error_mapper, ErrorDocuments, ErrorHandler, \
15    StaticJavascripts
16from pylons.wsgiapp import PylonsApp
17
18import cows_wps.helpers
19from cows_wps.routing import make_map
20
21from cows_wps.utils.setenv import setenv_wps
22
23def load_environment(global_conf, app_conf, set_env = True):
24    """
25    Configure the Pylons environment via the ``pylons.config`` object.
26    """
27    # Pylons paths
28    root = os.path.dirname(os.path.abspath(__file__))
29    paths = dict(root=root,
30                 controllers=os.path.join(root, 'controllers'),
31                 static_files=os.path.join(root, 'public'),
32                 templates=[os.path.join(root, 'templates')])
33
34    # Initialize config with the basic options
35    config.init_app(global_conf, app_conf, package='cows_wps',
36                    template_engine='genshi', paths=paths)
37
38    config['pylons.strict_c'] = True
39
40    config['routes.map'] = make_map()
41    config['pylons.g'] = Globals()
42    config['pylons.h'] = cows_wps.helpers
43
44    # Customize templating options via this variable
45    tmpl_options = config['buffet.template_options']
46
47    # CONFIGURATION OPTIONS HERE (note: all config options will override
48    # any Pylons config options)
49    if set_env == True:
50        setenv_wps()
51
52
53def make_app(global_conf, full_stack = True, **app_conf):
54    """Create a Pylons WSGI application and return it
55
56    ``global_conf``
57        The inherited configuration for this application. Normally from
58        the [DEFAULT] section of the Paste ini file.
59
60    ``full_stack``
61        Whether or not this application provides a full WSGI stack (by
62        default, meaning it handles its own exceptions and errors).
63        Disable full_stack when this application is "managed" by another
64        WSGI middleware.
65
66    ``app_conf``
67        The application's local configuration. Normally specified in the
68        [app:<name>] section of the Paste ini file (where <name>
69        defaults to main).
70    """
71    # Configure the Pylons environment
72    load_environment(global_conf, app_conf)
73
74    # The Pylons WSGI app
75    app = PylonsApp()
76
77    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
78    app = RoutesMiddleware(app, config['routes.map'])
79    app = SessionMiddleware(app, config)
80    app = CacheMiddleware(app, config)
81
82
83    # Import managers here to trigger instantiation in main thread.
84    import cows_wps.model.managers
85
86    if asbool(full_stack):
87        # Display error documents for 401, 403, 404 status codes (and
88        # 500 when debug is disabled)
89        app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)
90
91    # Establish the Registry for this application
92    app = RegistryManager(app)
93
94    # Static files
95    javascripts_app = StaticJavascripts()
96    static_app = StaticURLParser(config['pylons.paths']['static_files'])
97    app = Cascade([static_app, javascripts_app, app])
98    return app
99
100
101
102
103
104class Globals(object):
105    """Globals acts as a container for objects available throughout the
106    life of the application
107    """
108
109    def __init__(self):
110        """One instance of Globals is created during application
111        initialization and is available during requests via the 'g'
112        variable.
113        """
114        pass
Note: See TracBrowser for help on using the repository browser.