changeset 25:64b703d1b8a4

Merge with d036de7fd78d45d9558dfccb88042cbec83d4b5e
author casties
date Fri, 27 Jul 2012 12:53:51 +0200
parents 5ed16f971297 (current diff) d036de7fd78d (diff)
children a19575be96e8
files MetaDataFolder.py
diffstat 2 files changed, 43 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/MetaData.py	Wed Jul 25 12:53:17 2012 +0200
+++ b/MetaData.py	Fri Jul 27 12:53:51 2012 +0200
@@ -150,6 +150,36 @@
         return data
             
 
+    def getDRI(self,path=None,type="escidoc",dom=None):
+        """returns the DRI of an document, i.e. the content of the dri tag with the given type."""
+        
+        #logging.debug("getData(path=%s, dom=%s)"%(path,dom))
+        
+        
+        if path is None and dom is None:
+            return None
+        
+        
+        if dom is None:
+            # get from server
+            dom = self.getDomFromPathOrUrl(path)
+                
+        # ElementTree doesn't like absolute paths
+        # lets assume dom is rooted in the first element
+        
+        xpath = '.' + self.getXmlPath(omitRoot=True)+'/dri[@type="%s"]'%type
+        logging.debug("getSubDom looking for %s in %s"%(xpath, dom))
+       
+        
+        elem = dom.find(xpath)
+            
+      
+        if elem is None:
+            return None
+        
+        
+        return getText(elem)
+        
     def getData(self, path=None, dom=None, normalizeNames=True, all=False, recursive=0, allText=0):
         """Returns dict with attributes and child elements from corresponding tag.
         
@@ -289,7 +319,9 @@
             """returns string with document data formatted according to template.
                gets data from server or dom or pre-parsed data."""
             logging.debug("getFormatted(template=%s)"%(template))
-            
+            logging.debug(self.absolute_url())
+            logging.debug(self.__dict__)
+                        
             # get contents of tag
             if data is None:
                 data = self.getData(path=path, dom=dom)
@@ -301,9 +333,11 @@
             type = data.get('@type', '')
            
             # get template
+          
             tp=getattr(self,"%s_%s"%(template, normalizeFieldName(type)), None)
+            
             if tp is None:
-                logging.warning("getFormatted: no template for: %s_%s"%(template, type))
+                logging.warning("getFormatted: no template for: %s_%s!"%(template, normalizeFieldName(type)))
                 # try generic
                 tp=getattr(self,"%s_generic"%(template), None)
                 if tp is None:
@@ -315,7 +349,9 @@
                 fields = self.getMappedData(data, allFields=allFields)
             else:
                 fields = {}
-                
+            
+            logging.debug("XXXX")    
+            logging.debug(tp)    
             return tp(mdmap=fields, md=data)
 
 
--- a/MetaDataFolder.py	Wed Jul 25 12:53:17 2012 +0200
+++ b/MetaDataFolder.py	Fri Jul 27 12:53:51 2012 +0200
@@ -211,6 +211,10 @@
         return self.getXmlPathData('resource/meta/context', path=path, dom=dom,  all=all)
         
     
+    def getDRI(self,path=None,type="escidoc",dom=None):
+        """returns the DRI of the document"""
+        return self.resource.meta.getDRI(path=path, dom=dom)
+    
     def getBibData(self, path=None, dom=None):
         """returns contents of bib tag as dict"""
         return self.resource.meta.bib.getData(path=path, dom=dom)