Ignore:
Timestamp:
25/05/06 16:42:02 (14 years ago)
Author:
lawrence
Message:

More discovery (from browse) related improvments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/renderDiscoverySet.py

    r1006 r1020  
    1 from DiscoveryWS import DiscoveryWS 
     1from DiscoveryWS import DiscoveryWS,DiscoveryState 
    22from DIF import DIF 
     3from htmlUtilities import * 
    34 
    4 def renderDiscoverySet(difSet,summary=0,services=0,spatial=0,temporal=0, 
     5def renderDiscoverySet(difSet,state,selector=None,summary=0,services=0,spatial=0,temporal=0, 
    56    linkto='NDG_B_SERVICE'): 
    6     '''Takes a set of xml DIFS from a discovery search and renders a list of responses as a table, 
    7     with layout depending on a set of keywords: 
     7    '''Takes a set of xml DIFS from a discovery search (difSet) and renders a  
     8    list of responses as a table, with layout depending on a set of keywords: 
    89            summary (boolean) - show the abstract, 
    910            services (boolean) - show the service list, 
    1011            spatial (boolean) - show the bounding box, 
    1112            temporal (boolean) - show the date range, 
    12             linkto (string) - clicking on the name should go to a service binding to this url 
    13             ''' 
     13            linkto (string) - clicking on the select widget should add the url for 
     14                              this service to the selected list 
     15     Note that state is a DiscoveryState instance containing the sessionID from the search, 
     16     and the offset, stride, and total number of results ...selector is a class for adding 
     17     particular datasets to a selection dataset (and cookie). 
     18     ''' 
     19             
    1420    # 
    1521    # List of methods which deal with the actual row content ... 
    1622    #    
    17     def span(x,id): 
    18         return '<span class="%s">%s</span>'%(id,x) 
    19      
    20     def hyperlink(n,u): 
    21         return '<a href="%s">%s</a>'%(u,n) 
    2223     
    2324    def row(rowList,bgcolor='rbgWhite'): 
     
    3738    
    3839    def serviceList(d): 
    39         ll='<br/>Services: '+hyperlink('Full Record','url') 
     40        ll=span(' Links: ','ndgem')+hyperlink('Full Record','url') 
     41        ndg=0 
    4042        for item in d.services: 
    4143            ll+=', ' 
    4244            if item == 'NDG_A_SERVICE':  
    4345                ll+=hyperlink('data',d.services[item].url) 
     46                ndg=1 
    4447            elif item == 'NDG_B_SERVICE': 
    4548                ll+=hyperlink('metadata',d.services[item].url) 
    4649            else: 
    4750                ll+=hyperlink(item,d.services[item].url) 
    48         return ll 
    49      
    50     def abbreviate(string,newlen): 
    51         ''' We want to ensure that a particular block of text does not exceed 
    52         a specific length - and finishes on a word boundary. ''' 
    53         if len(string)< newlen: 
    54             return string 
    55         else: 
    56             r='' 
    57             for w in string[0:newlen].split(' ')[:-1]:r+='%s '%w 
    58             r+=' ...' 
    59             return r 
     51        return ndg,ll 
     52 
    6053     
    6154    # ################################## 
     
    6558    # depending on keyword options, provide column headings 
    6659    # 
    67     columns=['Dataset','Repository']    
    68     if spatial: columns.insert(-1,'Location') 
     60     
     61    columns=['Dataset',]    
     62    if spatial: columns.append('Location') 
    6963    if temporal:  
    7064        #two columns for temporal but put a column header across both columns 
    71         header='''<table><tbody><tr><td colspan="2" align="center">Temporal Coverage</td></tr><tr> 
    72         <td align="center">Start Date</td><td align="center"> End Date</td></tr></tbody></table>''' 
    73         columns.insert(-1,(header,2)) 
     65        header='''<table><tbody><tr><td colspan="2" align="center">Time&nbsp;Coverage</td></tr><tr> 
     66        <td align="center">Start</td><td align="center"> End</td></tr></tbody></table>''' 
     67        columns.append((header,2)) 
    7468    html='<div class="ListOfResults"><table><tbody>'+row(columns,bgcolor="rbgBeige") 
    7569     
     
    8074        bgc={1:'rbgWhite',-1:'rbgGrey'}[i] 
    8175        i=-1*i 
    82         rlist=[abbreviate(d.name,60),d.centre.toHTML()] 
    83         if summary: 
    84             rlist[0]='Name: %s'%rlist[0] 
    85             rlist[0]+='<br/>Summary: %s'%abbreviate(d.abstract,200) 
    86         if services: 
    87             rlist[0]+=serviceList(d) 
    88         if spatial: rlist.insert(-1,spatialBox(d)) 
    89         if temporal:  
    90             rlist.insert(-1,d.timeCoverage[0]) 
    91             rlist.insert(-1,d.timeCoverage[1]) 
    92          
    93          
    94         html+=row(rlist,bgcolor=bgc) 
     76        ndg,slist=serviceList(d) 
     77        if d.elem is None: 
     78            html+='<tr class="%s"><td colspan="%s"> Unparseable record </td></tr>'%(bgc,len(columns)) 
     79        else: 
     80            rlist=[abbreviate(d.name,60),] 
     81            if summary: 
     82                rlist[0]='%s: %s'%(span('Name','ndgem'),rlist[0]) 
     83                rlist[0]+='<br/>%s: %s'%(span('Summary','ndgem'),abbreviate(d.abstract,200)) 
     84            rlist[0]+='<br/>%s: %s.'%(span('Repository','ndgem'),d.centre.toHTML()) 
     85            if services:rlist[0]+=slist 
     86            rlist[0]+=',&nbsp;'+selector.target(d.entryID) 
     87            if spatial: rlist.append(spatialBox(d)) 
     88            if temporal:  
     89                rlist.append(htmlTime(d.timeCoverage[0])) 
     90                rlist.append(htmlTime(d.timeCoverage[1])) 
     91            html+=row(rlist,bgcolor=bgc) 
    9592 
    96     html+='</tbody></table></div>' 
     93    html+='</tbody></table>' 
     94    html+='<p>Results %s to %s of %s</p>'%(state.offset,state.offset+state.stride-1,state.hits) 
     95    html+='</div>' 
    9796    return html 
    9897 
     
    101100    from ETxmlView import xmlCleanup 
    102101    ws=DiscoveryWS() 
    103     ws.SearchFullText('acsoe') 
    104     results=ws.GetResults(number=5) 
     102    r=ws.SearchFullText('acsoe') 
     103    hits,time=r['hits'],r['queryTime'] 
     104    results=ws.GetResults(offset=1,number=5) 
    105105    difs=[] 
     106    querystring='dummyUrl' 
     107    state=Discovery(ws.sessionID,queryString,hits,stride=5) 
    106108    #g=file('log.xml','w') 
    107109    for result in results: 
    108110        #g.write(xmlCleanup(result)+'\n') 
    109111        difs.append(xmlCleanup(result)) 
    110     html=renderDiscoverySet(difs,summary=1,spatial=1,temporal=1) 
     112    html=renderDiscoverySet(difs,state,summary=1,spatial=1,temporal=1) 
    111113    f=file('output.html','wb') 
    112114    f.write(html) 
Note: See TracChangeset for help on using the changeset viewer.