# Changeset 2340 for TI07-MOLES/trunk/PythonCode/wsgi/renderDiscoverySet.py

Ignore:
Timestamp:
28/03/07 12:26:31 (14 years ago)
Message:

Bug fixes and test cases for ticket:672

File:
1 edited

Unmodified
Added
Removed
• ## TI07-MOLES/trunk/PythonCode/wsgi/renderDiscoverySet.py

 r2330 from renderService import * debug=1 def CalculateStride(start,stride,total): ''' Work out the previous and next chunks, returns a list of lists, the first of which is the start and offset of the next chunk, the second of which is the staft and offset of the previous chunk ''' result=[] defStride=10 if start+stridetotal: r[1]=total+1-r[0] result.append(r) else:result.append([]) if start>1: #there are previous records b=max(stride,defStride) r=[start-b,b] if r[0]<1: r[0]=1 if r[1]>total: r[1]=total result.append(r) else: result.append([]) return result def htmlStride(state): ''' Given the previous and next list from CalculateStride, and the current state class (which provides a method for the fundamental URL, return a previous next piece of html ''' html='

Results %s to %s of %s'%(state.offset,state.offset+state.stride-1,state.hits) r=CalculateStride(state.offset,state.stride,state.hits) if r[0]<>[]: s1='Next %s'%r[0][1] nexturl=state.geturl(offset=r[0][0],stride=r[0][1]) html+=', %s'%hyperlink(s1,nexturl) if r[1]<>[]: l1='Previous %s'%r[1][1] lasturl=state.geturl(offset=r[1][0],stride=r[1][1]) html+=', %s'%hyperlink(l1,lasturl) html+='.

' return html def renderDiscoverySet(difSet,state,config,summary=0,services=0,spatial=0,temporal=0, linkto='NDG_B_SERVICE',selector=None): html+='' #now work out the links to step through a large result set #html+='

Results %s to %s of %s'%(state.offset,min(state.offset+state.stride-1,state.hits),state.hits) html+='

Results %s to %s of %s'%(state.offset,state.offset+len(difSet)-1,state.hits) if state.stride < state.hits: #1,10,21   11,20,21  21,21,21 if state.offset+state.stride-11: last1=max(1,state.offset-state.stride) lastNum=min(state.stride,1+state.hits-last1) if lastNum' return html import unittest class TestCase(unittest.TestCase): def testStrideself(self): ''' Test striding through a dataset ''' res=CalculateStride(1,10,15) self.assertEqual([[11,5],[]],res) res=CalculateStride(11,5,15) self.assertEqual([[],[1,10]],res) res=CalculateStride(11,10,50) self.assertEqual([[21,10],[1,10]],res) def testHtmlStride(self): ''' Test the html striding part ''' DummyEnviron={'QUERY_STRING':'start=10&howmany=10','HTTP_HOST':'example.ndg', 'PATH_INFO':'/discovery','wsgi.url_scheme':'http','SERVER_PORT':'80'} d=DiscoveryState('123',DummyEnviron,12) html=htmlStride(d) print html if __name__=="__main__": unittest.main()

Note: See TracChangeset for help on using the changeset viewer.