source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/retrieve.py @ 2639

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

Shopping cart, history and login framework for ows/discovery/browse.

Line 
1
2from ows_server.lib.base import *
3from ows_server.models import ndgObject,  ndgRetrieve
4from paste.request import parse_querystring
5
6#from ows_server.models import ndgRetrieve
7
8class RetrieveController(BaseController):
9    ''' Provides the pylons controller for retrieving NDG documents. The simple model
10    is now that an attempt to retrieve/uri will parse the uri, read the config file,
11    and if the local server name is not the same as the uri server name. '''
12   
13    def __setup(self,uri):
14        ''' Common setup stuff for all the actions on this controller '''
15        try:
16            self.uri=ndgObject.ndgObject(uri)
17        except ValueError,e:
18            return e
19        self.cf=request.environ['ndgConfig']
20        self.uri.setConfig(self.cf)
21        self.requestor=request.environ['REMOTE_ADDR']
22        self.logger=0
23        if logger: self.logger=logger
24        self.inputs=dict(parse_querystring(request.environ))
25        # it's kind of unfortunate that format=(xml,html) is what we expect in the
26        # url but at the retrieval level format is the schema ... oh well ...
27        self.format=''
28        if 'original' in self.inputs:
29            self.format={'0':'','1':'original'}[self.inputs['original']]
30        return 0
31       
32    def index(self,uri):
33        ''' Returns the document unadorned in anyway, i.e. the raw xml'''
34        status=self.__setup(uri)
35        if status: return Response(status)
36        status,x=ndgRetrieve.ndgRetrieve(
37                self.uri,self.cf,logger=self.logger,requestor=self.requestor,format=self.format)
38       
39        if status:
40            #(the return object x is an xmlHandler object)
41            xml=x.html
42            return Response(xml)
43        else:
44            return Response(xml)
45       
46    def view(self,uri):
47        ''' Returns either an html marked up version of the xml, or a properly laid
48        out version of the document '''
49        status=self.__setup(uri)
50        if status: return Response(status)
51        status,x=ndgRetrieve.ndgRetrieve(
52                self.uri,self.cf,logger=self.logger,requestor=self.requestor,format=self.format)
53        if status:
54            #(the return object x is an xmlHandler object)
55            xml=x.html
56            if 'format' in self.inputs:
57                if self.inputs['format']=='xml':
58                    pass
59        else: xml=x
60        c.xml=xml
61        c.title='Viewing [%s]'%self.uri
62        f=file('debug.xml','w')
63        f.write(xml)
64        f.close()
65        return render_response('content')
66   
67   
68       
Note: See TracBrowser for help on using the repository browser.