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

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

Fixes for ticket:722, changing to internal unicode (probably not complete),
with decode on the edge coming out ... fixes 722 but may have some
other problems now ...

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            #Apr 25, removed for ticket: 722, I should have documented which ticket it was a bug fix for ...
26            #description=service.description.decode('utf-8')
27            description=service.description
28        x=('<a href="%s" title="%s"><img src="%s" alt="%s"/></a>'%(
29                url,description,icon,alt),description)
30        return x
31
32import unittest
33from ServiceBinding import DIFService
34from Utilities import myConfig
35
36configFile='examples/example.config'
37class TestCase(unittest.TestCase):
38
39    def testDIFBinding(self):
40        ''' Tests a DIF binding does the right thing '''
41       
42        s=DIFService('NDG_B_SERVICE','grid.bodc.rl.ac.uk','The NDG service for browsing metadata')
43        c=myConfig(configFile)
44        x=renderService(c)
45        h=x.get(s)
46        print h
47       
48    def testOdditity(self):
49        '''Tests a specific record for misbehaviour'''
50        from ndgRetrieve import ndgRetrieve
51        from DIF import DIF
52        from ndgObject import ndgObject
53        testURI='grid.bodc.nerc.ac.uk:DIF:EDMED1048008'
54        testURI='ndg.noc.soton.ac.uk__DIF__NOCSDAT162'
55        inputs={'repository':'glue.badc.rl.ac.uk','uri':testURI,'format':'DIF','type':'xml','original':'1'}
56        retriever=ndgRetrieve('./')
57        ctype,r=retriever._present(inputs,'text/xml')
58        con=myConfig(configFile)
59        obj=ndgObject(testURI)
60        obj.setConfig(con)
61        d=DIF(r,ndgObj=obj)
62        for s in d.services:
63            h=renderService(con)
64            html= h.get(s)[0]
65
66       
67if __name__=="__main__":
68    unittest.main()
69       
Note: See TracBrowser for help on using the repository browser.