Changeset 2528 for TI07-MOLES/trunk/PythonCode/wsgi/renderDiscoverySet.py
- Timestamp:
- 30/05/07 16:44:15 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TI07-MOLES/trunk/PythonCode/wsgi/renderDiscoverySet.py
r2487 r2528 49 49 50 50 51 def renderDiscoverySet(difSet,state,config,summary=0,services=0,spatial=0,temporal=0, 52 linkto='NDG_B_SERVICE',selector=None): 51 def renderDiscoverySet(difSet,state,config, linkto='NDG_B_SERVICE',selector=None): 53 52 '''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 59 54 linkto (string) - clicking on the select widget should add the url for 60 55 this service to the selected list … … 67 62 # List of methods which deal with the actual row content ... 68 63 # 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 79 83 def spatialBox(elem): 80 84 return elem.bbox.toHTMLbox() … … 107 111 # ################################## 108 112 109 # depending on keyword options, provide column headings 110 # 113 # previous versions of this code had options, but let's simplify this a lot ... 111 114 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 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 Coverage','(-ve:W,S;','+ve:N,E)')) 116 temporal=doubleheader(('Temporal Coverage','Start','End')) 117 columns=['Dataset',spatial,temporal] 118 html='<table><tbody>'+row(columns,rclass="rbgBeige") 120 119 121 120 # ok, now let's cycle through the hits 122 121 i=1 123 122 for item in difSet: 124 #print item.entryID125 123 d=item # we used to do the diffing here ... but we don't anymore 126 124 bgc={1:'rbgWhite',-1:'rbgGrey'}[i] 127 125 i=-1*i 128 if debug: print 'Rendering ',d.entryID129 126 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 131 128 else: 132 129 ndg,slist=serviceList(d) 133 130 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) 141 137 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 145 139 if ndg and selector !=None: 146 140 rlist[0]+=', '+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) 153 145 154 146 html+='</tbody></table>'
Note: See TracChangeset
for help on using the changeset viewer.