Changeset 4563 for MILK/trunk/milk_server
- Timestamp:
- 08/12/08 16:20:26 (12 years ago)
- Location:
- MILK/trunk/milk_server/milk_server
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
MILK/trunk/milk_server/milk_server/controllers/atom_editor/editatom.py
r4556 r4563 5 5 @author: C Byrom, Tessella Sep 2008 6 6 ''' 7 import logging, traceback, sys, cgi 7 import logging, traceback, sys, cgi, xmlrpclib 8 8 from paste.request import parse_querystring 9 9 from xml.parsers.expat import ExpatError … … 25 25 from ndgUtils.lib.utilities import escapeSpecialCharacters 26 26 from ndgUtils.vocabtermdata import VocabTermData as VTD 27 from granulatorTool.granulite import granulite asgranulite27 from ndgUtils.lib.granulite import granulite 28 28 29 29 class EditatomController(BaseController): … … 63 63 c.xml = escapeSpecialCharacters('Unexpected error loading page [%s]' \ 64 64 %str(errorMessage)) 65 c.doc =''65 c.doc = '' 66 66 67 67 # unpack errors, if possible - NB, the c.errors value is used by the template 68 68 # function, displayErrors, which is used by most of the editor templates 69 if isinstance(e, xmlrpclib.Fault): 70 # strip out the exception type - NB, this is usually native library code 71 # and is of no real interest - and will just confuse viewers 72 c.errors['Unexpected error'] = e.faultString.split(':')[-1] 69 73 if hasattr(e, 'unpack_errors'): 70 74 c.errors.update(e.unpack_errors()) 75 71 76 else: 72 77 c.errors['Unexpected error'] = [c.xml] … … 98 103 def upload(self, uri): 99 104 ''' 100 Upload a CSML or granulite file and store it in the session variable105 Upload a CSML, CDML or granulite file and store it in the session variable 101 106 NB, if the uri is specified, we're already dealing with an atom 102 107 (which this refers to) - so the file is not a granulite - since 103 this is used to create the atom108 this is used to create an atom from scratch 104 109 ''' 105 110 logging.info("Uploading file...") 106 111 self.__setup(uri=uri) 107 i f uri:108 file = request.POST.get('upload_CSML')109 else:110 file = request.POST.get('upload_granulite')111 112 inputs = self.__getTidyInputs() 113 114 granFile = request.POST.get('upload_granulite') 115 csmlOrCdmlFile = request.POST.get('CSMLOrCDML') 116 112 117 c.errors = {} 113 118 try: 114 if file == '': 119 useCSMLID = True 120 c.atom = None 121 if uri: 122 self.prepareDataModel(uri) 123 useCSMLID = False 124 125 if (granFile == '' or granFile == None) and \ 126 (csmlOrCdmlFile == '' or csmlOrCdmlFile == None): 115 127 errorMessage = "Error: could not load file - please try again" 116 128 logging.error(errorMessage) 117 129 raise IOError(errorMessage) 118 130 else: 119 logging.debug("- file name: '%s'" %file.name)120 121 131 # Prepare the basic data model 122 132 # NB, if loading a granulite, this will create the displayed atom 123 if uri: 124 self.prepareDataModel(uri) 125 else: 126 c.atom = Atom() 133 # with the ID taken from the CSML file, if specified 134 fileContents = None 135 if (granFile is not None and granFile != ''): 136 fileContents = granFile.value 137 138 # use the granulite helper class to add either the full granulite 139 # data or just the CSML/CDML data 140 # NB, we'll be creating the atom in the default local eXist 141 eXistClient = self.__getExistClient('local') 142 gran = granulite(fileContents, granuleAtom = c.atom, \ 143 eXistClient = eXistClient, \ 144 csmlOrCdmlFile = csmlOrCdmlFile, \ 145 timeAxis = inputs.get('timeAxis'), \ 146 datasetID = inputs.get('datasetID'), \ 147 useCSMLID = useCSMLID) 127 148 128 149 # now process the input file and add any extra required data 129 150 if uri: 130 self.__processCSMLFile(file)151 c.atom = gran.processCSMLOrCDMLFile() 131 152 132 153 # save new data - NB, for granulites, this is done as part of the … … 134 155 self.saveAtomToExist(c.atom) 135 156 else: 136 self.__processGranuliteFile(file.value) 157 c.atom = gran.processGranulite() 158 137 159 # Now set up the ndgObject with the created atom's vals 138 160 self.__setup(uri=c.atom.ndgURI) 139 161 c.atom.ndgObject = self.ndgObject 140 141 162 142 163 # now do redirection - NB, this ensures that current atom contents are … … 155 176 else: 156 177 return self.createGranule() 157 158 159 def __processCSMLFile(self, file):160 '''161 Accept the contents of a CSML file and extract and add appropriate data162 to the current atom data model163 @param fileContents: contents of the file uploaded164 '''165 logging.info("Extracting CSML data")166 csmlDoc = c.atom.addCSMLData(file.filename, file.value)167 logging.info("Finished extracting CSML data")168 169 logging.info("Adding CSML file to eXist")170 eXist = self.__getExistClient(c.atom.ME.providerID)171 eXist.createOrUpdateEXistFile(csmlDoc.toPrettyXML(), \172 eXistConnector.NDG_A_COLLECTION_PATH + \173 c.atom.ME.providerID + '/', \174 file.filename)175 logging.info("CSML file added to eXist")176 177 178 def __processGranuliteFile(self, fileContents):179 '''180 Accept the contents of a granulite file and extract and add appropriate data181 to the current atom data model182 @param fileContents: contents of the file uploaded183 '''184 logging.info("Processing granulite data")185 # check for uploaded CSML/CDML file data186 cdmlFile = request.POST.get('upload_cdml')187 csmlFile = request.POST.get('upload_csml')188 if cdmlFile and csmlFile:189 raise ValueError("Cannot specify both CDML and CSML file - please choose a single one to ingest.")190 191 # NB, we'll be creating the atom in the default local eXist192 eXistClient = self.__getExistClient('local')193 gran = granulite(fileContents, eXistClient = eXistClient, \194 cdmlFile = cdmlFile, csmlFile = csmlFile)195 c.atom = gran.processGranulite()196 197 logging.info("Finished processing granulite data")198 178 199 179 … … 261 241 g.validator.validateAtom() 262 242 logging.info("- input valid") 263 except ValidationError, e: 243 244 self.saveAtomToExist(c.atom) 245 except Exception, e: 264 246 self.__unpackErrors(e) 265 247 logging.info("- input invalid") 266 248 return self.edit(uri) 267 268 self.saveAtomToExist(c.atom)269 249 270 250 # now do redirection - NB, this ensures that current atom contents are … … 692 672 693 673 except Exception, e: 674 import pdb 675 pdb.set_trace() 694 676 return self.__handleError(e) -
MILK/trunk/milk_server/milk_server/templates/atom_editor/atom_editor.html
r4557 r4563 7 7 <head> 8 8 <title py:content="c.title">title</title> 9 <span py:if="c.atom.isDeployable() " py:strip="">9 <span py:if="c.atom.isDeployable() or c.atom.isDE()" py:strip=""> 10 10 <script type="text/javascript"> 11 11 var placeholderNames = ['deploymentsPlaceholder']; … … 29 29 var urls = ['$c.dataEntitiesURL']; 30 30 </script> 31 </span> 32 <span py:if="not c.atom.isDeployment()" py:strip=""> 31 33 <script type="text/javascript" src="$g.server/js/queueDeployments.js"/> 32 34 </span> … … 51 53 52 54 <div py:if="not c.atom.isDeployment() and not c.atom.isGranule()" py:replace="GeneralInfo(c.saveLink)"/> 53 <div py:if="c.atom.isGranule() and not c.atom.contentFile" py:replace="Upload File('Ingest data from CSML file', 'CSML',c.saveLink)"/>55 <div py:if="c.atom.isGranule() and not c.atom.contentFile" py:replace="UploadCSMLOrCDMLFileForm(c.saveLink)"/> 54 56 <div py:if="not c.atom.isDeployment() and not c.atom.isGranule()" py:replace="TextArea('Summary', c.atom.Summary, c.saveLink)"/> 55 57 <div py:if="not c.atom.isDeployment() and not c.atom.isGranule()" py:replace="TextArea('Content', c.atom.Content, c.saveLink)"/> … … 64 66 <div id="dataEntitiesPlaceholder" /> 65 67 </div> 66 <div class="metadataSection" py:if="c.atom.isDeployable() ">68 <div class="metadataSection" py:if="c.atom.isDeployable() or c.atom.isDE()"> 67 69 <div id="deploymentsPlaceholder" /> 68 70 </div> -
MILK/trunk/milk_server/milk_server/templates/atom_editor/atom_functions.html
r4557 r4563 17 17 </table> 18 18 </div> 19 20 21 <div py:def="UploadCSMLOrCDMLFileRows(editLink)"> 22 <tr> 23 <td class="cellhead"> 24 CSML or CDML file: 25 </td> 26 <td> 27 ${Markup(h.file_field('CSMLOrCDML', size="80"))} 28 </td> 29 </tr> 30 <tr> 31 <td class="cellhead"> 32 Dataset ID: 33 <span py:replace="helpIcon('datasetID_help')"/> 34 </td> 35 <td> 36 ${Markup(h.text_field('datasetID', size="80"))} 37 </td> 38 </tr> 39 <tr id="datasetID_help" class="hidden" > 40 <td class="helptxt" colspan="2"> 41 If uploading CDML data, specify a dataset ID to use for the generated 42 CSML file - otherwise this will be created randomly. 43 </td> 44 </tr> 45 <tr> 46 <td class="cellhead"> 47 Time axis: 48 <span py:replace="helpIcon('timeAxis_help')"/> 49 </td> 50 <td> 51 ${Markup(h.text_field('timeAxis', size="80"))} 52 </td> 53 </tr> 54 <tr id="timeAxis_help" class="hidden" > 55 <td class="helptxt" colspan="2"> 56 If uploading CDML data, specify the time axis used by the 57 CDML file - NB, 'time' is taken as the default axis. 58 </td> 59 </tr> 60 <tr> 61 <td /> 62 <td colspan="2"> 63 ${Markup(h.submit('Upload'))} 64 </td> 65 </tr> 66 </div> 67 68 69 <div py:def="UploadCSMLOrCDMLFileForm(editLink)"> 70 <div class="headingblock" py:if="editLink"> 71 ${Markup(h.form(h.url(controller='atom_editor/editatom', action='upload', uri = c.uri), multipart=True))} 72 <table> 73 <tr> 74 <td class="linehead" colspan="2"> 75 Upload data 76 </td> 77 </tr> 78 <div py:replace="UploadCSMLOrCDMLFileRows(editLink)"/> 79 </table> 80 ${Markup(h.end_form())} 81 </div> 82 </div> 19 83 20 84 … … 876 940 </tbody></table> 877 941 </div> 942 943 944 <!--! Help Icons --> 945 <span py:def="helpIcon(value)"> 946 <span> 947 <a href="javascript:;" title="Toggle help" onclick="toggleDiv(1,'$value','shown','hidden','tr'); return false;"> 948 <img src="$g.helpIcon" alt="Toggle help" class="helpicon"/></a> 949 950 </span> 951 </span> 952 878 953 879 954 </html> -
MILK/trunk/milk_server/milk_server/templates/atom_editor/atom_granulator.html
r4503 r4563 29 29 </td> 30 30 </tr> 31 <tr> 32 <td class="cellhead"> 33 CSML file: 34 </td> 35 <td> 36 ${Markup(h.file_field('upload_csml', size="80"))} 37 </td> 38 </tr> 39 <tr> 40 <td></td><td>OR</td></tr> 41 <tr> 42 <td class="cellhead"> 43 CDML file: 44 </td> 45 <td> 46 ${Markup(h.file_field('upload_cdml', size="80"))} 47 </td> 48 </tr> 49 <tr> 50 <td /> 51 <td colspan="2"> 52 ${Markup(h.submit('Upload'))} 53 </td> 54 </tr> 31 <div py:replace="UploadCSMLOrCDMLFileRows('bbb')"/> 55 32 </table> 56 33 ${Markup(h.end_form())}
Note: See TracChangeset
for help on using the changeset viewer.