Diff for /documentViewer/documentViewer.py between versions 1.24 and 1.31

version 1.24, 2007/05/03 17:28:23 version 1.31, 2007/06/29 15:44:40
Line 18  import sys Line 18  import sys
 import cgi  import cgi
 import urllib  import urllib
 import logging  import logging
   import math
   
 import urlparse   import urlparse 
   
Line 31  def getInt(number, default=0): Line 32  def getInt(number, default=0):
     try:      try:
         return int(number)          return int(number)
     except:      except:
         return default          return int(default)
   
 def getTextFromNode(nodename):  def getTextFromNode(nodename):
     """get the cdata content of a node"""      """get the cdata content of a node"""
Line 80  class documentViewer(Folder): Line 81  class documentViewer(Folder):
     image_main = PageTemplateFile('zpt/image_main', globals())      image_main = PageTemplateFile('zpt/image_main', globals())
     head_main = PageTemplateFile('zpt/head_main', globals())      head_main = PageTemplateFile('zpt/head_main', globals())
     docuviewer_css = PageTemplateFile('css/docuviewer.css', globals())      docuviewer_css = PageTemplateFile('css/docuviewer.css', globals())
       info_xml = PageTemplateFile('zpt/info_xml', globals())
   
     security.declareProtected('View management screens','changeDocumentViewerForm')          security.declareProtected('View management screens','changeDocumentViewerForm')    
     changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals())      changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals())
Line 108  class documentViewer(Folder): Line 110  class documentViewer(Folder):
     def index_html(self,mode,url,viewMode="auto",start=None,pn=1):      def index_html(self,mode,url,viewMode="auto",start=None,pn=1):
         '''          '''
         view it          view it
         @param mode: defines which type of document is behind url (text,images or auto)          @param mode: defines how to access the document behind url 
         @param url: url which contains display information          @param url: url which contains display information
         @param viewMode: if images display images, if text display text, default is images          @param viewMode: if images display images, if text display text, default is images (text,images or auto)
                   
         '''          '''
                   
Line 133  class documentViewer(Folder): Line 135  class documentViewer(Folder):
             else:              else:
                 viewMode="images"                  viewMode="images"
                                 
   
         return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode)          return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode)
       
       
Line 153  class documentViewer(Folder): Line 154  class documentViewer(Folder):
         return url          return url
   
           
       def getInfo_xml(self,url,mode):
           """returns info about the document as XML"""
   
           if not self.digilibBaseUrl:
               self.digilibBaseUrl = self.findDigilibUrl() or "http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary"
           
           docinfo = self.getDocinfo(mode=mode,url=url)
           pt = getattr(self.template, 'info_xml')
           return pt(docinfo=docinfo)
   
       
     def getStyle(self, idx, selected, style=""):      def getStyle(self, idx, selected, style=""):
         """returns a string with the given style and append 'sel' if path == selected."""          """returns a string with the given style and append 'sel' if path == selected."""
         #logger("documentViewer (getstyle)", logging.INFO, "idx: %s selected: %s style: %s"%(idx,selected,style))          #logger("documentViewer (getstyle)", logging.INFO, "idx: %s selected: %s style: %s"%(idx,selected,style))
Line 298  class documentViewer(Folder): Line 310  class documentViewer(Folder):
                   
     def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None):      def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None):
         """gets bibliographical info from the index.meta file at path or given by dom"""          """gets bibliographical info from the index.meta file at path or given by dom"""
         logger("documentViewer (getbibinfofromindexmeta)", logging.INFO,"path: %s"%(path))          logging.debug("documentViewer (getbibinfofromindexmeta) path: %s"%(path))
                   
         if docinfo is None:          if docinfo is None:
             docinfo = {}              docinfo = {}
Line 306  class documentViewer(Folder): Line 318  class documentViewer(Folder):
         if dom is None:          if dom is None:
             dom = self.getIndexMeta(getParentDir(path))              dom = self.getIndexMeta(getParentDir(path))
                           
           # put in all raw bib fields as dict "bib"
           bib = dom.xpath("//bib/*")
           if bib and len(bib)>0:
               bibinfo = {}
               for e in bib:
                   bibinfo[e.localName] = getTextFromNode(e)
               docinfo['bib'] = bibinfo
           
           # extract some fields (author, title, year) according to their mapping
         metaData=self.metadata.main.meta.bib          metaData=self.metadata.main.meta.bib
         bibtype=dom.xpath("//bib/@type")          bibtype=dom.xpath("//bib/@type")
         if bibtype and (len(bibtype)>0):          if bibtype and (len(bibtype)>0):
             bibtype=bibtype[0].value              bibtype=bibtype[0].value
         else:          else:
             bibtype="generic"              bibtype="generic"
               
         bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC)          bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC)
           docinfo['bib_type'] = bibtype
         bibmap=metaData.generateMappingForType(bibtype)          bibmap=metaData.generateMappingForType(bibtype)
         #print "bibmap: ", bibmap, " for: ", bibtype  
         # if there is no mapping bibmap is empty (mapping sometimes has empty fields)          # if there is no mapping bibmap is empty (mapping sometimes has empty fields)
         if len(bibmap) > 0 and len(bibmap['author'][0]) > 0:          if len(bibmap) > 0 and len(bibmap['author'][0]) > 0:
               try:
             docinfo['author']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['author'][0])[0])              docinfo['author']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['author'][0])[0])
               except: pass
               try:
             docinfo['title']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['title'][0])[0])              docinfo['title']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['title'][0])[0])
               except: pass
               try:
             docinfo['year']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['year'][0])[0])              docinfo['year']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['year'][0])[0])
                           except: pass
             logging.info("bla")              logging.debug("documentViewer (getbibinfofromindexmeta) using mapping for %s"%bibtype)
             try:              try:
                 docinfo['lang']=getTextFromNode(dom.xpath("//bib/lang")[0])                  docinfo['lang']=getTextFromNode(dom.xpath("//bib/lang")[0])
             except:              except:
                 docinfo['lang']=''                  docinfo['lang']=''
   
         return docinfo          return docinfo
   
                   
