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

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@3184
Revision 3184, 3.9 KB checked in by spascoe, 12 years ago (diff)

Things missed in previous commit

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