source: TI07-MOLES/trunk/PythonCode/newDiscovery/DiscoveryGUI.py @ 1583

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/PythonCode/newDiscovery/DiscoveryGUI.py@1583
Revision 1583, 3.7 KB checked in by lawrence, 13 years ago (diff)

Yet more renaming ...

Line 
1import template
2
3class DiscoveryGUI:
4    ''' This class handles the NDG gui search interface, and is intimately related to the
5    template.py code which provides the gui interface and the variables which need to be populated '''
6   
7    #The key options are either there is content in the inputdictoinary, in which case we have a
8    #search to do, and then some results to present, or there is none, in which case we present
9    #an appropriate interface back to the user (remembering that we only produce part of a page,
10    #this can all be embedded in anything else.
11   
12    def __init__(self,inputDict,config=None):
13        ''' Takes a dictionary of variables which have been populated by the cgi (or whatever)
14        handler, and tests them for sanity before handing queries off to the NDG backend xqquery
15        web service '''
16       
17        self.inputs=inputDict
18        self.message=''
19        self.html=''
20        self.config=config
21        print self.inputs.keys()
22       
23        #is this simply a blank request for an interface?
24        if self.inputs.keys()==[]:
25            self.standardInterface()
26            return
27        elif self.inputs.keys()==['advanced']:
28            self.advancedInterface()
29            return
30       
31        #check simplest text issues common to both simple and advanced search
32        expected=['advanced','textTarget','searchString']
33        self.__checkform(expected)
34        if self.message!='': return
35       
36        #the following may also be present
37        continuations=['start','howmany']
38           
39        advanced=inputDict['advanced']
40        if not advanced:
41            self.doText(inputDict['searchString'],inputDict['textTarget'])
42        else:
43            #check content
44            expected=['timeLimit','startDateDay','startDateMon','startDateYear',
45                        'endDateDay','endDateMon','endDateYear','spaceLimit',
46                        'bboxN','bboxE','bboxS','bboxW','sourceLimit']
47            self.__checkForm(expected)
48            if self.message!='': return
49           
50            if self.inputs['timeLimit']=="None" and self.inputs['sourceLimit']=="None" and \
51                self.inputs['spaceLimit']=="None":
52                #it's a simple text search from the advanced box
53                self.doText()
54            else:
55                #it's more complicated
56                self.doGeoSpatial()
57        return
58           
59    def __checkForm(self,expected):
60        ''' Simply checks the inputs to make sure the elements in expected are present '''
61        message="An incomplete NDG search form was received"
62        for i in expected:
63            if i not in self.inputs: self.message=message
64       
65    def doText(self):
66        ''' Carry out a text search without geospatial elements '''
67        pass
68   
69    def doGeoSpatial(self):
70        pass
71   
72    def standardInterface(self):
73       
74        try:
75            helpAddress=self.config.get('SEARCH','helpURL')
76            discoveryURL=self.config.get('SEARCH','discoveryURL')
77            advancedURL=self.config.get('SEARCH','advancedURL')
78        except:
79            self.message='Error, invalid configuration for search interface'
80            self.html=''
81            return
82       
83        self.html=template.main%locals()
84        return
85   
86    def advancedInterface(self):
87       
88        try:
89            helpAddress=self.config.get('SEARCH','helpURL')
90            discoveryURL=self.config.get('SEARCH','discoveryURL')
91            advancedURL=self.config.get('SEARCH','advancedURL')
92        except:
93            self.message='Error, invalid configuration for search interface'
94            self.html=''
95            return
96        self.html=template.advanced%locals()
97        return
98       
99       
Note: See TracBrowser for help on using the repository browser.