Diff for /documentViewer/documentViewer.py between versions 1.175.2.6 and 1.175.2.7

version 1.175.2.6, 2011/07/20 08:22:36 version 1.175.2.7, 2011/07/20 19:36:57
Line 102  def getParentDir(path): Line 102  def getParentDir(path):
     """returns pathname shortened by one"""      """returns pathname shortened by one"""
     return '/'.join(path.split('/')[0:-1])      return '/'.join(path.split('/')[0:-1])
                   
   def normalizeBibtype(bt):
       """returns normalised bib type for looking up mappings"""
       bt = bt.strip().replace(' ', '-').lower()
       return bt
   
 def getBibdataFromDom(dom):  def getBibdataFromDom(dom):
     """returns dict with all elements from bib-tag"""      """returns dict with all elements from bib-tag"""
     bibinfo = {}      bibinfo = {}
Line 109  def getBibdataFromDom(dom): Line 114  def getBibdataFromDom(dom):
     if bib is not None:      if bib is not None:
         # put type in @type          # put type in @type
         type = bib.get('type')          type = bib.get('type')
         bibinfo['@type'] = type          bibinfo['@type'] = normalizeBibtype(type)
         # put all subelements in dict          # put all subelements in dict
         for e in bib:          for e in bib:
             bibinfo[e.tag] = getText(e)              bibinfo[e.tag] = getText(e)
Line 575  class documentViewer(Folder): Line 580  class documentViewer(Folder):
         # put all raw bib fields in dict "bib"          # put all raw bib fields in dict "bib"
         bib = getBibdataFromDom(dom)          bib = getBibdataFromDom(dom)
         docinfo['bib'] = bib          docinfo['bib'] = bib
                   bibtype = bib.get('@type', None)
         # extract some fields (author, title, year) according to their mapping  
         metaData=self.metadata.main.meta.bib  
         bibtype=bib.get("@type")  
         #bibtype=dom.xpath("//bib/@type")  
         if not bibtype:  
             bibtype="generic"  
               
         bibtype=bibtype.replace("-"," ") # wrong types in index meta "-" instead of " " (not wrong! ROC)  
         docinfo['bib_type'] = bibtype          docinfo['bib_type'] = bibtype
         bibmap=metaData.generateMappingForType(bibtype)          if bibtype:
         logging.debug("documentViewer (getbibinfofromindexmeta) bibmap:"+repr(bibmap))              # also store standard mapped metadata for convenience
         logging.debug("documentViewer (getbibinfofromindexmeta) bibtype:"+repr(bibtype))  
         # if there is no mapping bibmap is empty (mapping sometimes has empty fields)  
         if len(bibmap) > 0 and bibmap.get('author',None) or bibmap.get('title',None):  
             try:  
                 docinfo['author']=bib.get(bibmap['author'][0])  
             except: pass  
             try:  
                 docinfo['title']=bib.get(bibmap['title'][0])  
             except: pass  
             try:              try:
                 docinfo['year']=bib.get(bibmap['year'][0])                  stdbib = self.metadata.getStdMappedHash(bib)
             except: pass                  docinfo['std_bib'] = stdbib
                   docinfo['author'] = stdbib['author']
                   docinfo['title'] = stdbib['title']
                   docinfo['year'] = stdbib['year']
               except:
                   pass
                           
             # ROC: why is this here?  
             #            logging.debug("documentViewer (getbibinfofromindexmeta) using mapping for %s"%bibtype)  
             #            try:  
             #                docinfo['lang']=getTextFromNode(dom.find(".//bib/lang")[0])  
             #            except:  
             #                docinfo['lang']=''  
             #            try:  
             #                docinfo['city']=getTextFromNode(dom.find(".//bib/city")[0])  
             #            except:  
             #                docinfo['city']=''  
             #            try:  
             #                docinfo['number_of_pages']=getTextFromNode(dom.find(".//bib/number_of_pages")[0])  
             #            except:  
             #                docinfo['number_of_pages']=''  
             #            try:  
             #                docinfo['series_volume']=getTextFromNode(dom.find(".//bib/series_volume")[0])  
             #            except:  
             #                docinfo['series_volume']=''  
             #            try:  
             #                docinfo['number_of_volumes']=getTextFromNode(dom.find(".//bib/number_of_volumes")[0])  
             #            except:  
             #                docinfo['number_of_volumes']=''  
             #            try:  
             #                docinfo['translator']=getTextFromNode(dom.find(".//bib/translator")[0])  
             #            except:  
             #                docinfo['translator']=''  
             #            try:  
             #                docinfo['edition']=getTextFromNode(dom.find(".//bib/edition")[0])  
             #            except:  
             #                docinfo['edition']=''  
             #            try:  
             #                docinfo['series_author']=getTextFromNode(dom.find(".//bib/series_author")[0])  
             #            except:  
             #                docinfo['series_author']=''  
             #            try:  
             #                docinfo['publisher']=getTextFromNode(dom.find(".//bib/publisher")[0])  
             #            except:  
             #                docinfo['publisher']=''  
             #            try:  
             #                docinfo['series_title']=getTextFromNode(dom.find(".//bib/series_title")[0])  
             #            except:  
             #                docinfo['series_title']=''  
             #            try:  
             #                docinfo['isbn_issn']=getTextFromNode(dom.find(".//bib/isbn_issn")[0])  
             #            except:  
             #                docinfo['isbn_issn']=''             
         return docinfo          return docinfo
           
           
