Changeset 1587 for TI07-MOLES


Ignore:
Timestamp:
15/10/06 21:24:06 (13 years ago)
Author:
lawrence
Message:

Better handling of request URLs for both discovery and browse

Location:
TI07-MOLES/trunk/PythonCode/browse/portal/cgi/browse
Files:
4 edited

Legend:

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

    r1586 r1587  
    2525        self.config=config 
    2626        self.serviceFile=self.config.get('services','serviceFile') 
    27         self.selector=None  # This is the tick box that I think we should get rid of ... 
    2827         
    2928        #is this simply a blank request for an interface? 
     
    6261                #it's a simple text search from the advanced box 
    6362                self.doText(self.inputs['searchString'],self.inputs['textTarget'], 
    64                         self.inputs['start'],self.inputs['howmany']) 
     63                            self.inputs['start'],self.inputs['howmany']) 
    6564            else: 
    6665                #it's more complicated 
     
    7877    def __setState(self,id,hits,offset,stride): 
    7978        ''' Sets the discovery state to be used by external routines ''' 
    80         return DiscoveryState(id,self.request.URL,hits,offset,stride) 
     79        return DiscoveryState(id,self.request,hits,offset,stride) 
    8180         
    8281    def doText(self,searchString,textTarget,start,howmany): 
     
    8584        by the DiscoveryTemplate GUI, and are: All, Authors, Parameters ''' 
    8685        # although at the moment we only support ALL 
     86         
     87        start,howmany=int(start),int(howmany)  # url arguments need conversion ... 
     88         
    8789        ws=NS.ndgSearch() 
    8890        documents=ws.search(searchString,start=start,howmany=howmany) 
     
    9698            difs=[] 
    9799            for result in results: difs.append(DIF(result,serviceFile=self.serviceFile,et=1)) 
    98             self.html=renderDiscoverySet(difs,state,selector=self.selector, 
     100            self.html=renderDiscoverySet(difs,state, 
    99101                               summary=1,spatial=1,temporal=1,services=1) 
    100102                 
  • TI07-MOLES/trunk/PythonCode/browse/portal/cgi/browse/Utilities.py

    r1577 r1587  
    4646                                   env.get('SCRIPT_NAME')) 
    4747        self.baseURL=self.URL 
    48         #qs=env.get('QUERY_STRING') 
    49         #if qs!='': self.URL+='?'+qs 
    50         try: # some apache problems result in nasty errors ... 
    51             self.variables=getURLdict(cgi.FieldStorage()) 
     48        try: 
     49             self.variables=getURLdict(cgi.FieldStorage()) 
     50        except Exception,e: 
     51            self.variables={'Error':'<p> Error in Request, parseing url [%s]</p>'%self.URL} 
     52            return 
     53        self.URL=self.__rebuildURL() 
     54 
     55    def __rebuildURL(self): 
     56        ''' builds  a url from the cgi variables that are loaded ''' 
     57        url=self.baseURL 
     58        try:  
    5259            #reconstruct the url carefully, to avoid the selector and any 
    5360            #ndg security info if present ... 
     
    5663            for i in self.variables: 
    5764                if i not in reject: tmp[i]=self.variables[i] 
    58             if tmp!={}: self.URL+='?%s'%urllib.urlencode(tmp) 
     65            if tmp!={}: url+='?%s'%urllib.urlencode(tmp) 
    5966        except Exception,e: 
    6067            #raise e 
    61             self.variables={'Error':'<p> Error in Request, parsing url [%s] </p>'%self.URL} 
    62  
     68            self.variables={'Error':'<p> Error rebuilding URL from [%s] </p>'%url} 
     69        return url 
     70             
     71    def modify(self,variables): 
     72        ''' Used to take a GET request url, and modify some of the variables and provide  
     73        a new modified GET ''' 
     74        for var in variables: 
     75            self.variables[var]=variables[var] 
     76        return self.__rebuildURL() 
    6377class Response: 
    6478        ''' Holds all the parts of the response to an HTML get or post ''' 
  • TI07-MOLES/trunk/PythonCode/browse/portal/cgi/browse/browseCGI.py

    r1586 r1587  
    329329                 
    330330                if hits==0: return self.error('No records found'),title 
    331                 state=DiscoveryState(id,self.requestURL,hits,stride=stride,offset=start) 
     331                state=DiscoveryState(id,self.request,hits,stride=stride,offset=start) 
    332332                results=ws.getAllDocsAsElements() 
    333333                difs=[] 
    334334                for result in results: difs.append(DIF(result,serviceFile=self.serviceFile,et=1)) 
    335335         
    336                 html=renderDiscoverySet(difs,state,selector=self.selector, 
     336                html=renderDiscoverySet(difs,state, 
    337337                               summary=1,spatial=1,temporal=1,services=1) 
    338338                 
  • TI07-MOLES/trunk/PythonCode/browse/portal/cgi/browse/renderDiscoverySet.py

    r1577 r1587  
    44from htmlUtilities import * 
    55 
    6 def renderDiscoverySet(difSet,state,selector=None,summary=0,services=0,spatial=0,temporal=0, 
     6def renderDiscoverySet(difSet,state,summary=0,services=0,spatial=0,temporal=0, 
    77    linkto='NDG_B_SERVICE'): 
    88    '''Takes a set of xml DIFS from a discovery search (difSet) and renders a  
     
    107107    #html+='<p>Results %s to %s of %s'%(state.offset,min(state.offset+state.stride-1,state.hits),state.hits) 
    108108    html+='<p>Results %s to %s of %s'%(state.offset,state.offset+len(difSet)-1,state.hits) 
    109     if state.stride < state.hits and selector is not None: 
     109    if state.stride < state.hits and state.request is not None: 
    110110        #1,10,21   11,20,21  21,21,21 
    111111        if state.offset+state.stride-1<state.hits: 
     
    113113            nextNum=min(state.stride,1+state.hits-next1) # 10,1 
    114114            s1='Next %s'%nextNum 
    115             nexturl='%s&start=%s&howmany=%s&searchSession=%s'%( 
    116                         selector.baseURL,next1,nextNum,state.sessID) 
     115            nexturl=state.request.modify({'start':next1,'howmany':nextNum,'searchSession':state.sessID}) 
    117116            html+=', %s'%hyperlink(s1,nexturl) 
    118117        if state.offset>1: 
     
    121120            if lastNum<min(20,state.hits): lastNum=20 
    122121            l1='Last %s'%lastNum 
    123             lasturl='%s&start=%s&howmany=%s&searchSession=%s'%( 
    124                         selector.baseURL,last1,lastNum,state.sessID) 
     122            lasturl=state.request.modify({'start':last1,'howmany':lastNum,'searchSession':state.sessID}) 
    125123            html+=', %s'%hyperlink(l1,lasturl) 
    126124    else: 
Note: See TracChangeset for help on using the changeset viewer.