source: TI07-MOLES/trunk/PythonCode/wsgi/renderService.py @ 2422

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/PythonCode/wsgi/renderService.py@2422
Revision 2422, 2.3 KB checked in by lawrence, 12 years ago (diff)

Code to support late binding to Browse service

Line 
1
2class renderService:
3    def __init__(self,config):
4        self.config=config
5    def get(self,service):
6        if service.contentType.upper() not in ['NDG_A_SERVICE','NDG_B_SERVICE','DISCOVERY']:
7            section='RELATED'
8        else: section=service.contentType
9        icon=self.config.get(section,'icon')
10        alt=self.config.get(section,'icon_alt')
11        if service.description=='':
12            d=self.config.get(section,'title')
13        else: d=service.description
14        #assume an http link if no protocol binding ...
15        s=service.url.find('://')
16        if s==-1:
17            url='http://%s'%service.url
18        else:
19            url=service.url
20        if service.contentType.upper().find('NDG')<>-1:
21            description=service.description+' Note that NDG services are not currently enabled.'
22        else:
23            #this is a bug fix, and it worries me that I had to do it ... I don't understand why
24            #ideally this should apply to all the attributes of a DIF ...
25            description=service.description.decode('utf-8')
26        x=('<a href="%s" title="%s"><img src="%s" alt="%s"/></a>'%(
27                url,description,icon,alt),description)
28        return x
29
30import unittest
31from ServiceBinding import DIFService
32from Utilities import myConfig
33
34configFile='examples/example.config'
35class TestCase(unittest.TestCase):
36
37    def testDIFBinding(self):
38        ''' Tests a DIF binding does the right thing '''
39       
40        s=DIFService('NDG_B_SERVICE','grid.bodc.rl.ac.uk','The NDG service for browsing metadata')
41        c=myConfig(configFile)
42        x=renderService(c)
43        print x.get(s)
44       
45    def testOdditity(self):
46        '''Tests a specific record for misbehaviour'''
47        from ndgRetrieve import ndgRetrieve
48        from DIF import DIF
49        from ndgObject import ndgObject
50        testURI='grid.bodc.nerc.ac.uk:DIF:EDMED1048008'
51        inputs={'repository':'glue.badc.rl.ac.uk','uri':testURI,'format':'DIF','type':'xml','original':'1'}
52        retriever=ndgRetrieve('./')
53        ctype,r=retriever._present(inputs,'text/xml')
54        con=myConfig(configFile)
55        obj=ndgObject(testURI)
56        obj.setConfig(con)
57        d=DIF(r,ndgObj=obj)
58        for s in d.services:
59            h=renderService(con)
60            print h.get(s)
61
62       
63if __name__=="__main__":
64    unittest.main()
65       
Note: See TracBrowser for help on using the repository browser.