changeset 24:d036de7fd78d

getDRI added
author dwinter
date Fri, 27 Jul 2012 12:46:00 +0200
parents 9a1e75e708e1
children 64b703d1b8a4
files MetaData.py MetaDataFolder.py
diffstat 2 files changed, 43 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/MetaData.py	Sun Oct 23 21:29:02 2011 +0200
+++ b/MetaData.py	Fri Jul 27 12:46:00 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	Sun Oct 23 21:29:02 2011 +0200
+++ b/MetaDataFolder.py	Fri Jul 27 12:46:00 2012 +0200
@@ -206,6 +206,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)