source: TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/controllers/master.py @ 5226

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/controllers/master.py@5226
Revision 5226, 2.2 KB checked in by cbyrom, 12 years ago (diff)

Initial check in of code for the OAI Info Editor pylons based web app.

This includes basic controllers for viewing provider info - with the
associated repository info. Also included is the model and dal layer,
allowing the provider info to be processed and imported/exported to
XML file. Unit tests for the dal and model packages are included.
Templates for rendering provider and repository info are included.

  • Property svn:executable set to *
Line 
1'''
2 Class representing the top level pylons controller with functionality shared
3 across the different controllers - which should inherit this one
4 
5 @author: C Byrom, Tessella Apr 2009
6'''
7import logging, urllib, datetime, re
8from oai_info_editor.lib.base import *
9import oai_info_editor.lib.constants as constants
10
11class MasterController(BaseController):
12
13           
14    def _setUpController(self, providerName = None):
15        '''
16        Set up anything that may be of use to various controllers
17        @keyword providerName: name of provider related to currently viewed data - used
18        to refined the providerInfos data available to the templates
19        '''
20        self.cf = request.environ['appConfig']
21       
22        # TODO: determine the ID of the current user
23        userID = 'calum'
24       
25        if not userID in g.users:
26            raise ValueError("Unrecognised user, '%s' - access to editor denied" %userID)
27       
28        c.user = g.users[userID]
29        c.providerInfos = g.dao.getProviderInfoForUser(c.user)
30        if providerName and providerName != constants.ALL_PROVIDER_IDS:
31            pis = []
32            logging.debug("- refining provider info list to include only data from provider, '%s'"
33                          %providerName)
34            for pi in c.providerInfos:
35                if pi.name == providerName:
36                    pis.append(pi)
37            c.providerInfos = pis
38           
39        # get any inputs POSTED from forms
40        self.inputs = request.params
41
42
43    def _renderTemplate(self, type, template):
44        '''
45        Render templates in a consistent manner - to catch errors in the same way
46        - allowing these to be displayed better
47        @param type: type of template to use - e.g. 'kid' or 'genshi'
48        @param template: template to render
49        '''
50        logging.debug("Rendering '%s' style template, '%s'" %(type, template))
51        try:
52            html = render(type, template)
53            logging.debug("- rendering completed successfully - returning data")
54            return html
55        except Exception, e:
56            logging.error("Problem occured whilst rendering template: %s" %e)
57            c.errors = {'Rendering error': e}
58            return render('genshi', 'error')
Note: See TracBrowser for help on using the repository browser.