1 | from DiscoveryWS import DiscoveryWS |
---|
2 | from DIF import DIF |
---|
3 | |
---|
4 | def renderDiscoverySet(difSet,summary=0,services=0,spatial=0,temporal=0, |
---|
5 | 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: |
---|
8 | summary (boolean) - show the abstract, |
---|
9 | services (boolean) - show the service list, |
---|
10 | spatial (boolean) - show the bounding box, |
---|
11 | temporal (boolean) - show the date range, |
---|
12 | linkto (string) - clicking on the name should go to a service binding to this url |
---|
13 | ''' |
---|
14 | # |
---|
15 | # List of methods which deal with the actual row content ... |
---|
16 | # |
---|
17 | def row(rowList,bgcolor='#EEEEEE'): |
---|
18 | h='<tr bgcolor="%s">'%bgcolor |
---|
19 | for item in rowList: |
---|
20 | print item |
---|
21 | if type(item)==type((1,2)): |
---|
22 | h+='<td colspan="%s">%s</td>'%(item[1],item[0]) |
---|
23 | else:h+='<td>%s</td>'%item |
---|
24 | h+='</tr>' |
---|
25 | return h |
---|
26 | |
---|
27 | def spatialBox(elem): |
---|
28 | return elem.bbox.toHTMLbox() |
---|
29 | |
---|
30 | def temporalRange(elem): |
---|
31 | return '' |
---|
32 | |
---|
33 | def serviceList(elem,linkDefault): |
---|
34 | return '' |
---|
35 | |
---|
36 | # ################################## |
---|
37 | # Actual html production follows |
---|
38 | # ################################## |
---|
39 | |
---|
40 | # depending on keyword options, provide column headings |
---|
41 | # |
---|
42 | columns=['Dataset','Repository'] |
---|
43 | if spatial: columns.insert(-1,'Location') |
---|
44 | if temporal: |
---|
45 | #two columns for temporal but put a column header across both columns |
---|
46 | header='''<table><tr><td colspan="2" align="center">Temporal Coverage</td></tr><tr> |
---|
47 | <td align="center">Start Date</td><td align="center"> End Date</td></tr></table>''' |
---|
48 | columns.insert(-1,(header,2)) |
---|
49 | if services: columns.insert(-1,'Services') |
---|
50 | html='<div class="ListOfResults"><table><tbody>'+row(columns,bgcolor="#FDFFCC") |
---|
51 | |
---|
52 | # ok, now let's cycle through the hits, nb, look and feel should be |
---|
53 | # factored out to css .. |
---|
54 | |
---|
55 | i=1 |
---|
56 | for item in difSet: |
---|
57 | d=DIF(item) |
---|
58 | bgc={1:'#FFFFFF',-1:'#EEEEEE'}[i] |
---|
59 | i=-1*i |
---|
60 | rlist=[d.name[0:60],d.centre.toHTML()] |
---|
61 | if summary: |
---|
62 | rlist[0]='Name: '+rlist[0] |
---|
63 | rlist[0]+='</br>Summary: %s'%d.abstract[0:200] |
---|
64 | rlist[0]+='<br/>+' |
---|
65 | if spatial: rlist.insert(-1,spatialBox(d)) |
---|
66 | if temporal: |
---|
67 | rlist.insert(-1,d.timeCoverage[0]) |
---|
68 | rlist.insert(-1,d.timeCoverage[1]) |
---|
69 | if services: rlist.insert(-1,serviceList(d,linkto)) |
---|
70 | |
---|
71 | html+=row(rlist,bgcolor=bgc) |
---|
72 | |
---|
73 | html+='</tbody></table></div>' |
---|
74 | return html |
---|
75 | |
---|
76 | if __name__=="__main__": |
---|
77 | |
---|
78 | from ETxmlView import xmlCleanup |
---|
79 | ws=DiscoveryWS() |
---|
80 | ws.SearchFullText('acsoe') |
---|
81 | results=ws.GetResults(number=5) |
---|
82 | difs=[] |
---|
83 | for result in results: |
---|
84 | difs.append(xmlCleanup(result)) |
---|
85 | html=renderDiscoverySet(difs,summary=1,spatial=1,temporal=1) |
---|
86 | f=file('output.html','wb') |
---|
87 | f.write(html) |
---|
88 | ws.release() |
---|