Ignore:
Timestamp:
30/05/07 16:44:15 (12 years ago)
Author:
lawrence
Message:

Improvements associated with ticket:733

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI07-MOLES/trunk/PythonCode/wsgi/renderDiscoverySet.py

    r2487 r2528  
    4949     
    5050         
    51 def renderDiscoverySet(difSet,state,config,summary=0,services=0,spatial=0,temporal=0, 
    52     linkto='NDG_B_SERVICE',selector=None): 
     51def renderDiscoverySet(difSet,state,config, linkto='NDG_B_SERVICE',selector=None): 
    5352    '''Takes a set of xml DIFS from a discovery search (difSet) and renders a  
    54     list of responses as a table, with layout depending on a set of keywords: 
    55             summary (boolean) - show the abstract, 
    56             services (boolean) - show the service list, 
    57             spatial (boolean) - show the bounding box, 
    58             temporal (boolean) - show the date range, 
     53    list of responses as a table. The argument is  
    5954            linkto (string) - clicking on the select widget should add the url for 
    6055                              this service to the selected list 
     
    6762    # List of methods which deal with the actual row content ... 
    6863    #    
    69      
    70     def row(rowList,bgcolor='rbgWhite'): 
    71         h='<tr class="%s">'%bgcolor 
    72         for item in rowList: 
    73             if type(item)==type((1,2)): 
    74                 h+='<td colspan="%s">%s</td>'%(item[1],item[0]) 
    75             else:h+='<td>%s</td>'%item 
    76         h+='</tr>' 
    77         return h#span(h,bgcolor) 
    78  
     64    def doubleheader(args): 
     65        return '''<table><tbody><tr><td colspan="2" align="center">%s</td></tr> 
     66                  <tr><td align="center">%s</td><td align="center">%s</td></tr></tbody></table>'''%args 
     67    def row(rowlist,rclass='rbgWhite'): 
     68        print rowlist 
     69        r= '''<tr class="%s"><td width="70%%">%s</td><td width="12%%" align="center">%s</td> 
     70            '''%(rclass,rowlist[0],rowlist[1]) 
     71        ll=len(rowlist) 
     72        print 'BBB[',rowlist[2:],']' 
     73         
     74        if ll==3: 
     75            r+='<td align="center" colspan="2" width="12%%">%s</td></tr>'%rowlist[2] 
     76        elif ll==4: 
     77            r+='<td align="center">%s</td><td align="center">%s</td></tr>'%tuple(rowlist[2:]) 
     78        else: 
     79            raise 'Coding error in renderDiscovery' 
     80        print 'ok' 
     81        return r 
     82         
    7983    def spatialBox(elem): 
    8084        return elem.bbox.toHTMLbox() 
     
    107111    # ################################## 
    108112     
    109     # depending on keyword options, provide column headings 
    110     # 
     113    # previous versions of this code had options, but let's simplify this a lot ... 
    111114     
    112     columns=['Dataset',]    
    113     if spatial: columns.append('Location') 
    114     if temporal:  
    115         #two columns for temporal but put a column header across both columns 
    116         header='''<table><tbody><tr><td colspan="2" align="center">Time&nbsp;Coverage</td></tr><tr> 
    117         <td align="center">Start</td><td align="center"> End</td></tr></tbody></table>''' 
    118         columns.append((header,2)) 
    119     html='<table><tbody>'+row(columns,bgcolor="rbgBeige") 
     115    spatial=doubleheader(('Spatial&nbsp;Coverage','(-ve:W,S;','+ve:N,E)')) 
     116    temporal=doubleheader(('Temporal&nbsp;Coverage','Start','End')) 
     117    columns=['Dataset',spatial,temporal]  
     118    html='<table><tbody>'+row(columns,rclass="rbgBeige") 
    120119     
    121120    # ok, now let's cycle through the hits 
    122121    i=1 
    123122    for item in difSet: 
    124         #print item.entryID 
    125123        d=item # we used to do the diffing here ... but we don't anymore 
    126124        bgc={1:'rbgWhite',-1:'rbgGrey'}[i] 
    127125        i=-1*i 
    128         if debug: print 'Rendering ',d.entryID 
    129126        if d.tree is None: 
    130             html+='<tr class="%s"><td colspan="%s"> Unparseable record </td></tr>'%(bgc,len(columns)) 
     127            html+='<tr class="%s"><td colspan="4"> Unparseable record </td></tr>'%bgc 
    131128        else: 
    132129            ndg,slist=serviceList(d) 
    133130            rlist=['',] 
    134             if summary: 
    135                 if d.briefCitation <>'': 
    136                     rlist[0]='%s: %s'%(span('Citation','ndgem'),d.briefCitation) 
    137                 else: 
    138                     rlist[0]='%s: %s'%(span('Title','ndgem'),abbreviate(d.name,60)) 
    139                 rlist[0]+='<br/>%s: %s'%(span('Summary','ndgem'),abbreviate(d.abstract,200)) 
    140                 if d.binding is not None: rlist[0]+=' '+hyperlink('(more)',d.binding.url) 
     131            if d.briefCitation <>'': 
     132                rlist[0]='%s: %s'%(span('Citation','ndgem'),d.briefCitation) 
     133            else: 
     134                rlist[0]='%s: %s'%(span('Title','ndgem'),abbreviate(d.name,60)) 
     135            rlist[0]+='<br/>%s: %s'%(span('Summary','ndgem'),abbreviate(d.abstract,200)) 
     136            if d.binding is not None: rlist[0]+=' '+hyperlink('(more)',d.binding.url) 
    141137            rlist[0]+='<br/>%s: %s.'%(span('Repository','ndgem'),d.centre.url()) 
    142             if not summary and d.binding is not None: 
    143                 rlist[0]+=' '+hyperlink('(more)',d.binding.url) 
    144             if services:rlist[0]+=slist 
     138            rlist[0]+=slist 
    145139            if ndg and selector !=None:  
    146140                rlist[0]+=',&nbsp;'+selector.target(d.entryID,name=d.abbreviation) 
    147             if spatial: rlist.append(spatialBox(d)) 
    148             if temporal:  
    149                 rlist.append(htmlTime(d.timeCoverage[0])) 
    150                 rlist.append(htmlTime(d.timeCoverage[1])) 
    151             html+=row(rlist,bgcolor=bgc) 
    152         print 'Completed rendering ',d.entryID 
     141            rlist.append(spatialBox(d)) 
     142            rlist.append(htmlTime(d.timeCoverage[0])) 
     143            rlist.append(htmlTime(d.timeCoverage[1])) 
     144            html+=row(rlist,rclass=bgc) 
    153145 
    154146    html+='</tbody></table>' 
Note: See TracChangeset for help on using the changeset viewer.