Ignore:
Timestamp:
20/04/09 09:32:19 (11 years ago)
Author:
cbyrom
Message:

Move re-usable content in atomeditorcontroller to home controller and
inherit this in the atomeditorcontroller.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MILK/trunk/milk_server/milk_server/controllers/atom_editor/atomeditorcontroller.py

    r5158 r5199  
    44 @author: C Byrom, Tessella Dec 2008 
    55''' 
    6 import logging, xmlrpclib, cgi, traceback 
     6import logging, cgi 
    77from ndg.common.src.models.ndgObject import ndgObject 
    8 from ndg.common.src.lib.utilities import escapeSpecialCharacters 
    9 from ndg.common.src.models.vocabtermdata import VocabTermData as VTD 
    108from milk_server.lib.base import * 
    119from milk_server.models.ndgdoc import NDGDoc  
    1210from editorconstants import * 
    13 from formencode import htmlfill 
     11from milk_server.controllers.home import HomeController 
    1412    
    15 class AtomEditorController(BaseController): 
     13class AtomEditorController(HomeController): 
    1614    '''  
    1715    Provides the pylons controller for shared functions 
     
    9896        logging.debug("Pickleable data extracted") 
    9997        return tidyInputs 
    100  
    101  
    102     def _unpackErrors(self, e): 
    103         ''' 
    104         Add exception errors to the common error structures - for use 
    105         in templates 
    106         @param e: Exception to add 
    107         @return errors: dict of errors 
    108         ''' 
    109         if not c.errors: 
    110             c.errors = {} 
    111  
    112         errorMessage = e.message 
    113         if g.debugModeOn == 'True': 
    114             errorMessage = traceback.format_exc() 
    115  
    116         c.xml = escapeSpecialCharacters('Unexpected error loading page [%s]' \ 
    117                                         %str(errorMessage)) 
    118         c.doc = '' 
    119          
    120         # unpack errors, if possible - NB, the c.errors value is used by the template 
    121         # function, displayErrors, which is used by most of the editor templates 
    122         if isinstance(e, xmlrpclib.Fault): 
    123             # strip out the exception type - NB, this is usually native library code 
    124             # and is of no real interest - and will just confuse viewers 
    125             c.errors['Unexpected error'] = e.faultString.split(':')[-1]  
    126  
    127         if hasattr(e, 'unpack_errors'): 
    128             c.errors.update(e.unpack_errors()) 
    129              
    130         else: 
    131             c.errors['Unexpected error'] = [c.xml] 
    132  
    133         # tidy up errors - escaping any xml tags, if necessary 
    134         for key, errors in c.errors.items(): 
    135             newErrors = [] 
    136             for error in errors: 
    137                 for err in error.split('<br/>'): 
    138                     newErrors.append(escapeSpecialCharacters(err)) 
    139             c.errors[key] = newErrors 
    140          
    141         return c.errors 
    142  
    143  
    144     def _handleError(self, e, template='error'): 
    145         ''' 
    146         Handle exceptions thrown; if debug mode on, display full stack trace 
    147         in output, otherwise just show basic error message in error template 
    148         @param e: Exception to process 
    149         @keyword template: template to render - 'error' is the default - NB, if 
    150         an alternative is specified it should have a div with class set to 'error' 
    151         containing the variable, c.xml to display properly  
    152         ''' 
    153         self._unpackErrors(e) 
    154         logging.error(c.xml) 
    155         response.status_code = 400 
    156         return render("genshi", template) 
    157  
    158  
    159     def savePageAndRender(self, template, **inputs): 
    160         ''' 
    161         Save the current path info - to provide a memory function when changing 
    162         tabs + render the given template with the specified inputs filled in 
    163         automatically 
    164         @param template: name of template to render 
    165         @param inputs: dict of inputs with keynames matching input names in template 
    166         form   
    167         ''' 
    168         logging.debug("Saving current page url (%s) - to keep track of atom editor state" \ 
    169                       %self.pathInfo) 
    170         session['currentEditor'] = self.pathInfo 
    171         session.save() 
    172         logging.debug("Now rendering current template (%s)" %template) 
    173         html = render("genshi", template) 
    174          
    175         # replace any browse links with to links to editor 
    176         html = html.replace(VTD.BROWSE_SERVER_URL, g.server) 
    177          
    178         # NB, need html in unicode for for htmlfill.render 
    179         html = unicode(html, 'utf-8', 'xmlcharrefreplace') 
    180         for key, val in inputs.items(): 
    181             inputs[key] = str(val) 
    182  
    183         return htmlfill.render(html, inputs) 
Note: See TracChangeset for help on using the changeset viewer.