Changeset 5024


Ignore:
Timestamp:
23/02/09 17:18:08 (11 years ago)
Author:
cbyrom
Message:

Allow inputs dict to be passed into ndgdoc - to allow Atom data model
to be set up with predefined inputs + adjust atomeditorcontroller to
use this data model instead of the existing code.

Location:
MILK/trunk/milk_server/milk_server
Files:
2 edited

Legend:

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

    r4998 r5024  
    66import logging, xmlrpclib, cgi, traceback 
    77from ndg.common.src.models.ndgObject import ndgObject 
    8 from ndg.common.src.models.Atom import Atom 
    98from ndg.common.src.lib.utilities import escapeSpecialCharacters 
    109from milk_server.lib.base import * 
    11 from milk_server.lib.ndgInterface import ndgInterface  
    12 from milk_server.lib import Utilities 
     10from milk_server.models.ndgdoc import NDGDoc  
    1311from editorconstants import * 
    1412from formencode import htmlfill 
     
    3432 
    3533        if uri: 
    36             self.ndgObject = ndgObject(uri, config=self.cf) 
     34            self.ndgObject = ndgObject(uri, config = self.cf) 
     35 
     36            self.ndgDoc = NDGDoc(ndgURI = uri, config = self.cf) 
    3737            if loadAtom: 
    3838                self.__prepareDataModel(uri) 
     
    4848        logging.info("Preparing underlying data model") 
    4949        logging.info("Retrieving document to edit") 
    50         # NB, don't use the cache as docs are likely to change 
    51         # quite a lot during editing; ensure you've always got  
    52         # the latest updates loaded 
    53         interface = ndgInterface() 
    54         status,x = interface.GetXML(uri, useCache=False) 
    55  
    56         if not status: 
    57             code=400 
    58             if x.startswith('<p> Access Denied'): 
    59                 code=401 
    60  
    61             c.xml='%s'%x 
    62             response.status_code = code 
    63             raise SystemError('Problem experienced retrieving atom doc from eXist [%s]' %x) 
    6450 
    6551        # NB, passing in the inputs will overwrite any original values with the 
     
    6854            self.inputs = self.__getTidyInputs() 
    6955 
    70         c.atom = Atom(xmlString=str(x), ndgObject = self.ndgObject, **dict(self.inputs)) 
     56        self.ndgDoc.setupDocumentModel(ndgUri = uri, inputs = self.inputs) 
    7157 
    72         # lookup the atom publication state 
    73         edc = Utilities.getExistClient(c.atom.ME.providerID) 
    74         c.atom.state = edc.getAtomPublicationState(c.atom.datasetID,  
    75                                                    c.atom.ME.providerID) 
     58        if not self.ndgDoc.status: 
     59            c.xml = self.ndgDoc.xmlString  
     60            response.status_code = self.ndgDoc.htmlCode 
     61            raise SystemError('Problem experienced retrieving atom doc from eXist [%s]' %x) 
     62 
     63        c.atom = self.ndgDoc.docModel 
     64 
    7665        # save the current atom - to avoid this needing be recreated by the  
    7766        # asynch viewAssociatedData call 
  • MILK/trunk/milk_server/milk_server/models/ndgdoc.py

    r5022 r5024  
    6969 
    7070    def setupDocumentModel(self, ndgUri = None, config = None, 
    71                              outputSchema = None, format = None): 
     71                             outputSchema = None, format = None, 
     72                             inputs = None): 
    7273        ''' 
    7374        Retrieve and set up document model relating to specified ndgUri 
     
    7980        'xml' (return html visible xml), 'raw' (return as is) or None - defaults 
    8081        to standard type of data model.  Default = None    
     82        @keyword inputs: a dict of input data to be added to the document model 
     83        when setting this up; NB, currently this is only used by Atoms  
    8184        ''' 
    8285        self.__initiatiliseFields() 
     
    8588             
    8689        self.getDoc(outputSchema = outputSchema) 
    87         self.processDoc(outputSchema = outputSchema, format = format) 
     90        self.processDoc(outputSchema = outputSchema, format = format, 
     91                        inputs = inputs) 
    8892 
    8993 
     
    111115        @keyword outputSchema: format to return doc in. Default = None => 
    112116        return doc in its original format 
    113         @keyword format: display format of doc - currently can specify 
    114         'xml' (return html visible xml), 'raw' (return as is) or None - defaults 
    115         to standard type of data model.  Default = None    
    116117        ''' 
    117118        logging.info("Retrieving document to view") 
     
    133134 
    134135 
    135     def processDoc(self, outputSchema = None, format = None): 
     136    def processDoc(self, outputSchema = None, format = None, inputs = None): 
    136137        ''' 
    137138        Extract details from the NDG Doc, according to the doc type 
     139        @keyword outputSchema: format to return doc in. Default = None => 
     140        return doc in its original format 
     141        @keyword format: display format of doc - currently can specify 
     142        'xml' (return html visible xml), 'raw' (return as is) or None - defaults 
     143        to standard type of data model.  Default = None    
     144        @keyword inputs: a dict of input data to be added to the document model 
     145        when setting this up; NB, currently this is only used by Atoms  
    138146        ''' 
    139147        logging.debug("Processing document...") 
     
    176184 
    177185            self.isAtom = True 
    178             atom = Atom(xmlString = self.xmlString, ndgObject = self.ndgObject) 
     186            if not inputs: 
     187                inputs = {} 
     188            atom = Atom(xmlString = self.xmlString, ndgObject = self.ndgObject, 
     189                        **dict(inputs)) 
    179190            self.templateType = "genshi" 
    180191            self.renderTemplate = 'atom_editor/atom_editor' 
Note: See TracChangeset for help on using the changeset viewer.