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

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

Sundry modifications associated with the deployment on glue, and better
options for viewing and downloading the underlying xml records (not yet
complete)

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+=i
83        if footer: response+=self.footer
84        #currently need to coerce response into a string for flup ...
85        return [str(response)]
86       
87       
88    def __buildHeader(self,configFile):
89       
90        if configFile is None: return ''
91        config=myConfig(configFile)
92        localLink=config.get('layout','localLink',None)
93        localImage=config.get('layout','localImage',None)
94        localAlt=config.get('layout','localAlt','Visit Local Site')
95        ndgLink=config.get('layout','ndgLink','http://ndg.nerc.ac.uk')
96        ndgImage=config.get('layout','ndgImage',None)
97        ndgAlt=config.get('layout','ndgAlt','Visit NDG')
98        PageLogo=config.get('layout','pageLogo',None)
99       
100        banner='''   
101            <table cellpadding="0" cellspacing="0" width="100%%">
102            <tbody><tr>
103            <td width="10%%" align="center" valign="middle">
104              <a href="%s"> <img src="%s" alt="%s"/> </a> </td>
105            <td width="80%%" align="center" valign="middle" >
106              Natural Environment Research Council<br/>
107              Data Discovery Service</td>
108            <td width="10%%" align="center" valign="middle">
109              <a href="%s"> <img src="%s" alt="%s"/> </a> </td>
110            </tr>
111            </tbody></table>'''%(ndgLink,ndgImage,ndgAlt,localLink,localImage,localAlt)
112       
113        return banner
Note: See TracBrowser for help on using the repository browser.