source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/base.py @ 2494

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

Created a trivial CSML reading app based on Dom's code. Just shows the
featureIds for now.

Line 
1from pylons import Response, c, g, cache, request, session
2from pylons.controllers import WSGIController
3from pylons.decorators import jsonify, validate
4from pylons.templating import render, render_response
5from pylons.helpers import abort, redirect_to, etag_cache
6from pylons.i18n import N_, _, ungettext
7import ows_server.models as model
8import ows_server.lib.helpers as h
9
10from ows_common.exception_report import OwsError
11
12class BaseController(WSGIController):
13    def __call__(self, environ, start_response):
14        # Insert any code to be run per request here. The Routes match
15        # is under environ['pylons.routes_dict'] should you want to check
16        # the action or route vars here
17        return WSGIController.__call__(self, environ, start_response)
18
19class OwsController(BaseController):
20    def __call__(self, environ, start_response):
21
22        # All OWS parameter names are case insensitive.
23        req = request._current_obj()
24        self.ows_params = {}
25        for k in req.params:
26            self.ows_params[k.lower()] = req.params[k]       
27
28        try:
29            self._fix_ows_action(environ)
30            return WSGIController.__call__(self, environ, start_response) 
31        except OwsError, e:
32            return render_response('exception_report', report=e.report,
33                                   format='xml')
34           
35 
36    def _fix_ows_action(self, environ):
37        # Override the Routes action from the request query parameter
38        try:
39            action = self.ows_params['request']
40        except KeyError:
41            raise OwsError('MissingParameterValue', 'request parameter not specified', 'request')
42
43        # Check action is a method in self
44        if not getattr(self, action):
45            raise OwsError('InvalidParameterValue', 'request=%s not supported' % action, 'request')
46
47        # override routes action with request
48        environ['pylons.routes_dict']['action'] = action
49        del self.ows_params['request']
50
51    def _get_method_args(self):
52        """Extends Controller._get_method_args to retrieve arguments from the query string.
53
54        See the docstring for Controller._get_method_args for details.
55
56        """
57
58        # Get the method arguments and add the query string arguments
59        kargs = WSGIController._get_method_args(self)
60        kargs.update(self.ows_params)
61
62        return kargs
63
64# Include the '_' function in the public names
65__all__ = [__name for __name in locals().keys() if not __name.startswith('_') \
66           or __name == '_']
Note: See TracBrowser for help on using the repository browser.