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

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

Created a dummy controller for testing the ows parameter parsing
features. It works :-)

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
15        # All OWS parameter names are case insensitive.
16        req = request._current_obj()
17        self.ows_params = {}
18        for k in req.params:
19            self.ows_params[k.lower()] = req.params[k]       
20
21        try:
22            self._fix_ows_action(environ)
23            return WSGIController.__call__(self, environ, start_response) 
24        except OwsError, e:
25            return render_response('exception_report', report=e.report,
26                                   format='xml')
27           
28 
29    def _fix_ows_action(self, environ):
30        # Override the Routes action from the request query parameter
31        try:
32            action = self.ows_params['request']
33        except KeyError:
34            raise OwsError('MissingParameterValue', 'request parameter not specified', 'request')
35
36        # Check action is a method in self
37        if not getattr(self, action):
38            raise OwsError('InvalidParameterValue', 'request=%s not supported' % action, 'request')
39
40        # override routes action with request
41        environ['pylons.routes_dict']['action'] = action
42        del self.ows_params['request']
43
44    def _get_method_args(self):
45        """Extends Controller._get_method_args to retrieve arguments from the query string.
46
47        See the docstring for Controller._get_method_args for details.
48
49        """
50
51        # Get the method arguments and add the query string arguments
52        kargs = WSGIController._get_method_args(self)
53        kargs.update(self.ows_params)
54
55        return kargs
56
57# Include the '_' function in the public names
58__all__ = [__name for __name in locals().keys() if not __name.startswith('_') \
59           or __name == '_']
Note: See TracBrowser for help on using the repository browser.