source: TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/brow @ 1162

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/brow@1162
Revision 1162, 5.2 KB checked in by lawrence, 14 years ago (diff)

Made a subversion error, this is a temporary move ...
will fix shortly

Line 
1from DiscoveryWS import DiscoveryWS,DiscoveryState
2from DIF import DIF
3from htmlUtilities import *
4
5def renderDiscoverySet(difSet,state,selector=None,summary=0,services=0,spatial=0,temporal=0,
6    linkto='NDG_B_SERVICE'):
7    '''Takes a set of xml DIFS from a discovery search (difSet) and renders a
8    list of responses as a table, 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 select widget should add the url for
14                              this service to the selected list
15     Note that state is a DiscoveryState instance containing the sessionID from the search,
16     and the offset, stride, and total number of results ...selector is a class for adding
17     particular datasets to a selection dataset (and cookie).
18     '''
19           
20    #
21    # List of methods which deal with the actual row content ...
22    #   
23   
24    def row(rowList,bgcolor='rbgWhite'):
25        h='<tr class="%s">'%bgcolor
26        for item in rowList:
27            if type(item)==type((1,2)):
28                h+='<td colspan="%s">%s</td>'%(item[1],item[0])
29            else:h+='<td>%s</td>'%item
30        h+='</tr>'
31        return h#span(h,bgcolor)
32
33    def spatialBox(elem):
34        return elem.bbox.toHTMLbox()
35     
36    def temporalRange(elem):
37        return ''
38   
39    def serviceList(d):
40        ll=span(' Links: ','ndgem')
41        ndg=0
42        s=1
43        for item in d.services:
44            if not s: ll+=', '
45            s=0
46            if item.serviceType == 'NDG_A_SERVICE':
47                ll+=item.icon()
48                ndg+=1
49            elif item.serviceType == 'NDG_B_SERVICE':
50                ndg+=1
51                ll+=item.icon()
52            else:
53                ll+=item.icon()
54        if ndg<2: ndg=0
55        return ndg,ll
56
57   
58    # ##################################
59    # Actual html production follows
60    # ##################################
61   
62    # depending on keyword options, provide column headings
63    #
64   
65    columns=['Dataset',]   
66    if spatial: columns.append('Location')
67    if temporal:
68        #two columns for temporal but put a column header across both columns
69        header='''<table><tbody><tr><td colspan="2" align="center">Time&nbsp;Coverage</td></tr><tr>
70        <td align="center">Start</td><td align="center"> End</td></tr></tbody></table>'''
71        columns.append((header,2))
72    html='<div class="ListOfResults"><table><tbody>'+row(columns,bgcolor="rbgBeige")
73   
74    # ok, now let's cycle through the hits
75    i=1
76    for item in difSet:
77        d=item # we used to do the diffing here ... but we don't anymore
78        bgc={1:'rbgWhite',-1:'rbgGrey'}[i]
79        i=-1*i
80       
81        if d.elem is None:
82            html+='<tr class="%s"><td colspan="%s"> Unparseable record </td></tr>'%(bgc,len(columns))
83        else:
84            ndg,slist=serviceList(d)
85            rlist=[abbreviate(d.name,60),]
86            if summary:
87                rlist[0]='%s: %s'%(span('Name','ndgem'),rlist[0])
88                rlist[0]+='<br/>%s: %s'%(span('Summary','ndgem'),abbreviate(d.abstract,200))
89                rlist[0]+=' '+hyperlink('(more)',d.entryID)
90            rlist[0]+='<br/>%s: %s.'%(span('Repository','ndgem'),d.centre.toHTML())
91            if not summary:
92                rlist[0]+=' '+hyperlink('(more)',d.entryID)
93            if services:rlist[0]+=slist
94            if ndg and selector !=None: rlist[0]+=',&nbsp;'+selector.target(d.entryID)
95            if spatial: rlist.append(spatialBox(d))
96            if temporal:
97                rlist.append(htmlTime(d.timeCoverage[0]))
98                rlist.append(htmlTime(d.timeCoverage[1]))
99            html+=row(rlist,bgcolor=bgc)
100
101    html+='</tbody></table>'
102   
103    #now work out the links to step through a large result set
104    html+='<p>Results %s to %s of %s'%(state.offset,min(state.offset+state.stride-1,state.hits),state.hits)
105    if state.stride < state.hits and selector is not None:
106        if state.offset+state.stride-1<state.hits:
107            next1=state.offset+state.stride
108            nextNum=min(next1+state.stride,state.hits)-next1
109            s1='Next %s'%nextNum
110            nexturl='%s&start=%s&howmany=%s'%(selector.baseURL,next1,nextNum)
111            html+=', %s'%hyperlink(s1,nexturl)
112        if state.offset>1:
113            last1=state.offset-state.stride
114            lastNum=state.stride
115            l1='Last %s'%lastNum
116            lasturl='%s&start=%s&howmany=%s'%(selector.baseURL,last1,lastNum)
117            html+=', %s'%hyperlink(l1,lasturl)
118    else:
119        html+='</p>'
120    html+='</div>'
121    return html
122
123if __name__=="__main__":
124
125    ws=DiscoveryWS()
126    hits=ws.SearchFullText('acsoe')
127    results=ws.GetResults(offset=1,number=5)
128    difs=[]
129    querystring='dummyUrl'
130    state=DiscoveryState(ws.sessID,querystring,hits,stride=5)
131    #g=file('log.xml','w')
132    for result in results:
133        #g.write(xmlCleanup(result)+'\n')
134        difs.append(DIF(result,serviceFile='serviceMap.config'))
135    html=renderDiscoverySet(difs,state,summary=1,spatial=1,temporal=1)
136    f=file('output.html','wb')
137    f.write(html)
138    ws.release()
Note: See TracBrowser for help on using the repository browser.