source: TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/renderDiscoverySet.py @ 996

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/renderDiscoverySet.py@996
Revision 996, 3.0 KB checked in by lawrence, 16 years ago (diff)

Further changes associated with the browse/discovery
look and feel

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