Changeset 1586 for TI07-MOLES


Ignore:
Timestamp:
15/10/06 20:48:56 (13 years ago)
Author:
lawrence
Message:

First cut of standalone discovery code ... integrated into one python
module with the browe stuff ... (next steps include split into two
parents and one child egg as well as making it actually work).

Location:
TI07-MOLES/trunk/PythonCode/browse/portal/cgi
Files:
3 added
2 edited
3 copied

Legend:

Unmodified
Added
Removed
  • TI07-MOLES/trunk/PythonCode/browse/portal/cgi/browse/DiscoveryGUI.py

    r1583 r1586  
    1 import template 
     1import DiscoveryTemplate 
     2import ndgSearch as NS 
     3from DIF import DIF 
     4from renderDiscoverySet import renderDiscoverySet 
     5from DiscoveryState import DiscoveryState 
    26 
    37class DiscoveryGUI: 
     
    59    template.py code which provides the gui interface and the variables which need to be populated ''' 
    610     
    7     #The key options are either there is content in the inputdictoinary, in which case we have a 
     11    #The key options are either there is content in the inputdictionary, in which case we have a 
    812    #search to do, and then some results to present, or there is none, in which case we present 
    913    #an appropriate interface back to the user (remembering that we only produce part of a page, 
    1014    #this can all be embedded in anything else. 
    1115     
    12     def __init__(self,inputDict,config=None): 
     16    def __init__(self,request,config=None): 
    1317        ''' Takes a dictionary of variables which have been populated by the cgi (or whatever)  
    1418        handler, and tests them for sanity before handing queries off to the NDG backend xqquery 
    1519        web service ''' 
    1620         
    17         self.inputs=inputDict 
     21        self.request=request 
     22        self.inputs=request.variables 
    1823        self.message='' 
    1924        self.html='' 
    2025        self.config=config 
    21         print self.inputs.keys() 
     26        self.serviceFile=self.config.get('services','serviceFile') 
     27        self.selector=None  # This is the tick box that I think we should get rid of ... 
    2228         
    2329        #is this simply a blank request for an interface? 
     
    3541         
    3642        #the following may also be present 
    37         continuations=['start','howmany'] 
     43        continuations={'start':1,'howmany':20} 
     44        for i in continuations: 
     45            if i not in self.inputs: self.inputs[i]=continuations[i] 
    3846             
    39         advanced=inputDict['advanced'] 
     47        advanced=int(self.inputs['advanced']) 
     48         
    4049        if not advanced: 
    41             self.doText(inputDict['searchString'],inputDict['textTarget']) 
     50            self.doText(self.inputs['searchString'],self.inputs['textTarget'], 
     51                        self.inputs['start'],self.inputs['howmany']) 
    4252        else: 
    4353            #check content 
     
    4555                        'endDateDay','endDateMon','endDateYear','spaceLimit', 
    4656                        'bboxN','bboxE','bboxS','bboxW','sourceLimit'] 
    47             self.__checkForm(expected) 
     57            self.__checkform(expected) 
    4858            if self.message!='': return 
    4959             
     
    5161                self.inputs['spaceLimit']=="None": 
    5262                #it's a simple text search from the advanced box 
    53                 self.doText() 
     63                self.doText(self.inputs['searchString'],self.inputs['textTarget'], 
     64                        self.inputs['start'],self.inputs['howmany']) 
    5465            else: 
    5566                #it's more complicated 
     
    5768        return 
    5869             
    59     def __checkForm(self,expected): 
     70    def __checkform(self,expected): 
    6071        ''' Simply checks the inputs to make sure the elements in expected are present ''' 
    61         message="An incomplete NDG search form was received" 
     72        message="An incomplete NDG search form was received: " 
    6273        for i in expected: 
    63             if i not in self.inputs: self.message=message 
     74            if i not in self.inputs:  
     75                self.message=message+i 
     76                self.html='<p>%s</p>'%self.message 
     77                 
     78    def __setState(self,id,hits,offset,stride): 
     79        ''' Sets the discovery state to be used by external routines ''' 
     80        return DiscoveryState(id,self.request.URL,hits,offset,stride) 
    6481         
    65     def doText(self): 
    66         ''' Carry out a text search without geospatial elements ''' 
    67         pass 
     82    def doText(self,searchString,textTarget,start,howmany): 
     83        ''' Carry out a text search for <searchString> without geospatial elements,  
     84        in the <textTarget> where the accepted text target values are controlled 
     85        by the DiscoveryTemplate GUI, and are: All, Authors, Parameters ''' 
     86        # although at the moment we only support ALL 
     87        ws=NS.ndgSearch() 
     88        documents=ws.search(searchString,start=start,howmany=howmany) 
     89        hits=ws.hits 
     90        id=ws.serverSessionID 
     91        state=self.__setState(id,hits,start,howmany) 
     92        if hits==0:  
     93            self.html='<p> No records found </p>' 
     94        else: 
     95            results=ws.getAllDocsAsElements() 
     96            difs=[] 
     97            for result in results: difs.append(DIF(result,serviceFile=self.serviceFile,et=1)) 
     98            self.html=renderDiscoverySet(difs,state,selector=self.selector, 
     99                               summary=1,spatial=1,temporal=1,services=1) 
     100                 
     101        return 
    68102     
    69103    def doGeoSpatial(self): 
     
    81115            return 
    82116         
    83         self.html=template.main%locals() 
     117        self.html=DiscoveryTemplate.main%locals() 
    84118        return 
    85119     
     
    94128            self.html='' 
    95129            return 
    96         self.html=template.advanced%locals() 
     130        self.html=DiscoveryTemplate.advanced%locals() 
    97131        return 
    98132         
  • TI07-MOLES/trunk/PythonCode/browse/portal/cgi/browse/browseCGI.py

    r1577 r1586  
    244244                    ws=ndgSearch() 
    245245                    ws.search(self.uri) 
    246                     xml=ws.getDoc(ws.documents[0]) 
     246                    if ws.documents is not None: 
     247                        xml=ws.getDoc(ws.documents[0]) 
     248                    else: 
     249                        xml='Error' 
    247250                    if xml[0:5]=='Error': 
    248251                        return self.error('Unable to obtain record [%s] from database'%self.uri),self.uri 
  • TI07-MOLES/trunk/PythonCode/browse/portal/cgi/browse/testDiscovery.py

    r1583 r1586  
    1 import template 
     1import DiscoveryTemplate 
    22from Utilities import myConfig 
    33from DiscoveryGUI import DiscoveryGUI 
  • TI07-MOLES/trunk/PythonCode/browse/portal/cgi/discovery/ndgSearch.py

    r1577 r1586  
    6262        docs=[] 
    6363        self.status=[] 
     64         
     65        if self.documents is None: return [] 
    6466         
    6567        #create a request object 
Note: See TracChangeset for help on using the changeset viewer.