Ignore:
Timestamp:
15/05/07 16:04:20 (13 years ago)
Author:
spascoe
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/base.py

    r2476 r2479  
    88import ows_server.lib.helpers as h 
    99 
     10from ows_common.exception_report import OwsError 
     11 
    1012class BaseController(WSGIController): 
    1113    def __call__(self, environ, start_response): 
    12         # Insert any code to be run per request here. The Routes match 
    13         # is under environ['pylons.routes_dict'] should you want to check 
    14         # the action or route vars here 
    15         return WSGIController.__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 
    1657 
    1758# Include the '_' function in the public names 
Note: See TracChangeset for help on using the changeset viewer.