changeset 9:eeaad777d3d7

more work for non-bib metadata
author casties
date Thu, 28 Jul 2011 18:08:58 +0200
parents 4cd862bf37a3
children 68bc459c9f59
files MetaData.py MetaDataFolder.py MetaDataMapping.py
diffstat 3 files changed, 30 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/MetaData.py	Thu Jul 28 14:54:54 2011 +0200
+++ b/MetaData.py	Thu Jul 28 18:08:58 2011 +0200
@@ -2,26 +2,11 @@
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 from Globals import package_home
 from AccessControl import ClassSecurityInfo
-import os.path
-import urllib
 import logging
-import urlparse
 
-# TODO: which xml toolkit?
-import amara
-import xml.sax.saxutils
-import xml.dom.minidom
 import xml.etree.ElementTree as ET
 
-
-# TODO: do we need this?
-#from Products.OSA_system2 import OSAS_helpers
-#from Products.OSA_system2.OSAS_metadata import OSAS_Metadata,OSAS_MetadataMapping
-
 from MetaDataMapping import MetaDataMapping
-from OSAS_metadata import OSAS_Metadata, OSAS_MetadataMapping
-
-
 from SrvTxtUtils import getHttpData, getText
 
 def normalizeFieldName(bt, underscore=True):
@@ -210,14 +195,9 @@
                gets data from server or dom or pre-parsed data."""
             logging.debug("getFormatted(template=%s)"%(template))
             
-            if dom is None and data is None:
-                # get from server
-                md = self.getMDFromPathOrUrl(path.replace("/mpiwg/online",""))
-                dom = ET.fromstring(md)
-                
             # get contents of bib tag
             if data is None:
-                data = getDataFromDom(dom)
+                data = self.getData(path=path, dom=dom)
 
             type = data.get('@type', '')
            
@@ -314,10 +294,7 @@
     
     
     security.declarePublic('changeMetaDataForm')
-    def changeMetaDataForm(self):
-        """Main configuration"""
-        pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeMetadata.zpt')).__of__(self)
-        return pt()
+    changeMetaDataForm = PageTemplateFile('zpt/changeMetadata', globals())
     
     security.declarePublic('changeMetaData')
     def changeMetaData(self,shortDescription,description,fields,metaDataServerUrl,RESPONSE=None):
@@ -331,13 +308,13 @@
 
 
 def manage_addMetaDataForm(self):
-    """interface for adding the OSAS_add_Metadata"""
-    pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMetadataForm.zpt')).__of__(self)
+    """interface for adding the Metadata"""
+    pt=PageTemplateFile('zpt/addMetadataForm', globals()).__of__(self)
     return pt()
 
 def manage_addMetaData(self,id,shortDescription,description,fields,RESPONSE=None):
     """a metadata objekt"""
-    newObj=MetaData(id,shortDescription,description,fields)
+    newObj = MetaData(id,shortDescription,description,fields)
     self.Destination()._setObject(id,newObj)
     if RESPONSE is not None:
         RESPONSE.redirect('manage_main')
--- a/MetaDataFolder.py	Thu Jul 28 14:54:54 2011 +0200
+++ b/MetaDataFolder.py	Thu Jul 28 18:08:58 2011 +0200
@@ -3,6 +3,7 @@
 from Globals import package_home
 from AccessControl import ClassSecurityInfo
 import os.path
+import urlparse
 import logging
 
 from MetaDataMapping import MetaDataMapping
@@ -100,14 +101,25 @@
         md = getHttpData(url)
         return md
 
+    def getXmlPathData(self, xmlpath, path=None, dom=None):
+        """returns contents of element at xmlpath as dict"""
+        logging.error("getXmlPathData(%s)"%xmlpath)
+        # make xmlpath relative for Zope
+        if xmlpath[0] == '/':
+            xmlpath = xmlpath[1:]
+            
+        mdObj = self.restrictedTraverse(xmlpath, None)
+        if mdObj is not None:
+            return mdObj.getData(path=path, dom=dom)
+        else:
+            logging.error("getXmlPathData: MetaData element at '%s' not found!"%xmlpath)
+            return None
+
     def getTexttoolData(self, path=None, dom=None):
         """returns contents of texttool tag as dict"""
-        return self.resource.meta.texttool.getData(path=path, dom=dom)
-
+        return self.getXmlPathData('resource/meta/texttool', path=path, dom=dom)
 
-
-
-    def getBibdata(self, path=None, dom=None):
+    def getBibData(self, path=None, dom=None):
         """returns contents of bib tag as dict"""
         return self.resource.meta.bib.getData(path=path, dom=dom)
 
@@ -238,7 +250,10 @@
             RESPONSE.redirect('manage_main')
 
 
-manage_addMetaDataFolderForm = PageTemplateFile('zpt/addMetadataFolderForm',globals())
+def manage_addMetaDataFolderForm(self):
+    """add MetaDataFolder form"""
+    pt = PageTemplateFile('zpt/addMetadataFolderForm',globals()).__of__(self)
+    return pt()
 
 def manage_addMetaDataFolder(self,id,title,RESPONSE=None):
     """a MetaDataFolder objekt"""
--- a/MetaDataMapping.py	Thu Jul 28 14:54:54 2011 +0200
+++ b/MetaDataMapping.py	Thu Jul 28 18:08:58 2011 +0200
@@ -124,7 +124,10 @@
             RESPONSE.redirect('manage_main')
 
     
-manage_addMetaDataMappingForm = PageTemplateFile('zpt/addMetadataMappingForm', globals())
+def manage_addMetaDataMappingForm(self):
+    """add MetapdataMapping form"""
+    pt = PageTemplateFile('zpt/addMetadataMappingForm', globals()).__of__(self)
+    return pt()
 
 def manage_addMetaDataMapping(self,idOfObject,titleOfObject,RESPONSE=None):
     """add the MetapdataMapping"""