Changeset 25:e93fb8cadd3a in documentViewer


Ignore:
Timestamp:
Apr 7, 2006, 6:45:48 PM (18 years ago)
Author:
casties
Branch:
default
Message:

new, less preliminary version 0.2

  • lots of stuff rewritten
  • new template system
  • still no access control
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • documentViewer.py

    r22 r25  
    1818import urllib
    1919import zLOG
     20
     21def getInt(number, default=0):
     22    """returns always an int (0 in case of problems)"""
     23    try:
     24        return int(number)
     25    except:
     26        return default
     27   
    2028
    2129def getTextFromNode(nodename):
     
    8088
    8189   
    82     def __init__(self,id,imageViewerUrl,title="",digilibBaseUrl=None):
     90    def __init__(self,id,imageViewerUrl,title="",digilibBaseUrl=None,thumbcols=2,thumbrows=10):
    8391        """init document viewer"""
    8492        self.id=id
    8593        self.title=title
    8694        self.imageViewerUrl=imageViewerUrl
    87         self.digilibBaseUrl = digilibBaseUrl
    88         if not self.digilibBaseUrl:
     95        if not digilibBaseUrl:
    8996            self.digilibBaseUrl = self.findDigilibUrl()
     97        else:
     98            self.digilibBaseUrl = digilibBaseUrl
     99        self.thumbcols = thumbcols
     100        self.thumbrows = thumbrows
    90101        # add template folder so we can always use template.something
    91102        self.manage_addFolder('template')
     
    93104
    94105    security.declareProtected('View','index_html')
    95     def index_html(self,mode,url,start=0,pn=1):
     106    def index_html(self,mode,url,start=None,pn=1):
    96107        '''
    97108        view it
     
    113124        print "dlbaseurl:", self.digilibBaseUrl
    114125
    115         docinfo = self.getDocinfo(mode=mode, url=url)
    116         pageinfo = self.getPageinfo(start=start,current=pn)
     126        docinfo = self.getDocinfo(mode=mode,url=url)
     127        pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo)
    117128        pt = getattr(self.template, 'viewer_main')
    118129        return pt(docinfo=docinfo,pageinfo=pageinfo)
    119130 
    120131 
    121     def imageLink(self,nr):
    122         """link hinter den images"""
    123         paramsTmp=cgi.parse_qs(self.REQUEST['QUERY_STRING'])
    124         params={}
    125         for x in paramsTmp.iteritems():
    126                 params[x[0]]=x[1][0]
    127    
    128         params['pn']=nr
    129         newUrl=self.REQUEST['URL']+"?"+urllib.urlencode(params)
    130         return newUrl
    131        
     132    def getLink(self,param=None,val=None):
     133        """link to documentviewer with parameter param set to val"""
     134        params=cgi.parse_qs(self.REQUEST['QUERY_STRING'])
     135        if param is not None:
     136            if val is None and params.has_key(param):
     137                del params[param]
     138            else:
     139                params[param] = val
     140       
     141        url=self.REQUEST['URL']+"?"+urllib.urlencode(params, doseq=True)
     142        return url
     143
     144   
    132145    def getStyle(self, idx, selected, style=""):
    133         """returns a string with the given style + 'sel' if path == selected."""
     146        """returns a string with the given style and append 'sel' if path == selected."""
    134147        #zLOG.LOG("documentViewer (getstyle)", zLOG.INFO, "idx: %s selected: %s style: %s"%(idx,selected,style))
    135148        if idx == selected:
     
    137150        else:
    138151            return style   
    139 
    140            
    141     def thumbruler(self,cols,rows,start,maximum):
    142         """ruler for thumbs"""
    143         ret=""
    144         paramsTmp=cgi.parse_qs(self.REQUEST['QUERY_STRING'])
    145         params={}
    146         for x in paramsTmp.iteritems():
    147 
    148             if not x[0]=="start":
    149                 params[x[0]]=x[1][0]
    150 
    151         newUrlSelect=self.REQUEST['URL']+"?"+urllib.urlencode(params)   
    152         if start>0:
    153             newStart=max(start-cols*rows,0)
    154             params['start']=newStart
    155             newUrl=self.REQUEST['URL']+"?"+urllib.urlencode(params)
    156             ret+="""<a href="%s">prev</a>"""%newUrl
    157 
    158 
    159         ret+="""<select onChange="location.href='%s&start='+this.options[this.selectedIndex].value">"""%newUrlSelect
    160         nr,rest=divmod(maximum,cols*rows)
    161         if rest > 0:
    162             nr+=1
    163         for i in range(nr):
    164             nr=i*cols*rows
    165            
    166             if (start >= nr) and (start < nr+cols*rows): 
    167                 ret+="""<option value="%s" selected>%s</option>"""%(nr,nr)
    168             else:
    169                 ret+="""<option value="%s">%s</option>"""%(nr,nr)
    170         ret+="</select>"
    171        
    172         if start<maximum:
    173             newStart=min(start+cols*rows,maximum)
    174             params['start']=newStart
    175             newUrl=self.REQUEST['URL']+"?"+urllib.urlencode(params)
    176             ret+="""<a href="%s">next</a>"""%newUrl
    177        
    178         return ret
    179    
    180152       
    181153       
     
    187159            docinfo = {}
    188160           
    189         metaData=self.metadata.main.meta.bib
    190161        if dom is None:
    191162            server="http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary/servlet/Texter?fn="
     
    197168                return docinfo
    198169       
    199         type=dom.xpath("//bib/@type")
    200         if type and (len(type)>0):
    201             type=type[0].value
     170        metaData=self.metadata.main.meta.bib
     171        bibtype=dom.xpath("//bib/@type")
     172        if bibtype and (len(bibtype)>0):
     173            bibtype=bibtype[0].value
    202174        else:
    203             type="generic"
    204         type=type.replace("-"," ")# wrong typesiin index meta "-" instead of " "
    205         hash=metaData.generateMappingForType(type)
    206 
    207         docinfo['author']=getTextFromNode(dom.xpath("//bib/%s"%hash['author'][0])[0])
    208         docinfo['title']=getTextFromNode(dom.xpath("//bib/%s"%hash['title'][0])[0])
    209         docinfo['year']=getTextFromNode(dom.xpath("//bib/%s"%hash['year'][0])[0])
     175            bibtype="generic"
     176        bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC)
     177        bibmap=metaData.generateMappingForType(bibtype)
     178        if len(bibmap) > 0:
     179            docinfo['author']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['author'][0])[0])
     180            docinfo['title']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['title'][0])[0])
     181            docinfo['year']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['year'][0])[0])
    210182       
    211183        return docinfo
     
    243215           pt=getParamFromDigilib(image,'size')
    244216           docinfo['imagePath'] = image
    245            docinfo['numberOfPages'] = pt
     217           docinfo['numPages'] = pt
    246218           
    247219       viewerUrls=dom.xpath("//texttool/digiliburlprefix")
     
    269241        path=path.replace("/mpiwg/online","")
    270242        pt=getParamFromDigilib(path,'size')
    271         docinfo['numberOfPages'] = pt
     243        docinfo['numPages'] = pt
    272244        imageUrl=genericDigilib+"/servlet/Scaler?fn=%s"%path
    273245        docinfo['imageURL'] = imageUrl
     
    300272       
    301273       
    302     def getPageinfo(self, start, current):
     274    def getPageinfo(self, current, start=None, rows=None, cols=None, docinfo=None):
    303275        """returns pageinfo with the given parameters"""
    304276        pageinfo = {}
     277        current = getInt(current)
     278        pageinfo['current'] = current
     279        rows = int(rows or self.thumbrows)
     280        pageinfo['rows'] = rows
     281        cols = int(cols or self.thumbcols)
     282        pageinfo['cols'] = cols
     283        grpsize = cols * rows
     284        pageinfo['groupsize'] = grpsize
     285        start = getInt(start, default=(int(current / grpsize) * grpsize +1))
     286        print "start3:", start
    305287        pageinfo['start'] = start
    306         pageinfo['current'] = current
     288        pageinfo['end'] = start + grpsize
     289        if docinfo is not None:
     290            np = int(docinfo['numPages'])
     291            pageinfo['end'] = min(pageinfo['end'], np)
     292            pageinfo['numgroups'] = int(np / grpsize)
     293            if np % grpsize > 0:
     294                pageinfo['numgroups'] += 1
     295               
    307296        return pageinfo
    308297               
     
    361350#
    362351
    363     def image(self,mode,url,pn):
    364         """give image out"""
    365         if mode=="texttool": #index.meta with texttool information
    366             (viewerUrl,imagepath,textpath)=parseUrlTextTool(url)
    367             if not viewerUrl:
    368                 viewerUrl=self.imageViewerUrl
    369             url=viewerUrl+"pn=%s&fn=%s"%(pn,imagepath[0])
    370             ret="""<iframe height="100%%" width="100%%" src="%s"/>"""%url
    371             return url
    372         elif mode=="imagepath":
    373             url=url.replace("/mpiwg/online","")
    374             url=self.imageViewerUrl+"pn=%s&fn=%s"%(pn,url)
    375             ret="""<iframe height="100%%" width="100%%" src="%s"/>"""%url
    376             return url
    377            
    378        
    379352    def findDigilibUrl(self):
    380353        """try to get the digilib URL from zogilib"""
     
    386359            return None
    387360   
    388     def changeDocumentViewer(self,imageViewerUrl,title="",digilibBaseUrl=None,RESPONSE=None):
     361    def changeDocumentViewer(self,imageViewerUrl,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=10,RESPONSE=None):
    389362        """init document viewer"""
    390363        self.title=title
    391364        self.imageViewerUrl=imageViewerUrl
    392365        self.digilibBaseUrl = digilibBaseUrl
     366        self.thumbrows = thumbrows
     367        self.thumbcols = thumbcols
    393368       
    394369        if RESPONSE is not None:
  • zpt/changeDocumentViewer.zpt

    r24 r25  
    1212        <p class="form-text">This information can be automatically detected if the image viewer above is a Zogilib instance.<br/>
    1313        You must clear this field when you change the image viewer URL above.</p>
     14        <p class="form-optional">Thumbnail rows</p>
     15        <p class="form-element"><input size="3" tal:attributes="value here/thumbrows | default" name="thumbrows"></p>
     16        <p class="form-optional">Thumbnail columns</p>
     17        <p class="form-element"><input size="3" tal:attributes="value here/thumbcols | default" name="thumbcols"></p>
    1418               
    1519                <p><input type="submit" value="change"></p>
  • zpt/thumbs_main.zpt

    r22 r25  
    1 <div tal:define="cols python:2; rows python:10; docinfo python:options['docinfo']; pageinfo python:options['pageinfo']; start python:pageinfo['start']; end python:min(start+cols*rows,int(docinfo['numberOfPages'])); current pageinfo/current; rowsCorrected python:divmod(end-start,cols);">
    2 <span tal:replace="structure python:here.thumbruler(cols,rows,start,int(docinfo['numberOfPages']))"/>
    3 
     1<div tal:define="docinfo options/docinfo; pageinfo options/pageinfo; 
     2  start pageinfo/start; end pageinfo/end; rows pageinfo/rows; cols pageinfo/cols;
     3  current pageinfo/current; grpsize pageinfo/groupsize">
     4<div class="thumbruler">
     5  <span tal:condition="python:(start>1)">
     6    <a tal:attributes="href python:here.getLink(param='start',val=max(start-grpsize,1))">&lt;</a>
     7  </span>
     8  <select tal:attributes="onChange python:'location.href=\'%s&start=\'+this.options[this.selectedIndex].value'%here.getLink(param='start',val=None)">
     9    <option tal:repeat="grp python:range(pageinfo['numgroups'])"
     10      tal:attributes="selected python:(start==grp*grpsize+1); value python:(grp*grpsize+1)"
     11      tal:content="python:(grp*grpsize+1)"/>
     12  </select>
     13  <span tal:condition="python:(start+grpsize<docinfo['numPages'])">
     14    <a tal:attributes="href python:here.getLink(param='start',val=start+grpsize)">&gt;</a>
     15  </span>
     16</div>
    417<table>
    5         <tr tal:repeat="i python:range(rowsCorrected[0])">
    6                 <td align="center" tal:repeat="j python:range(start+i*cols,start+(i+1)*cols)"
    7                         tal:attributes="class python:here.getStyle(str(j+1),current,'thumb')">
    8                 <a tal:attributes="href python:here.imageLink(j+1)">
    9                  <img class="thumbimg" border="0" tal:attributes="src python:docinfo['imageURL']+'&pn=%i&dw=100&dh=100'%(j+1)"/>
    10                  <div class="thumbcap" tal:content="python:(j+1)"/>
     18  <tr tal:repeat="row python:range(rows)">
     19    <tal:block tal:repeat="idx python:range(start+row*cols,start+(row+1)*cols)">
     20      <td align="center" tal:condition="python:(idx <= end)"
     21                        tal:attributes="class python:here.getStyle(idx,current,'thumb')">
     22                <a tal:attributes="href python:here.getLink(param='pn',val=idx)">
     23                  <img class="thumbimg" border="0" tal:attributes="src python:'%s&pn=%d&dw=100&dh=100'%(docinfo['imageURL'],idx)"/>
     24                  <div class="thumbcap" tal:content="idx"/>
    1125                </a>
    12                 </td>
    13         </tr>
    14         <tr tal:condition="python:rowsCorrected[1]>0">
    15                 <td align="center" tal:repeat="j python:range(start+cols*rowsCorrected[0],int(docinfo['numberOfPages']))"
    16                         tal:attributes="class python:here.getStyle(str(j+1),current,'thumb')">
    17                 <a tal:attributes="href python:here.imageLink(j+1)">
    18                  <img class="thumbimg" border="0" tal:attributes="src python:docinfo['imageURL']+'&pn=%i&dw=100&dh=100'%(j+1)"/>
    19                  <div class="thumbcap" tal:content="python:(j+1)"/>
    20                  </a>
    21                 </td>
    22         </tr>
     26          </td>
     27    </tal:block>
     28  </tr>
    2329</table>
    2430</div>
Note: See TracChangeset for help on using the changeset viewer.