1 | from DiscoveryWS import DiscoveryWS |
---|
2 | from DIF import DIF |
---|
3 | from Utilities import cleanup |
---|
4 | |
---|
5 | def render(difSet,summary=0,services=0,spatial=0,temporal=0,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 | # List of methods which deal with the actual row content ... |
---|
9 | columns=['Dataset','Repository'] |
---|
10 | |
---|
11 | def row(rowList,bgcolor='#EEEEEE'): |
---|
12 | h='<tr bgcolor="%s">'%bgcolor |
---|
13 | for item in rowList: |
---|
14 | print item |
---|
15 | if type(item)==type((1,2)): |
---|
16 | h+='<td colspan="%s">%s</td>'%(item[1],item[0]) |
---|
17 | else:h+='<td>%s</td>'%item |
---|
18 | h+='</tr>' |
---|
19 | return h |
---|
20 | |
---|
21 | def spatialBox(elem): |
---|
22 | return elem.bbox.toHTMLbox() |
---|
23 | |
---|
24 | def temporalRange(elem): |
---|
25 | return '' |
---|
26 | |
---|
27 | def serviceList(elem): |
---|
28 | return '' |
---|
29 | |
---|
30 | #next three lines not yet used in anger |
---|
31 | if spatial: columns.insert(-1,'Location') |
---|
32 | if temporal: |
---|
33 | #two columns for temporal but put a column header across both columns |
---|
34 | header='''<table><tr><td colspan="2">Temporal Coverage</td></tr><tr> |
---|
35 | <td>Start Date</td><td> End Date</td></tr></table>''' |
---|
36 | columns.insert(-1,(header,2)) |
---|
37 | if services: columns.insert(-1,'Services') |
---|
38 | html='<table><tbody>'+row(columns,bgcolor="#FDFFCC") |
---|
39 | |
---|
40 | i=1 |
---|
41 | for item in difSet: |
---|
42 | d=DIF(item) |
---|
43 | bgc={1:'#FFFFFF',-1:'#EEEEEE'}[i] |
---|
44 | i=-1*i |
---|
45 | rlist=[d.name[0:60],d.centre.toHTML()] |
---|
46 | if summary: |
---|
47 | rlist[0]='Name: '+rlist[0] |
---|
48 | rlist[0]+='</br>Summary: %s'%d.abstract[0:200] |
---|
49 | rlist[0]+='<br/>+' |
---|
50 | if spatial: rlist.insert(-1,spatialBox(d)) |
---|
51 | if temporal: |
---|
52 | rlist.insert(-1,d.timeCoverage[0]) |
---|
53 | rlist.insert(-1,d.timeCoverage[1]) |
---|
54 | if services: rlist.insert(-1,serviceList(d)) |
---|
55 | |
---|
56 | html+=row(rlist,bgcolor=bgc) |
---|
57 | |
---|
58 | html+='</tbody></table>' |
---|
59 | return html |
---|
60 | |
---|
61 | if __name__=="__main__": |
---|
62 | ws=DiscoveryWS() |
---|
63 | ws.SearchFullText('acsoe') |
---|
64 | results=ws.GetResults(number=5) |
---|
65 | difs=[] |
---|
66 | for result in results: |
---|
67 | difs.append(cleanup(result)) |
---|
68 | html=render(difs,summary=1,spatial=1,temporal=1) |
---|
69 | f=file('output.html','wb') |
---|
70 | f.write(html) |
---|
71 | ws.release() |
---|