source: TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/renderDiscoveryResponses.py @ 963

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

Coding to support showing full xml documents etc in browse, note
not tested as underlying web services not workign at moment.

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