--- documentViewer/documentViewer.py 2011/07/20 08:22:36 1.175.2.6 +++ documentViewer/documentViewer.py 2011/07/20 19:36:57 1.175.2.7 @@ -102,6 +102,11 @@ def getParentDir(path): """returns pathname shortened by one""" 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): """returns dict with all elements from bib-tag""" bibinfo = {} @@ -109,7 +114,7 @@ def getBibdataFromDom(dom): if bib is not None: # put type in @type type = bib.get('type') - bibinfo['@type'] = type + bibinfo['@type'] = normalizeBibtype(type) # put all subelements in dict for e in bib: bibinfo[e.tag] = getText(e) @@ -575,77 +580,19 @@ class documentViewer(Folder): # put all raw bib fields in dict "bib" bib = getBibdataFromDom(dom) docinfo['bib'] = bib - - # 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) + bibtype = bib.get('@type', None) docinfo['bib_type'] = bibtype - bibmap=metaData.generateMappingForType(bibtype) - logging.debug("documentViewer (getbibinfofromindexmeta) bibmap:"+repr(bibmap)) - 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): + if bibtype: + # also store standard mapped metadata for convenience try: - docinfo['author']=bib.get(bibmap['author'][0]) - except: pass - try: - docinfo['title']=bib.get(bibmap['title'][0]) - except: pass - try: - docinfo['year']=bib.get(bibmap['year'][0]) - 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']='' + stdbib = self.metadata.getStdMappedHash(bib) + docinfo['std_bib'] = stdbib + docinfo['author'] = stdbib['author'] + docinfo['title'] = stdbib['title'] + docinfo['year'] = stdbib['year'] + except: + pass + return docinfo @@ -790,6 +737,7 @@ class documentViewer(Folder): imageUrl=self.digilibBaseUrl+"/servlet/Scaler?fn="+path docinfo['imageURL'] = imageUrl + #TODO: use getDocinfoFromIndexMeta #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.getAuthinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1) @@ -824,12 +772,9 @@ class documentViewer(Folder): logging.error("documentViewer (getdocinfo) unknown mode: %s!"%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: %s"%docinfo) + # store in session self.REQUEST.SESSION['docinfo'] = docinfo return docinfo @@ -845,6 +790,7 @@ class documentViewer(Folder): pageinfo['cols'] = cols grpsize = cols * rows pageinfo['groupsize'] = grpsize + # what does this do? start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1))) # int(current / grpsize) * grpsize +1)) pageinfo['start'] = start @@ -854,7 +800,8 @@ class documentViewer(Folder): pageinfo['end'] = min(pageinfo['end'], np) pageinfo['numgroups'] = int(np / grpsize) if np % grpsize > 0: - pageinfo['numgroups'] += 1 + pageinfo['numgroups'] += 1 + pageinfo['viewMode'] = viewMode pageinfo['tocMode'] = tocMode pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') @@ -866,10 +813,12 @@ class documentViewer(Folder): pageinfo['highlightQuery'] = self.REQUEST.get('highlightQuery','') pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30') pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '10') - pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1') - toc = int (pageinfo['tocPN']) - pageinfo['textPages'] =int (toc) + pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1') + # WTF?: + toc = int(pageinfo['tocPN']) + pageinfo['textPages'] =int(toc) + # What does this do? if 'tocSize_%s'%tocMode in docinfo: tocSize = int(docinfo['tocSize_%s'%tocMode]) tocPageSize = int(pageinfo['tocPageSize']) @@ -878,12 +827,15 @@ class documentViewer(Folder): tocPages=tocSize/tocPageSize+1 else: tocPages=tocSize/tocPageSize - pageinfo['tocPN'] = min (tocPages,toc) + + pageinfo['tocPN'] = min(tocPages,toc) + pageinfo['searchPN'] =self.REQUEST.get('searchPN','1') pageinfo['sn'] =self.REQUEST.get('sn','') 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""" self.title=title self.digilibBaseUrl = digilibBaseUrl