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

RevLine 
[2878]1import urllib
[2929]2from urlparse import urlsplit, urlunsplit
[2878]3from base64 import urlsafe_b64encode
[2476]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
[2675]10from paste.request import construct_url
[2479]11
[2677]12
[3183]13# OwsController is now in a separate module.  Eventually it might be loaded from
14# a separate egg.
15from ows_controller import OwsController
[2614]16
[2476]17class BaseController(WSGIController):
[2694]18   
[2905]19    def __call__(self, environ, start_response):       
[2494]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
[2929]23
24        logger.debug("BaseController.__call__ ...")
[2878]25       
26        # construct URL picking up setting of server name from config to
[2959]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       
[2878]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
[2794]46        if 'h' in request.params:
[2929]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
[2798]53            setSecuritySession()
[2794]54           
[2776]55            if 'panelView' not in session:
56                session['panelView']='History'
57            session.save()
58           
[2929]59            # Re-construct the URL removing the security related arguments
[2794]60            qs = LoginServiceQuery.stripFromURI()
61
[2929]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)
[2784]68            h.redirect_to(cc)
[2929]69
70               
[2802]71        #organise the information needed by pagetabs ...
72        # TODO avoid this for the server controllers ...
73       
[2800]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       
[2853]78        if 'selection' in session:
[2802]79            c.pageTabs.append(('Selections',h.url_for(controller='selection',action='index')))
[2854]80            c.pageTabs.append(('Visualise',h.url_for(controller='visualise', action='index')))
[2802]81            c.pageTabs.append(('Download','Blah'))
[2784]82
[2494]83        return WSGIController.__call__(self, environ, start_response)
[2502]84   
[2494]85
[2476]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.