source: TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_server/ows_server/lib/base.py @ 3183

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_server/ows_server/lib/base.py@3183
Revision 3183, 3.7 KB checked in by spascoe, 12 years ago (diff)

Moving OwsController? to it's own module

Line 
1import urllib
2from urlparse import urlsplit, urlunsplit
3from base64 import urlsafe_b64encode
4from pylons import Response, c, g, cache, request, session
5from pylons.controllers import WSGIController
6from pylons.decorators import jsonify, validate
7from pylons.templating import render, render_response
8from pylons.helpers import abort, redirect_to, etag_cache
9from pylons.i18n import N_, _, ungettext
10from paste.request import construct_url
11
12
13# OwsController is now in a separate module.  Eventually it might be loaded from
14# a separate egg.
15from ows_controller import OwsController
16
17class BaseController(WSGIController):
18   
19    def __call__(self, environ, start_response):       
20        # Insert any code to be run per request here. The Routes match
21        # is under environ['pylons.routes_dict'] should you want to check
22        # the action or route vars here
23
24        logger.debug("BaseController.__call__ ...")
25       
26        # construct URL picking up setting of server name from config to
27        # avoid exposing absolute URL hidden behind mod_proxy see #857
28        # Also, avoid returning to getCredentials and potentially exposing
29        # username/pass-phrase on URL.
30        # TODO: rework getCredentials get-out for more modular solution
31        pathInfo = urllib.quote(environ.get('PATH_INFO', '')) 
32        if 'getCredentials' in pathInfo:
33            logger.debug(\
34                "Reverting request URL from getCredentials to discovery...")
35            c.requestURL = g.server + '/discovery'       
36        else:
37            c.requestURL = g.server + pathInfo
38            query='&'.join(["%s=%s"%item for item in request.params.items()])
39            if query:
40                c.requestURL += '?' + query
41       
42        # Base 64 encode to enable passing around in 'r' argument of query
43        # string for use with login/logout
44        c.b64encRequestURL = urlsafe_b64encode(c.requestURL)
45
46        if 'h' in request.params:
47            # 'h' corresponds to the setting of a session manager host i.e.
48            # the request has come from a completed login from the login
49            # service
50            logger.debug("Setting security session from URL query args ...")
51           
52            # Copy the query arguments into security session keys
53            setSecuritySession()
54           
55            if 'panelView' not in session:
56                session['panelView']='History'
57            session.save()
58           
59            # Re-construct the URL removing the security related arguments
60            qs = LoginServiceQuery.stripFromURI()
61
62            logger.debug('Switching from https to http...')
63            cc = g.server + urllib.quote(environ.get('PATH_INFO',''))
64            if qs:
65                cc += "?" + qs
66               
67            logger.debug('URL transport switched to http: "%s"' % cc)
68            h.redirect_to(cc)
69
70               
71        #organise the information needed by pagetabs ...
72        # TODO avoid this for the server controllers ...
73       
74        c.pageTabs=[('Search',g.discoveryURL)]
75        if 'results' in session: c.pageTabs.append(('Results',session['results']))
76        if 'lastViewed' in session: c.pageTabs.append(('Display',session['lastViewed']))
77       
78        if 'selection' in session:
79            c.pageTabs.append(('Selections',h.url_for(controller='selection',action='index')))
80            c.pageTabs.append(('Visualise',h.url_for(controller='visualise', action='index')))
81            c.pageTabs.append(('Download','Blah'))
82
83        return WSGIController.__call__(self, environ, start_response)
84   
85
86# Include the '_' function in the public names
87__all__ = [__name for __name in locals().keys() if not __name.startswith('_') \
88           or __name == '_']
Note: See TracBrowser for help on using the repository browser.