Line 397  class documentViewer(Folder): Line 425  class documentViewer(Folder):
            textUrl=getTextFromNode(textUrls[0])             textUrl=getTextFromNode(textUrls[0])
            if urlparse.urlparse(textUrl)[0]=="": #keine url             if urlparse.urlparse(textUrl)[0]=="": #keine url
                textUrl=os.path.join(archivePath,textUrl)                  textUrl=os.path.join(archivePath,textUrl) 
              # fix URLs starting with /mpiwg/online
              if textUrl.startswith("/mpiwg/online"):
                  textUrl = textUrl.replace("/mpiwg/online",'',1)
   
            docinfo['textURL'] = textUrl             docinfo['textURL'] = textUrl
         
Line 404  class documentViewer(Folder): Line 435  class documentViewer(Folder):
        docinfo = self.getBibinfoFromIndexMeta(url,docinfo=docinfo,dom=dom)   # get info von bib tag         docinfo = self.getBibinfoFromIndexMeta(url,docinfo=docinfo,dom=dom)   # get info von bib tag
                 
        if presentationUrls and (len(presentationUrls)>0): # ueberschreibe diese durch presentation informationen          if presentationUrls and (len(presentationUrls)>0): # ueberschreibe diese durch presentation informationen 
             # presentation url ergiebt sich ersetzen von index.meta in der url der fŸr die Metadaten              # presentation url ergiebt sich ersetzen von index.meta in der url der fuer die Metadaten
             # durch den relativen Pfad auf die presentation infos              # durch den relativen Pfad auf die presentation infos
            presentationUrl=url.replace('index.meta',getTextFromNode(presentationUrls[0]))             presentationUrl=url.replace('index.meta',getTextFromNode(presentationUrls[0]))
            docinfo = self.getBibinfoFromTextToolPresentation(presentationUrl,docinfo=docinfo,dom=dom)             docinfo = self.getBibinfoFromTextToolPresentation(presentationUrl,docinfo=docinfo,dom=dom)
   
        docinfo = self.getAuthinfoFromIndexMeta(path,docinfo=docinfo)         docinfo = self.getAuthinfoFromIndexMeta(url,docinfo=docinfo,dom=dom)   # get access info
        return docinfo         return docinfo
         
         
Line 417  class documentViewer(Folder): Line 448  class documentViewer(Folder):
         """gets the bibliographical information from the preseantion entry in texttools          """gets the bibliographical information from the preseantion entry in texttools
         """          """
         dom=self.getPresentationInfoXML(url)          dom=self.getPresentationInfoXML(url)
           try:
         docinfo['author']=getTextFromNode(dom.xpath("//author")[0])          docinfo['author']=getTextFromNode(dom.xpath("//author")[0])
           except:
               pass
           try:
         docinfo['title']=getTextFromNode(dom.xpath("//title")[0])          docinfo['title']=getTextFromNode(dom.xpath("//title")[0])
           except:
               pass
           try:
         docinfo['year']=getTextFromNode(dom.xpath("//date")[0])          docinfo['year']=getTextFromNode(dom.xpath("//date")[0])
           except:
               pass
         return docinfo          return docinfo
           
     def getDocinfoFromImagePath(self,path,docinfo=None):      def getDocinfoFromImagePath(self,path,docinfo=None):
Line 474  class documentViewer(Folder): Line 514  class documentViewer(Folder):
         pageinfo['cols'] = cols          pageinfo['cols'] = cols
         grpsize = cols * rows          grpsize = cols * rows
         pageinfo['groupsize'] = grpsize          pageinfo['groupsize'] = grpsize
         start = getInt(start, default=(int(current / grpsize) * grpsize +1))          start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1)))
           # int(current / grpsize) * grpsize +1))
         pageinfo['start'] = start          pageinfo['start'] = start
         pageinfo['end'] = start + grpsize          pageinfo['end'] = start + grpsize
         if docinfo is not None:          if docinfo is not None:

Removed from v.1.24  
changed lines
  Added in v.1.31


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>