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

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

Operations metadata inserted correctly for CSML WMS.

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 import exceptions as OWS_E
11from ows_common.operations_metadata import OperationsMetadata, Operation, RequestMethod
12from ows_common.get_capabilities import ServiceMetadata
13
14class BaseController(WSGIController):
15    def __call__(self, environ, start_response):
16        # Insert any code to be run per request here. The Routes match
17        # is under environ['pylons.routes_dict'] should you want to check
18        # the action or route vars here
19        return WSGIController.__call__(self, environ, start_response)
20   
21class OwsController(BaseController):
22    def __call__(self, environ, start_response):
23
24        # All OWS parameter names are case insensitive.
25        req = request._current_obj()
26        self.ows_params = {}
27        for k in req.params:
28            self.ows_params[k.lower()] = req.params[k]       
29
30        try:
31            self._fix_ows_action(environ)
32            return WSGIController.__call__(self, environ, start_response) 
33        except OWS_E.OwsError, e:
34            return render_response('exception_report', report=e.report,
35                                   format='xml')
36           
37 
38    def _fix_ows_action(self, environ):
39        # Override the Routes action from the request query parameter
40        try:
41            action = self.ows_params['request']
42        except KeyError:
43            raise OWS_E.MissingParameterValue('REQUEST parameter not specified', 'REQUEST')
44
45        # Check action is a method in self
46        if not getattr(self, action):
47            raise OWS_E.InvalidParameterValue('request=%s not supported' % action, 'REQUEST')
48
49        # override routes action with request
50        environ['pylons.routes_dict']['action'] = action
51        del self.ows_params['request']
52
53    def _get_method_args(self):
54        """Extends Controller._get_method_args to retrieve arguments
55        from the query string.
56
57        See the docstring for Controller._get_method_args for details.
58
59        """
60
61        # Get the method arguments and add the query string arguments
62        kargs = WSGIController._get_method_args(self)
63        kargs.update(self.ows_params)
64
65        return kargs
66
67
68    def _load_capabilities(self, ows_endpoint):
69        """
70        creates an ows_common.get_capabilities.ServiceMetadata object
71        by consulting the paste configuration and annotations in the
72        controller definition.  The endpoint must be supplied to allow
73        a controller to serve multiple ows endpoints.
74
75        @param ows_endpoint: The URI of the OWS endpoint being served
76            by this controller.
77
78        """
79        if hasattr(self, '_ows_service_metadata'):
80            return
81
82        parameters = getattr(self, '_ows_parameters', {})
83        constraints = getattr(self, '_ows_constraints', {})
84
85        od = {}
86        for attr in dir(self):
87            op = getattr(self, attr)
88            if hasattr(op, '_ows_name'):
89                p = getattr(op, '_ows_parameters', {})
90                c = getattr(op, '_ows_constraints', {})
91                od[op._ows_name] = Operation(get=RequestMethod(href=ows_endpoint),
92                                             post=None,
93                                             parameters=p,
94                                             constraints=c)
95       
96        om = OperationsMetadata(od, constraints, parameters)
97        return ServiceMetadata(operationsMetadata=om)
98
99# Include the '_' function in the public names
100__all__ = [__name for __name in locals().keys() if not __name.startswith('_') \
101           or __name == '_']
Note: See TracBrowser for help on using the repository browser.