source: TI07-MOLES/trunk/PythonCode/wsgi/ndgPageLayout.py @ 1934

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

more minor modifications to wsgi browse

Line 
1from Utilities import myConfig
2from paste.request import parse_querystring
3
4def DiscoveryFrameFactory(global_config,**local_conf):
5   
6    ''' This factory is intended to be used by paste-deploy to return
7    the discovery FRAME wsgi MIDDLEWARE application, configured to use the configDir
8    to find local configuration information '''
9   
10    if 'configDir' in local_conf.keys():
11        configDir=local_conf[configDir]
12    else:
13        try:
14            configDir=global_config['configDir']
15        except:
16            configDir=None
17           
18    configFile=configDir+'ndgDiscovery.config'
19   
20    def filter(app):
21        return DiscoveryFrame(app,'NERC DataGrid: Data Portal',configFile)
22   
23    return filter
24
25class DiscoveryFrame(object):
26     
27    def __init__(self, wrapTarget,pageName,configFile=None):
28        ''' This is simple WSGI middleware to provide a page wrapper, will eventually
29        include cookie handling for grabbing a "cart" of datasets '''
30       
31        self.wrapTarget=wrapTarget
32        self.config=myConfig(configFile)
33       
34        helpAddress=self.config.get('SEARCH','helpURL')
35        discoveryURL=self.config.get('SEARCH','discoveryURL')
36        advancedURL=self.config.get('SEARCH','advancedURL')
37
38        self.pageStart='''<?xml version="1.0" encoding="utf-8"?>
39                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
40                 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
41                <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
42                <head>
43                  <meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8"/>
44                  <title>%s</title>
45                  <link media="all, screen" href="layout/ndg.css" type="text/css" rel="stylesheet"/>
46                </head><body><div id="Main">'''%pageName
47       
48        self.header='''
49        <div id="Header">%s</div>'''% self.__buildHeader(configFile)
50       
51        self.disclaimer='''<p> This portal is a pre-alpha release of NDG software.
52        We expect bugs, and things not to work, so please let us know about such problems
53        (please email badc@rl.ac.uk, and include "NDG problem" in the subject line).
54        </p>'''
55       
56        self.discovery='''
57            <div class="simpleSearch">
58            <form action="%s">
59            <center><table><tbody>
60            <tr><td> New search for text in: <input type="radio" name="textTarget" value="All" checked="checked"/> Everything
61                <input type="radio" name="textTarget" value="Authors"/> Authors
62                <input type="radio" name="textTarget" value="Params"/>&nbsp;&nbsp;Parameters
63                (<a href="%s">Advanced Search</a>,&nbsp;<a href="%s">Help</a>)</td></tr>
64            <tr><td><input type="text" size="66" name="searchString"/> <input type="submit"></input></td></tr>
65            </tbody></table></center>
66            <input type="hidden" value="0" name="advanced"/>
67            </form></div>'''%(discoveryURL,advancedURL,helpAddress)
68
69    def __call__(self,environ,start_response):
70        ''' Let's prepend and postpend some stuff'''
71        if ('type','xml') in parse_querystring(environ):
72            response=['''<?xml version="1.0" encoding="utf-8"?>''']
73            footer=0
74        else:
75            footer=1
76            response=[self.pageStart,self.header]
77        if environ['SCRIPT_NAME']=='/discovery':
78            insert=self.disclaimer
79        else:
80            insert=self.discovery+self.disclaimer
81        self.footer='''<div id="Footer">%s</div></div></body></html>'''%insert
82        for i in self.wrapTarget(environ,start_response): response.append(i)
83        if footer: response.append(self.footer)
84        return response
85       
86       
87    def __buildHeader(self,configFile):
88       
89        if configFile is None: return ''
90        config=myConfig(configFile)
91        localLink=config.get('layout','localLink',None)
92        localImage=config.get('layout','localImage',None)
93        localAlt=config.get('layout','localAlt','Visit Local Site')
94        ndgLink=config.get('layout','ndgLink','http://ndg.nerc.ac.uk')
95        ndgImage=config.get('layout','ndgImage',None)
96        ndgAlt=config.get('layout','ndgAlt','Visit NDG')
97        PageLogo=config.get('layout','pageLogo',None)
98       
99        banner='''   
100            <table cellpadding="0" cellspacing="0" width="100%%">
101            <tbody><tr>
102            <td width="10%%" align="center" valign="middle">
103              <a href="%s"> <img src="%s" alt="%s"/> </a> </td>
104            <td width="80%%" align="center" valign="middle" >
105              Natural Environment Research Council<br/>
106              Data Discovery Service</td>
107            <td width="10%%" align="center" valign="middle">
108              <a href="%s"> <img src="%s" alt="%s"/> </a> </td>
109            </tr>
110            </tbody></table>'''%(ndgLink,ndgImage,ndgAlt,localLink,localImage,localAlt)
111       
112        return banner
Note: See TracBrowser for help on using the repository browser.