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

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

Replace 'viewItems' controller and flesh out selected Items controller - to allow user to plot results out in Google Earth and conTerra +
add wmc client section to config file to allow this to be specified as
an alternative service + tidy up some logging and unused code + update
prototype version to avoid IE problems.

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
40
41# Configure
42EXCEPTION_TYPE = request.environ['ndgConfig'].get('MILK_SERVER', 'exception_type', 'ogc').lower()
43
44class BaseController(_BaseController):
45   
46    def __call__(self, environ, start_response):       
47        # Insert any code to be run per request here. The Routes match
48        # is under environ['pylons.routes_dict'] should you want to check
49        # the action or route vars here
50
51        logging.debug("BaseController.__call__ ...")       
52               
53        #organise the information needed by pagetabs ...
54        # TODO avoid this for the server controllers ...
55        c.pageTabs=[('Search',g.discoveryURL)]
56        if 'results' in session: 
57            c.pageTabs.append(('Results',session['results']))
58            # make selections tab available once results are shown - to simplify associated business logic
59            c.pageTabs.append(('Selections',h.url_for(controller='selectedItems',action='index')))
60           
61        if 'lastViewed' in session: c.pageTabs.append(('Details',session['lastViewed']))
62
63        if g.atomEditorEnabled: c.pageTabs.append(('Editor', session.get('currentEditor') or \
64                                                       h.url_for(controller='atom_editor/listatom',action='atomHome')))
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.