Changeset 482:7ca8ac7db06e in documentViewer


Ignore:
Timestamp:
Aug 16, 2011, 4:27:08 PM (13 years ago)
Author:
casties
Branch:
elementtree
Message:

more new template stuff. more batching methods in documentViewer.

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • MpdlXmlTextServer.py

    r478 r482  
    480480        return docinfo
    481481   
    482     def getTocPage(self, mode="text", pn=0, pageinfo=None, docinfo=None):
     482    def getTocPage(self, mode="text", pn=None, start=None, size=None, pageinfo=None, docinfo=None):
    483483        """returns single page from the table of contents"""
    484484        logging.debug("getTocPage mode=%s, pn=%s"%(mode,pn))
     
    495495        if not tocxml:
    496496            logging.error("getTocPage: unable to find tocXML")
    497             return "No ToC"
    498        
    499         pagesize = pageinfo['tocPageSize']
    500         tocPN = pageinfo['tocPN']
    501         if not pn:
    502             pn = tocPN
     497            return "Error: no table of contents!"
     498       
     499        if size is None:
     500            size = pageinfo.get('tocPageSize', 30)
     501           
     502        if start is None:
     503            start = (pn - 1) * size
    503504
    504505        fulltoc = ET.fromstring(tocxml)
     
    506507        if fulltoc:
    507508            # paginate
    508             start = (pn - 1) * pagesize * 2
    509             len = pagesize * 2
    510             del fulltoc[:start]
     509            first = (start - 1) * 2
     510            len = size * 2
     511            del fulltoc[:first]
    511512            del fulltoc[len:]
    512513            tocdivs = fulltoc
     
    526527                        logging.warning("getTocPage: Problem with link=%s"%href)
    527528                       
    528             return serialize(tocdivs)
     529            # fix two-divs-per-row with containing div
     530            newtoc = ET.Element('div', {'class':'queryResultPage'})
     531            for (d1,d2) in zip(tocdivs[::2],tocdivs[1::2]):
     532                e = ET.Element('div',{'class':'tocline'})
     533                e.append(d1)
     534                e.append(d2)
     535                newtoc.append(e)
     536               
     537            return serialize(newtoc)
     538       
     539        return "ERROR: no table of contents!"
    529540   
    530541   
  • css/docuviewer.css

    r481 r482  
    1111
    1212div.col_left {
    13     /* would be better without fixed width */
    1413    max-width: 20em;
    1514}
  • documentViewer.py

    r480 r482  
    556556            docinfo['imagePath'] = url.replace('/mpiwg/online/', '', 1)
    557557
    558            
    559 
    560558        # number of images from digilib
    561559        if docinfo.get('imagePath', None):
     
    787785
    788786
    789     def getPageBatch(self, start=None, rows=None, cols=None, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0):
     787    def getPageBatch(self, start=1, rows=10, cols=2, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0):
    790788        """returns dict with array of page informations for one screenfull of thumbnails"""
     789        batch = {}
    791790        grpsize = rows * cols
    792791        if maxIdx == 0:
    793792            maxIdx = start + grpsize
     793
     794        nb = int(math.ceil(maxIdx / float(grpsize)))
     795        # list of all batch start and end points
     796        batches = []
     797        if pageZero:
     798            ofs = 0
     799        else:
     800            ofs = 1
     801           
     802        for i in range(nb):
     803            s = i * grpsize + ofs
     804            e = min((i + 1) * grpsize + ofs - 1, maxIdx)
     805            batches.append({'start':s, 'end':e})
     806           
     807        batch['batches'] = batches
    794808
    795809        pages = []
     
    816830            pages.append(row)
    817831           
    818         batch = {}
    819832        if start > 1:
    820833            batch['prevStart'] = max(start - grpsize, 1)
     
    828841
    829842        batch['pages'] = pages
    830         #logging.debug("getPageList returns=%s"%(batch))
     843        return batch
     844       
     845    def getBatch(self, start=1, size=10, end=0, data=None, fullData=True):
     846        """returns dict with information for one screenfull of data."""
     847        batch = {}
     848        if end == 0:
     849            end = start + size                   
     850           
     851        nb = int(math.ceil(end / float(size)))
     852        # list of all batch start and end points
     853        batches = []
     854        for i in range(nb):
     855            s = i * size + 1
     856            e = min((i + 1) * size, end)
     857            batches.append({'start':s, 'end':e})
     858           
     859        batch['batches'] = batches
     860        # list of elements in this batch
     861        this = []
     862        j = 0
     863        for i in range(start, min(start+size, end)):
     864            if data:
     865                if fullData:
     866                    d = data[i]
     867                else:
     868                    d = data[j]
     869                    j += 1
     870           
     871            else:
     872                d = i+1
     873               
     874            this.append(d)
     875           
     876        batch['this'] = this
     877        if start > 1:
     878            batch['prevStart'] = max(start - size, 1)
     879        else:
     880            batch['prevStart'] = None
     881           
     882        if start + size < end:
     883            batch['nextStart'] = start + size
     884        else:
     885            batch['nextStart'] = None
     886       
    831887        return batch
    832888       
  • zpt/toc_figures.zpt

    r481 r482  
    88  <!-- block used for main content area -->
    99  <div class="col_left" metal:define-macro="main"
    10     tal:define="pn pageinfo/tocPN; tocsize docinfo/tocSize_figures; grpsize pageinfo/tocPageSize;
    11                 maxpn python:int(math.ceil(tocsize/float(grpsize)));">
     10    tal:define="start pageinfo/start; tocsize docinfo/tocSize_figures; grpsize pageinfo/tocPageSize;
     11                batch python:here.getBatch(start=start,size=grpsize,end=tocsize);">
    1212    <ul class="switcher">
    1313      <li><a
     
    1818        <a tal:attributes="href python:here.getLink('tocMode','text')">Content</a>
    1919      </li>
    20       <li
     20      <li class="sel"
    2121        tal:condition="python:docpath and docinfo.get('numFigureEntries', None)">
    2222        <a
     
    3030      <form class="autosubmit" tal:attributes="action viewerUrl">
    3131        <input type="hidden"
    32           tal:define="params python:here.getParams('tocPN', None)"
     32          tal:define="params python:here.getParams('start', None)"
    3333          tal:repeat="param params"
    3434          tal:attributes="name param; value python:params[param]" />
    35         <a tal:condition="python:(pn>1)"
    36           tal:attributes="href python:here.getLink('tocPN',pn-1)">&lt;</a>
    37         <span tal:condition="python:(pn<=1)">&lt;</span>
    38         <select class="autosubmit" name="tocPN">
    39           <option tal:repeat="idx python:range(maxpn)"
    40             tal:attributes="selected python:(pn==idx*grpsize+1); value python:(idx*grpsize+1)"
    41             tal:content="python:str(idx*grpsize+1)" />
     35        <a tal:condition="batch/prevStart"
     36          tal:attributes="href python:here.getLink('start',batch['prevStart'])">&lt;</a>
     37        <span tal:condition="not:batch/prevStart">&lt;</span>
     38        <select class="autosubmit" name="start">
     39          <option tal:repeat="grp batch/batches"
     40            tal:attributes="selected python:(start==grp['start']); value grp/start"
     41            tal:content="string:${grp/start} - ${grp/end}" />
    4242        </select>
    4343        <input type="submit" value="Go" />
    44         <a tal:condition="python:(pn<maxpn)"
    45           tal:attributes="href python:here.getLink('tocPN',pn+1)">&gt;</a>
    46         <span tal:condition="python:(pn>=maxpn)">&gt;</span>
     44        <a tal:condition="batch/nextStart"
     45          tal:attributes="href python:here.getLink('start',batch['nextStart'])">&gt;</a>
     46        <span tal:condition="not:batch/nextStart">&gt;</span>
    4747      </form>
    4848    </div>
    4949    <div class="content"
    50       tal:content="structure python:here.getTocPage(mode='figures',pageinfo=pageinfo,docinfo=docinfo)" />
     50      tal:content="structure python:here.getTocPage(mode='figures',start=start,pageinfo=pageinfo,docinfo=docinfo)" />
    5151  </div>
    5252  <!-- toc -->
  • zpt/toc_text.zpt

    r481 r482  
    88  <!-- block used for main content area -->
    99  <div class="col_left" metal:define-macro="main"
    10      tal:define="docinfo options/docinfo; pageinfo options/pageinfo; 
    11   pn python:int(pageinfo['tocPN']); tocsize python:int(docinfo['tocSize_text']); grpsize python:int(pageinfo['tocPageSize']);
    12   maxpn python:int(tocsize/grpsize);">
    13   <div class="thumbruler">
    14     <span tal:condition="python:(pn>1)">
    15       <a tal:attributes="href python:here.getLink(param='tocPN',val=pn-1)">&lt;</a>
    16     </span>
    17     <span tal:content="string:$pn of $tocsize"/>
    18     <span>
    19     <a tal:attributes="href python:here.getLink(param='tocPN',val=pn+1)">&gt;</a>
    20   </span>
    21 </div>
    22   <div class="content" tal:content="structure python:here.getTocPage(mode='text',pageinfo=pageinfo,docinfo=docinfo)"/>
    23 </div> <!-- toc -->
     10    tal:define="start pageinfo/start; tocsize docinfo/tocSize_text; grpsize pageinfo/tocPageSize;
     11                batch python:here.getBatch(start=start,size=grpsize,end=tocsize);">
     12    <ul class="switcher">
     13      <li><a
     14        tal:attributes="href python:here.getLink('tocMode','thumbs')">Thumbnails</a>
     15      </li>
     16      <li class="sel"
     17        tal:condition="python:docpath and docinfo.get('numTocEntries', None)">
     18        <a tal:attributes="href python:here.getLink('tocMode','text')">Content</a>
     19      </li>
     20      <li
     21        tal:condition="python:docpath and docinfo.get('numFigureEntries', None)">
     22        <a
     23        tal:attributes="href python:here.getLink('tocMode','figures')">Figures</a>
     24      </li>
     25      <li><a
     26        tal:attributes="href python:here.getLink('tocMode','none')">None</a>
     27      </li>
     28    </ul>
     29    <div class="ruler">
     30      <form class="autosubmit" tal:attributes="action viewerUrl">
     31        <input type="hidden"
     32          tal:define="params python:here.getParams('start', None)"
     33          tal:repeat="param params"
     34          tal:attributes="name param; value python:params[param]" />
     35        <a tal:condition="batch/prevStart"
     36          tal:attributes="href python:here.getLink('start',batch['prevStart'])">&lt;</a>
     37        <span tal:condition="not:batch/prevStart">&lt;</span>
     38        <select class="autosubmit" name="start">
     39          <option tal:repeat="grp batch/batches"
     40            tal:attributes="selected python:(start==grp['start']); value grp/start"
     41            tal:content="string:${grp/start} - ${grp/end}" />
     42        </select>
     43        <input type="submit" value="Go" />
     44        <a tal:condition="batch/nextStart"
     45          tal:attributes="href python:here.getLink('start',batch['nextStart'])">&gt;</a>
     46        <span tal:condition="not:batch/nextStart">&gt;</span>
     47      </form>
     48    </div>
     49    <div class="content"
     50      tal:content="structure python:here.getTocPage(mode='text',start=start,pageinfo=pageinfo,docinfo=docinfo)" />
     51  </div>
     52  <!-- toc -->
    2453</body>
    2554</html>
  • zpt/toc_thumbs.zpt

    r481 r482  
    3939          <select class="autosubmit" name="start"
    4040            tal:define="ofs python:test(pageinfo['pageZero'],0,1)">
    41             <tal:block tal:repeat="grp python:range(numgroups)">
    42               <option tal:define="idx python:max(grp*grpsize+ofs,1)"
    43                 tal:attributes="selected python:start==idx; value idx;"
    44                 tal:content="python:'%s - %s'%(idx,min((grp+1)*grpsize+ofs-1,numPages))" />
     41            <tal:block >
     42              <option tal:repeat="grp pageBatch/batches"
     43                tal:attributes="selected python:start==grp['start']; value grp/start;"
     44                tal:content="string:${grp/start} - ${grp/end}" />
    4545            </tal:block>
    4646          </select>
Note: See TracChangeset for help on using the changeset viewer.