Changeset 460:76bc2317146f in documentViewer for documentViewer.py


Ignore:
Timestamp:
Jul 20, 2011, 7:36:57 PM (13 years ago)
Author:
casties
Branch:
elementtree
Message:

more renovation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • documentViewer.py

    r459 r460  
    103103    return '/'.join(path.split('/')[0:-1])
    104104       
     105def normalizeBibtype(bt):
     106    """returns normalised bib type for looking up mappings"""
     107    bt = bt.strip().replace(' ', '-').lower()
     108    return bt
     109
    105110def getBibdataFromDom(dom):
    106111    """returns dict with all elements from bib-tag"""
     
    110115        # put type in @type
    111116        type = bib.get('type')
    112         bibinfo['@type'] = type
     117        bibinfo['@type'] = normalizeBibtype(type)
    113118        # put all subelements in dict
    114119        for e in bib:
     
    576581        bib = getBibdataFromDom(dom)
    577582        docinfo['bib'] = bib
    578        
    579         # extract some fields (author, title, year) according to their mapping
    580         metaData=self.metadata.main.meta.bib
    581         bibtype=bib.get("@type")
    582         #bibtype=dom.xpath("//bib/@type")
    583         if not bibtype:
    584             bibtype="generic"
    585            
    586         bibtype=bibtype.replace("-"," ") # wrong types in index meta "-" instead of " " (not wrong! ROC)
     583        bibtype = bib.get('@type', None)
    587584        docinfo['bib_type'] = bibtype
    588         bibmap=metaData.generateMappingForType(bibtype)
    589         logging.debug("documentViewer (getbibinfofromindexmeta) bibmap:"+repr(bibmap))
    590         logging.debug("documentViewer (getbibinfofromindexmeta) bibtype:"+repr(bibtype))
    591         # if there is no mapping bibmap is empty (mapping sometimes has empty fields)
    592         if len(bibmap) > 0 and bibmap.get('author',None) or bibmap.get('title',None):
     585        if bibtype:
     586            # also store standard mapped metadata for convenience
    593587            try:
    594                 docinfo['author']=bib.get(bibmap['author'][0])
    595             except: pass
    596             try:
    597                 docinfo['title']=bib.get(bibmap['title'][0])
    598             except: pass
    599             try:
    600                 docinfo['year']=bib.get(bibmap['year'][0])
    601             except: pass
    602            
    603             # ROC: why is this here?
    604             #            logging.debug("documentViewer (getbibinfofromindexmeta) using mapping for %s"%bibtype)
    605             #            try:
    606             #                docinfo['lang']=getTextFromNode(dom.find(".//bib/lang")[0])
    607             #            except:
    608             #                docinfo['lang']=''
    609             #            try:
    610             #                docinfo['city']=getTextFromNode(dom.find(".//bib/city")[0])
    611             #            except:
    612             #                docinfo['city']=''
    613             #            try:
    614             #                docinfo['number_of_pages']=getTextFromNode(dom.find(".//bib/number_of_pages")[0])
    615             #            except:
    616             #                docinfo['number_of_pages']=''
    617             #            try:
    618             #                docinfo['series_volume']=getTextFromNode(dom.find(".//bib/series_volume")[0])
    619             #            except:
    620             #                docinfo['series_volume']=''
    621             #            try:
    622             #                docinfo['number_of_volumes']=getTextFromNode(dom.find(".//bib/number_of_volumes")[0])
    623             #            except:
    624             #                docinfo['number_of_volumes']=''
    625             #            try:
    626             #                docinfo['translator']=getTextFromNode(dom.find(".//bib/translator")[0])
    627             #            except:
    628             #                docinfo['translator']=''
    629             #            try:
    630             #                docinfo['edition']=getTextFromNode(dom.find(".//bib/edition")[0])
    631             #            except:
    632             #                docinfo['edition']=''
    633             #            try:
    634             #                docinfo['series_author']=getTextFromNode(dom.find(".//bib/series_author")[0])
    635             #            except:
    636             #                docinfo['series_author']=''
    637             #            try:
    638             #                docinfo['publisher']=getTextFromNode(dom.find(".//bib/publisher")[0])
    639             #            except:
    640             #                docinfo['publisher']=''
    641             #            try:
    642             #                docinfo['series_title']=getTextFromNode(dom.find(".//bib/series_title")[0])
    643             #            except:
    644             #                docinfo['series_title']=''
    645             #            try:
    646             #                docinfo['isbn_issn']=getTextFromNode(dom.find(".//bib/isbn_issn")[0])
    647             #            except:
    648             #                docinfo['isbn_issn']=''           
     588                stdbib = self.metadata.getStdMappedHash(bib)
     589                docinfo['std_bib'] = stdbib
     590                docinfo['author'] = stdbib['author']
     591                docinfo['title'] = stdbib['title']
     592                docinfo['year'] = stdbib['year']
     593            except:
     594                pass
     595
    649596        return docinfo
    650597   
     
    791738        docinfo['imageURL'] = imageUrl
    792739       
     740        #TODO: use getDocinfoFromIndexMeta
    793741        #path ist the path to the images it assumes that the index.meta file is one level higher.
    794742        docinfo = self.getBibinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1)
     
    825773            raise ValueError("Unknown mode %s! Has to be one of 'texttool','imagepath','filepath'."%(mode))
    826774               
    827         # FIXME: fake texturlpath
    828         if not docinfo.has_key('textURLPath'):
    829             docinfo['textURLPath'] = None
    830        
    831775        logging.debug("documentViewer (getdocinfo) docinfo: keys=%s"%docinfo.keys())
    832776        #logging.debug("documentViewer (getdocinfo) docinfo: %s"%docinfo)
     777        # store in session
    833778        self.REQUEST.SESSION['docinfo'] = docinfo
    834779        return docinfo
     
    846791        grpsize = cols * rows
    847792        pageinfo['groupsize'] = grpsize
     793        # what does this do?
    848794        start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1)))
    849795        # int(current / grpsize) * grpsize +1))
     
    855801            pageinfo['numgroups'] = int(np / grpsize)
    856802            if np % grpsize > 0:
    857                 pageinfo['numgroups'] += 1       
     803                pageinfo['numgroups'] += 1
     804               
    858805        pageinfo['viewMode'] = viewMode
    859806        pageinfo['tocMode'] = tocMode
     
    867814        pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30')
    868815        pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '10')
    869         pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1')     
    870         toc = int (pageinfo['tocPN'])
    871         pageinfo['textPages'] =int (toc)
    872        
     816        pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1')
     817        # WTF?:
     818        toc = int(pageinfo['tocPN'])
     819        pageinfo['textPages'] =int(toc)
     820       
     821        # What does this do?
    873822        if 'tocSize_%s'%tocMode in docinfo:
    874823            tocSize = int(docinfo['tocSize_%s'%tocMode])
     
    879828            else:
    880829                tocPages=tocSize/tocPageSize
    881             pageinfo['tocPN'] = min (tocPages,toc)                   
     830               
     831            pageinfo['tocPN'] = min(tocPages,toc)
     832           
    882833        pageinfo['searchPN'] =self.REQUEST.get('searchPN','1')
    883834        pageinfo['sn'] =self.REQUEST.get('sn','')
    884835        return pageinfo
    885    
    886 def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None):
     836
     837   
     838    def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None):
    887839        """init document viewer"""
    888840        self.title=title
Note: See TracChangeset for help on using the changeset viewer.