Changeset 460:76bc2317146f in documentViewer for documentViewer.py
- Timestamp:
- Jul 20, 2011, 7:36:57 PM (13 years ago)
- Branch:
- elementtree
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
documentViewer.py
r459 r460 103 103 return '/'.join(path.split('/')[0:-1]) 104 104 105 def normalizeBibtype(bt): 106 """returns normalised bib type for looking up mappings""" 107 bt = bt.strip().replace(' ', '-').lower() 108 return bt 109 105 110 def getBibdataFromDom(dom): 106 111 """returns dict with all elements from bib-tag""" … … 110 115 # put type in @type 111 116 type = bib.get('type') 112 bibinfo['@type'] = type117 bibinfo['@type'] = normalizeBibtype(type) 113 118 # put all subelements in dict 114 119 for e in bib: … … 576 581 bib = getBibdataFromDom(dom) 577 582 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) 587 584 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 593 587 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 649 596 return docinfo 650 597 … … 791 738 docinfo['imageURL'] = imageUrl 792 739 740 #TODO: use getDocinfoFromIndexMeta 793 741 #path ist the path to the images it assumes that the index.meta file is one level higher. 794 742 docinfo = self.getBibinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1) … … 825 773 raise ValueError("Unknown mode %s! Has to be one of 'texttool','imagepath','filepath'."%(mode)) 826 774 827 # FIXME: fake texturlpath828 if not docinfo.has_key('textURLPath'):829 docinfo['textURLPath'] = None830 831 775 logging.debug("documentViewer (getdocinfo) docinfo: keys=%s"%docinfo.keys()) 832 776 #logging.debug("documentViewer (getdocinfo) docinfo: %s"%docinfo) 777 # store in session 833 778 self.REQUEST.SESSION['docinfo'] = docinfo 834 779 return docinfo … … 846 791 grpsize = cols * rows 847 792 pageinfo['groupsize'] = grpsize 793 # what does this do? 848 794 start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1))) 849 795 # int(current / grpsize) * grpsize +1)) … … 855 801 pageinfo['numgroups'] = int(np / grpsize) 856 802 if np % grpsize > 0: 857 pageinfo['numgroups'] += 1 803 pageinfo['numgroups'] += 1 804 858 805 pageinfo['viewMode'] = viewMode 859 806 pageinfo['tocMode'] = tocMode … … 867 814 pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30') 868 815 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? 873 822 if 'tocSize_%s'%tocMode in docinfo: 874 823 tocSize = int(docinfo['tocSize_%s'%tocMode]) … … 879 828 else: 880 829 tocPages=tocSize/tocPageSize 881 pageinfo['tocPN'] = min (tocPages,toc) 830 831 pageinfo['tocPN'] = min(tocPages,toc) 832 882 833 pageinfo['searchPN'] =self.REQUEST.get('searchPN','1') 883 834 pageinfo['sn'] =self.REQUEST.get('sn','') 884 835 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): 887 839 """init document viewer""" 888 840 self.title=title
Note: See TracChangeset
for help on using the changeset viewer.