Changeset 607:cb5a9c4f5e3a in documentViewer for documentViewer.py


Ignore:
Timestamp:
Dec 14, 2012, 10:28:31 PM (11 years ago)
Author:
casties
Branch:
default
Message:

CLOSED - # 268: display of subdocuments
https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/ticket/268

File:
1 edited

Legend:

Unmodified
Added
Removed
  • documentViewer.py

    r602 r607  
    161161            #templateFolder._setObject('zogilib',zogilib)
    162162        except Exception, e:
    163             logging.error("Unable to create zogiLib for zogilib: "+str(e))
     163            logging.error("Unable to create zogiLib for 'zogilib': "+str(e))
    164164           
    165165        try:
     
    638638                # replace with numTextPages (text-only?)
    639639                docinfo['numPages'] = docinfo['numTextPages']
     640               
     641        # min and max page no
     642        docinfo['minPageNo'] = docinfo.get('minPageNo', 1)
     643        docinfo['maxPageNo'] = docinfo.get('maxPageNo', docinfo['numPages'])
    640644
    641645        # normalize path
     
    684688        imageDir = getMDText(texttool.get('image', None))
    685689        docPath = getMDText(docinfo.get('documentPath', None))
    686         if imageDir and docPath:
    687             imageDir = os.path.join(docPath, imageDir)
    688             imageDir = imageDir.replace('/mpiwg/online', '', 1)
    689             docinfo['imagePath'] = imageDir
     690        if imageDir:
     691            if imageDir.startswith('/'):
     692                # absolute path
     693                imageDir = imageDir.replace('/mpiwg/online', '', 1)
     694                docinfo['imagePath'] = imageDir
     695               
     696            elif docPath:
     697                # relative path
     698                imageDir = os.path.join(docPath, imageDir)
     699                imageDir = imageDir.replace('/mpiwg/online', '', 1)
     700                docinfo['imagePath'] = imageDir
     701               
     702        # start and end page (for subdocuments of other documents)
     703        imgStartNo = getMDText(texttool.get('image-start-no', None))           
     704        minPageNo = getInt(imgStartNo, 1)
     705        docinfo['minPageNo'] = minPageNo
     706
     707        imgEndNo = getMDText(texttool.get('image-end-no', None))
     708        if imgEndNo:
     709            docinfo['maxPageNo'] = getInt(imgEndNo)
    690710       
    691711        # old style text URL
     
    725745           
    726746        # number of title page (default 1)
    727         docinfo['titlePage'] = getMDText(texttool.get('title-scan-no', 1))
     747        docinfo['titlePage'] = getMDText(texttool.get('title-scan-no', minPageNo))
    728748           
    729749        # old presentation stuff
     
    865885        pageinfo['tocMode'] = tocMode
    866886
     887        minPageNo = docinfo.get('minPageNo', 1)
     888
    867889        # pf takes precedence over pn
    868890        if pf:
     
    873895            self.REQUEST.form['pn'] = pn
    874896        else:
    875             pn = getInt(pn, 1)
     897            pn = getInt(pn, minPageNo)
    876898            pf = getPfForPn(docinfo, pn)
    877899            pageinfo['pf'] = pf
     
    884906        grpsize = cols * rows
    885907        pageinfo['groupsize'] = grpsize
    886         # is start is empty use one around pn
    887         start = getInt(start, default=(math.ceil(float(pn)/float(grpsize))*grpsize-(grpsize-1)))
    888         # int(current / grpsize) * grpsize +1))
     908        # if start is empty use one around pn
     909        grouppn = math.ceil(float(pn)/float(grpsize))*grpsize-(grpsize-1)
     910        # but not smaller than minPageNo
     911        start = getInt(start, max(grouppn, minPageNo))
    889912        pageinfo['start'] = start
    890913        # get number of pages
    891         np = int(docinfo.get('numPages', 0))
    892         if np == 0:
     914        numPages = int(docinfo.get('numPages', 0))
     915        if numPages == 0:
    893916            # try numTextPages
    894             np = docinfo.get('numTextPages', 0)
    895             if np != 0:
    896                 docinfo['numPages'] = np
     917            numPages = docinfo.get('numTextPages', 0)
     918            if numPages != 0:
     919                docinfo['numPages'] = numPages
     920
     921        maxPageNo = docinfo.get('maxPageNo', numPages)
     922        logging.debug("minPageNo=%s maxPageNo=%s start=%s numPages=%s"%(minPageNo,maxPageNo,start,numPages))
     923        np = maxPageNo
    897924
    898925        # cache table of contents
     
    907934        pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft))
    908935        pageinfo['pageZero'] = pageZero
    909         pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np)
     936        pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=minPageNo, maxIdx=np)
    910937        # more page parameters
    911938        pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg')
     
    939966    def getPageBatch(self, start=1, rows=10, cols=2, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0):
    940967        """returns dict with array of page information for one screenfull of thumbnails"""
     968        logging.debug("getPageBatch start=%s minIdx=%s maxIdx=%s"%(start,minIdx,maxIdx))
    941969        batch = {}
    942970        grpsize = rows * cols
     
    944972            maxIdx = start + grpsize
    945973
    946         nb = int(math.ceil(maxIdx / float(grpsize)))
     974        np = maxIdx - minIdx + 1
     975        nb = int(math.ceil(np / float(grpsize)))
    947976        # list of all batch start and end points
    948977        batches = []
    949978        if pageZero:
    950             ofs = 0
    951         else:
    952             ofs = 1
     979            ofs = minIdx - 1
     980        else:
     981            ofs = minIdx
    953982           
    954983        for i in range(nb):
     
    960989
    961990        pages = []
    962         if pageZero and start == 1:
     991        if pageZero and start == minIdx:
    963992            # correct beginning
    964             idx = 0
     993            idx = minIdx - 1
    965994        else:
    966995            idx = start
     
    9821011            pages.append(row)
    9831012           
    984         if start > 1:
    985             batch['prevStart'] = max(start - grpsize, 1)
     1013        if start > minIdx:
     1014            batch['prevStart'] = max(start - grpsize, minIdx)
    9861015        else:
    9871016            batch['prevStart'] = None
Note: See TracChangeset for help on using the changeset viewer.