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

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

Implemented basic query string handling by editing base.BaseController?.
Created an exception report template.
Disabled error document middleware.

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