Line 790  class documentViewer(Folder): Line 737  class documentViewer(Folder):
         imageUrl=self.digilibBaseUrl+"/servlet/Scaler?fn="+path          imageUrl=self.digilibBaseUrl+"/servlet/Scaler?fn="+path
         docinfo['imageURL'] = imageUrl          docinfo['imageURL'] = imageUrl
                   
           #TODO: use getDocinfoFromIndexMeta
         #path ist the path to the images it assumes that the index.meta file is one level higher.          #path ist the path to the images it assumes that the index.meta file is one level higher.
         docinfo = self.getBibinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1)          docinfo = self.getBibinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1)
         docinfo = self.getAuthinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1)          docinfo = self.getAuthinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1)
Line 824  class documentViewer(Folder): Line 772  class documentViewer(Folder):
             logging.error("documentViewer (getdocinfo) unknown mode: %s!"%mode)              logging.error("documentViewer (getdocinfo) unknown mode: %s!"%mode)
             raise ValueError("Unknown mode %s! Has to be one of 'texttool','imagepath','filepath'."%(mode))              raise ValueError("Unknown mode %s! Has to be one of 'texttool','imagepath','filepath'."%(mode))
                                   
         # FIXME: fake texturlpath   
         if not docinfo.has_key('textURLPath'):  
             docinfo['textURLPath'] = None  
           
         logging.debug("documentViewer (getdocinfo) docinfo: keys=%s"%docinfo.keys())          logging.debug("documentViewer (getdocinfo) docinfo: keys=%s"%docinfo.keys())
         #logging.debug("documentViewer (getdocinfo) docinfo: %s"%docinfo)          #logging.debug("documentViewer (getdocinfo) docinfo: %s"%docinfo)
           # store in session
         self.REQUEST.SESSION['docinfo'] = docinfo          self.REQUEST.SESSION['docinfo'] = docinfo
         return docinfo          return docinfo
                                 
Line 845  class documentViewer(Folder): Line 790  class documentViewer(Folder):
         pageinfo['cols'] = cols          pageinfo['cols'] = cols
         grpsize = cols * rows          grpsize = cols * rows
         pageinfo['groupsize'] = grpsize          pageinfo['groupsize'] = grpsize
           # what does this do?
         start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1)))          start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1)))
         # int(current / grpsize) * grpsize +1))          # int(current / grpsize) * grpsize +1))
         pageinfo['start'] = start          pageinfo['start'] = start
Line 855  class documentViewer(Folder): Line 801  class documentViewer(Folder):
             pageinfo['numgroups'] = int(np / grpsize)              pageinfo['numgroups'] = int(np / grpsize)
             if np % grpsize > 0:              if np % grpsize > 0:
                 pageinfo['numgroups'] += 1                          pageinfo['numgroups'] += 1        
                   
         pageinfo['viewMode'] = viewMode          pageinfo['viewMode'] = viewMode
         pageinfo['tocMode'] = tocMode          pageinfo['tocMode'] = tocMode
         pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg')          pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg')
Line 867  class documentViewer(Folder): Line 814  class documentViewer(Folder):
         pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30')          pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30')
         pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '10')          pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '10')
         pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1')               pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1')     
           # WTF?:
         toc = int (pageinfo['tocPN'])          toc = int (pageinfo['tocPN'])
         pageinfo['textPages'] =int (toc)          pageinfo['textPages'] =int (toc)
                   
           # What does this do?
         if 'tocSize_%s'%tocMode in docinfo:          if 'tocSize_%s'%tocMode in docinfo:
             tocSize = int(docinfo['tocSize_%s'%tocMode])              tocSize = int(docinfo['tocSize_%s'%tocMode])
             tocPageSize = int(pageinfo['tocPageSize'])              tocPageSize = int(pageinfo['tocPageSize'])
Line 878  class documentViewer(Folder): Line 827  class documentViewer(Folder):
                 tocPages=tocSize/tocPageSize+1                  tocPages=tocSize/tocPageSize+1
             else:              else:
                 tocPages=tocSize/tocPageSize                  tocPages=tocSize/tocPageSize
                   
             pageinfo['tocPN'] = min (tocPages,toc)                                  pageinfo['tocPN'] = min (tocPages,toc)                    
               
         pageinfo['searchPN'] =self.REQUEST.get('searchPN','1')          pageinfo['searchPN'] =self.REQUEST.get('searchPN','1')
         pageinfo['sn'] =self.REQUEST.get('sn','')          pageinfo['sn'] =self.REQUEST.get('sn','')
         return pageinfo          return pageinfo
           
       
 def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None):  def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None):
         """init document viewer"""          """init document viewer"""
         self.title=title          self.title=title

Removed from v.1.175.2.6  
changed lines
  Added in v.1.175.2.7


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