Changeset 587:6000c7e24d8a in documentViewer


Ignore:
Timestamp:
Nov 15, 2012, 4:09:45 PM (12 years ago)
Author:
casties
Branch:
default
Message:

new parameter "pf" to specify image file name. (still some issues)

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • MpiwgXmlTextServer.py

    r583 r587  
    198198            return None
    199199       
    200         # just checking
    201         if pageinfo['current'] != pn:
    202             logging.warning("getTextPage: current!=pn!")
    203            
    204200        # stuff for constructing full urls
    205201        selfurl = docinfo['viewerUrl']
  • documentViewer.py

    r585 r587  
    4747    # split by /, shorten, and reassemble
    4848    return '/'.join(path.split('/')[0:-cnt])
     49
     50def getPnForPf(docinfo, pf):
     51    """returns image number for image file name or 0"""
     52    if 'imgFileNames' in docinfo:
     53        pn = docinfo['imgFileNames'].get(pf, None)
     54        if pn is None:
     55            # try to cut extension
     56            xi = pf.rfind('.')
     57            if xi > 0:
     58                pf = pf[:xi]
     59                # try again, else return 0
     60                pn = docinfo['imgFileNames'].get(pf, 0)
     61               
     62        return pn
     63   
     64    return 0
    4965
    5066
     
    205221        docinfo = self.getDocinfo(mode=mode,url=url)
    206222        #pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo)
    207         pageinfo = self.getPageinfo(start=start,current=pn, docinfo=docinfo)
     223        pageinfo = self.getPageinfo(start=start,pn=pn, docinfo=docinfo)
    208224        ''' ZDES '''
    209225        pt = getattr(self.template, 'thumbs_main_rss')
     
    219235 
    220236    security.declareProtected('View','index_html')
    221     def index_html(self,url,mode="texttool",viewMode="auto",viewLayer=None,tocMode=None,start=1,pn=1):
     237    def index_html(self,url,mode="texttool",viewMode="auto",viewLayer=None,tocMode=None,start=None,pn=None,pf=None):
    222238        """
    223239        show page
     
    229245        """
    230246       
    231         logging.debug("documentViewer(index_html) mode=%s url=%s viewMode=%s viewLayer=%s start=%s pn=%s"%(mode,url,viewMode,viewLayer,start,pn))
     247        logging.debug("documentViewer(index_html) mode=%s url=%s viewMode=%s viewLayer=%s start=%s pn=%s pf=%s"%(mode,url,viewMode,viewLayer,start,pn,pf))
    232248       
    233249        if not hasattr(self, 'template'):
     
    272288               
    273289        # pageinfo: information about page (not cached)
    274         pageinfo = self.getPageinfo(start=start, current=pn, docinfo=docinfo, userinfo=userinfo, viewMode=viewMode, viewLayer=viewLayer, tocMode=tocMode)
     290        pageinfo = self.getPageinfo(start=start, pn=pn, pf=pf, docinfo=docinfo, userinfo=userinfo, viewMode=viewMode, viewLayer=viewLayer, tocMode=tocMode)
    275291                   
    276292        # get template /template/viewer_$viewMode
     
    452468        return False
    453469
    454 
    455470    def getUserinfo(self):
    456471        """returns userinfo object"""
     
    734749
    735750    def getDocinfoFromDigilib(self, docinfo, path):
    736         infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?mo=dir&fn="+path
     751        infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?fn="+path
    737752        # fetch data
    738753        txt = getHttpData(infoUrl)
     
    742757
    743758        dom = ET.fromstring(txt)
    744         size = getText(dom.find("size"))
     759        dir = dom
     760        # save size
     761        size = dir.findtext('size')
    745762        logging.debug("getDocinfoFromDigilib: size=%s"%size)
    746763        if size:
     
    748765        else:
    749766            docinfo['numPages'] = 0
    750            
    751         # TODO: produce and keep list of image names and numbers
     767            return docinfo
     768           
     769        # save list of image names and numbers
     770        imgNames = {}
     771        for f in dir:
     772            fn = f.findtext('name')
     773            pn = f.findtext('index')
     774            imgNames[fn] = getInt(pn)
     775           
     776        docinfo['imgFileNames'] = imgNames
    752777        return docinfo
    753778           
     
    767792        else:
    768793            # online path
    769            
    770794            server=self.digilibBaseUrl+"/servlet/Texter?fn="
    771795            metaUrl=server+url
     
    783807   
    784808
    785     def getPageinfo(self, current=None, start=None, rows=None, cols=None, docinfo=None, userinfo=None, viewMode=None, viewLayer=None, tocMode=None):
     809    def getPageinfo(self, pn=None, pf=None, start=None, rows=None, cols=None, docinfo=None, userinfo=None, viewMode=None, viewLayer=None, tocMode=None):
    786810        """returns pageinfo with the given parameters"""
    787         logging.debug("getPageInfo(current=%s, start=%s, rows=%s, cols=%s, viewMode=%s, viewLayer=%s, tocMode=%s)"%(current,start,rows,cols,viewMode,viewLayer,tocMode))
     811        logging.debug("getPageInfo(pn=%s, pf=%s, start=%s, rows=%s, cols=%s, viewMode=%s, viewLayer=%s, tocMode=%s)"%(pn,pf,start,rows,cols,viewMode,viewLayer,tocMode))
    788812        pageinfo = {}
    789813        pageinfo['viewMode'] = viewMode
     
    808832
    809833        # TODO: unify current and pn!
    810         current = getInt(current)
    811         pageinfo['current'] = current
    812         pageinfo['pn'] = current
     834        #pageinfo['current'] = current
     835        # pf takes precedence over pn
     836        if pf:
     837            pageinfo['pf'] = pf
     838            pn = getPnForPf(docinfo, pf)
     839        else:
     840            pn = getInt(pn, 1)
     841           
     842        pageinfo['pn'] = pn
    813843        rows = int(rows or self.thumbrows)
    814844        pageinfo['rows'] = rows
     
    817847        grpsize = cols * rows
    818848        pageinfo['groupsize'] = grpsize
    819         # is start is empty use one around current
    820         start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1)))
     849        # is start is empty use one around pn
     850        start = getInt(start, default=(math.ceil(float(pn)/float(grpsize))*grpsize-(grpsize-1)))
    821851        # int(current / grpsize) * grpsize +1))
    822852        pageinfo['start'] = start
     
    845875        if docinfo.get('pageNumbers'):
    846876            # get original page numbers
    847             pageNumber = docinfo['pageNumbers'].get(current, None)
     877            pageNumber = docinfo['pageNumbers'].get(pn, None)
    848878            if pageNumber is not None:
    849879                pageinfo['pageNumberOrig'] = pageNumber['no']
  • version.txt

    r580 r587  
    1 DocumentViewer 2.2.7
     1DocumentViewer 2.2.8
  • zpt/layer_images_annotator.zpt

    r586 r587  
    7373      </form>
    7474      <p tal:define="std modules/Products.PythonScripts.standard">
    75         <a class="button" tal:attributes="href python:'%s/login/login?came_from=%s'%(viewerUrl,std.url_quote(here.getLink()))">log in</a>
     75        <a class="button" tal:attributes="href python:'%s/login/login?came_from=%s'%(viewerUrl,std.url_quote(here.getLink()))">Log in</a>
    7676      </p>
    7777    </div>
  • zpt/layer_text_annotator.zpt

    r557 r587  
    126126      </form>
    127127      <p tal:define="std modules/Products.PythonScripts.standard">
    128         <a class="button" tal:attributes="href python:'%s/login/login?came_from=%s'%(viewerUrl,std.url_quote(here.getLink()))">log in</a>
    129         <!--  <a class="button" tal:attributes="href python:'%s/login/logout?came_from=%s'%(viewerUrl,std.url_quote(here.getLink()))">log out</a> -->
     128        <a class="button" tal:attributes="href python:'%s/login/login?came_from=%s'%(viewerUrl,std.url_quote(here.getLink()))">Log in</a>
    130129      </p>
    131130    </div>
Note: See TracChangeset for help on using the changeset viewer.