source: MILK/trunk/milk_server/milk_server/lib/base.py @ 4469

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/MILK/trunk/milk_server/milk_server/lib/base.py@4469
Revision 4469, 2.8 KB checked in by cbyrom, 11 years ago (diff)

Strip out code not relevant to MILK - mainly WCS and WMS stuff - also including the CSML server code + trackback code
Also tidy up structure of 'public' dir - setting up new 'style' dir and
centralising icons in icons dir + remove all unused icons, javascript and stylesheets.
Also strip out testcase code and populate new test directory structure.

Line 
1# Copyright (C) 2007 STFC & NERC (Science and Technology Facilities Council).
2# This software may be distributed under the terms of the
3# Q Public License, version 1.0 or later.
4# http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
5#
6"""
7 Base controller providing generic functionality and extended by most other controllers
8"""
9from pylons import c, g, cache, request, session, response
10from pylons.controllers import WSGIController
11from pylons.decorators import jsonify, validate
12from pylons.templating import render
13from pylons.controllers.util import abort, redirect_to, etag_cache
14from pylons.i18n import N_, _, ungettext
15from paste.request import construct_url
16import milk_server.models as model
17import milk_server.lib.helpers as h
18
19# NDG Security import enables Single Sign On capability but note this is not
20# required for a standalone discovery service deployment
21try:
22    from ndg.security.client.ssoclient.ssoclient.lib.base import \
23        BaseController as _BaseController
24except ImportError, e:
25    from warnings import warn
26    warn('%s: ndg.security.client unavailable - ' % __name__ + \
27         'Single Sign on functionality disabled: %s' % e,
28         RuntimeWarning)
29
30    # Extend BaseController from WSGIController instead
31    _BaseController = WSGIController
32
33 
34try:
35    from xml.etree import ElementTree as ET
36except ImportError:
37    from elementtree import ElementTree as ET
38
39import logging
40logger = logging.getLogger(__name__)
41
42# Configure
43EXCEPTION_TYPE = request.environ['ndgConfig'].get('MILK_SERVER', 'exception_type', 'ogc').lower()
44
45class BaseController(_BaseController):
46   
47    def __call__(self, environ, start_response):       
48        # Insert any code to be run per request here. The Routes match
49        # is under environ['pylons.routes_dict'] should you want to check
50        # the action or route vars here
51
52        logger.debug("BaseController.__call__ ...")       
53               
54        #organise the information needed by pagetabs ...
55        # TODO avoid this for the server controllers ...
56        c.pageTabs=[('Search',g.discoveryURL)]
57        if 'results' in session: 
58            c.pageTabs.append(('Results',session['results']))
59            # make selections tab available once results are shown - to simplify associated business logic
60            c.pageTabs.append(('Selections',h.url_for(controller='selectedItems',action='index')))
61           
62        if 'lastViewed' in session: c.pageTabs.append(('Details',session['lastViewed']))
63       
64        if 'viewItems' in session: c.pageTabs.append(('View', h.url_for(controller='viewItems',action='index')))
65       
66        return _BaseController.__call__(self, environ, start_response)
67
68
69# Include the '_' function in the public names
70__all__ = [__name for __name in locals().keys() if not __name.startswith('_') \
71           or __name == '_']
Note: See TracBrowser for help on using the repository browser.