Changeset 490:6f116b86a226 in documentViewer


Ignore:
Timestamp:
Aug 29, 2011, 2:39:50 PM (13 years ago)
Author:
casties
Branch:
elementtree
Message:

more new template stuff. moved ImageFile? index method to SrvTxtUtils?

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • SrvTxtUtils.py

    r464 r490  
    11"""Utility methods for handling XML, reading HTTP, etc"""
    22
     3from App.ImageFile import ImageFile
     4from App.Common import rfc1123_date
     5
    36import sys
     7import os
     8import stat
    49import urllib
    510import urllib2
     
    712
    813
    9 srvTxtUtilsVersion = "1.0"
     14srvTxtUtilsVersion = "1.3"
    1015
    1116def getInt(number, default=0):
     
    1621        return int(default)
    1722
    18 def getText(node):
     23def getAt(array, idx, default=None):
     24    """returns element idx from array or default (in case of problems)"""
     25    try:
     26        return array[idx]
     27    except:
     28        return default
     29
     30def getText(node, recursive=0):
    1931    """returns all text content of a node and its subnodes"""
    2032    if node is None:
    21         return ""
     33        return ''
     34   
    2235    # ElementTree:
    23     text = node.text or ""
     36    text = node.text or ''
    2437    for e in node:
    25         text += getText(e)
     38        if recursive:
     39            text += getText(e)
     40        else:
     41            text += e.text or ''
    2642        if e.tail:
    2743            text += e.tail
     
    8298    #return None
    8399
     100
     101def refreshingImageFileIndexHtml(self, REQUEST, RESPONSE):
     102    """index_html method for App.ImageFile that updates the file info for each request."""
     103    stat_info = os.stat(self.path)
     104    self.size = stat_info[stat.ST_SIZE]
     105    self.lmt = float(stat_info[stat.ST_MTIME]) or time.time()
     106    self.lmh = rfc1123_date(self.lmt)
     107    # call original method
     108    return ImageFile.index_html(self, REQUEST, RESPONSE)
     109
  • documentViewer.py

    r489 r490  
    33from Products.PageTemplates.PageTemplateFile import PageTemplateFile
    44from App.ImageFile import ImageFile
    5 from App.Common import rfc1123_date
    6 #from Products.ZSimpleFile.ZSimpleFile import ZSimpleFile
    75from AccessControl import ClassSecurityInfo
    86from AccessControl import getSecurityManager
     
    1210
    1311import os
    14 import stat
    1512import sys
    1613import urllib
     
    2118import string
    2219
    23 from SrvTxtUtils import getInt, getText, getHttpData
    24 
    25 def logger(txt,method,txt2):
    26     """logging"""
    27     logging.info(txt+ txt2)
    28    
     20from SrvTxtUtils import getInt, getText, getHttpData, refreshingImageFileIndexHtml
    2921   
    3022def serializeNode(node, encoding="utf-8"):
     
    10799    return '/'.join(path.split('/')[0:-cnt])
    108100
    109 def devImageFileIndexHtml(self, REQUEST, RESPONSE):
    110     """index_html method for App.ImageFile that updates the file info for each request."""
    111     stat_info = os.stat(self.path)
    112     self.size = stat_info[stat.ST_SIZE]
    113     self.lmt = float(stat_info[stat.ST_MTIME]) or time.time()
    114     self.lmh = rfc1123_date(self.lmt)
    115     # call original method
    116     return ImageFile.index_html(self, REQUEST, RESPONSE)
    117 
    118101##
    119102## documentViewer class
     
    149132    docuviewer_css = ImageFile('css/docuviewer.css',globals())
    150133    # make ImageFile better for development
    151     docuviewer_css.index_html = devImageFileIndexHtml
     134    docuviewer_css.index_html = refreshingImageFileIndexHtml
    152135   
    153136   
  • zpt/viewer_images.zpt

    r489 r490  
    5151              left python:test(flowLtr,prev,next); right python:test(flowLtr,next,prev);
    5252              leftest python:test(flowLtr,first,last); rightest python:test(flowLtr,last,first);">
    53     <div class="page-head" metal:use-macro="here/template/head_main/macros/main" />
     53    <div class="page-head">
     54      <metal:block metal:use-macro="here/template/head_main/macros/main" />
     55    </div>
    5456    <div class="page-body" tal:condition="python:here.isAccessible(docinfo)">
    5557      <!--table of contents-->
  • zpt/viewer_text.zpt

    r489 r490  
    11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    2     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    33<html xmlns="http://www.w3.org/1999/xhtml"
    4   tal:define="docinfo options/docinfo; pageinfo options/pageinfo; viewMode pageinfo/viewMode;
    5               tocMode pageinfo/tocMode; viewType pageinfo/viewType; viewerUrl docinfo/viewerUrl;
    6               numPages docinfo/numPages | nothing;">
    7 <head>
    8   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    9   <title tal:content="python:docinfo.get('creator',' ') + ' - ' + docinfo.get('title',' ')"/>
    10   <link rel="stylesheet" href="template/docuviewer_css" type="text/css">
    11 </head>
    12 <body tal:condition="numPages">
    13   <tal:block tal:define="docpath docinfo/textURLPath;
    14               pn pageinfo/pn;
    15               flowLtr python:pageinfo.get('pageFlow','ltr')!='rtl';
    16               prev python:test(pn>1,pn-1,None); next python:test(pn<numPages,pn+1,None);
    17               first python:test(pn>1,1,None); last python:test(pn<numPages,numPages,None);
    18               left python:test(flowLtr,prev,next); right python:test(flowLtr,next,prev);
    19               leftest python:test(flowLtr,first,last); rightest python:test(flowLtr,last,first);
    20               textPage python:here.getTextPage(mode=viewType, pn=pn, docinfo=docinfo, pageinfo=pageinfo);">
    21   <div class="page-head" metal:use-macro="here/template/head_main/macros/main" />
    22   <div class="page-body" tal:condition="python:here.isAccessible(docinfo)">
    23     <!--table of contents-->
    24     <div class="col-left">
    25       <metal:block metal:use-macro="python:path('here/template/toc_%s/macros/main'%tocMode)" />
    26     </div>
     4      tal:define="docinfo options/docinfo; pageinfo options/pageinfo; viewMode pageinfo/viewMode;
     5                  tocMode pageinfo/tocMode; viewType pageinfo/viewType; viewerUrl docinfo/viewerUrl;
     6                  numPages docinfo/numPages | nothing;">
     7  <head>
     8    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     9      <title tal:content="python:docinfo.get('creator',' ') + ' - ' + docinfo.get('title',' ')"/>
     10      <link rel="stylesheet" href="template/docuviewer_css" type="text/css">
     11      </head>
     12      <body tal:condition="numPages">
     13        <tal:block tal:define="docpath docinfo/textURLPath;
     14                               pn pageinfo/pn;
     15                               flowLtr python:pageinfo.get('pageFlow','ltr')!='rtl';
     16                               prev python:test(pn>1,pn-1,None); next python:test(pn<numPages,pn+1,None);
     17                               first python:test(pn>1,1,None); last python:test(pn<numPages,numPages,None);
     18                               left python:test(flowLtr,prev,next); right python:test(flowLtr,next,prev);
     19                               leftest python:test(flowLtr,first,last); rightest python:test(flowLtr,last,first);
     20                               textPage python:here.getTextPage(mode=viewType, pn=pn, docinfo=docinfo, pageinfo=pageinfo);">
     21          <div class="page-head">
     22            <metal:block metal:use-macro="here/template/head_main/macros/main" />
     23          </div>
     24          <div class="page-body" tal:condition="python:here.isAccessible(docinfo)">
     25            <!--table of contents-->
     26            <div class="col-left">
     27              <metal:block metal:use-macro="python:path('here/template/toc_%s/macros/main'%tocMode)" />
     28            </div>
    2729
    28     <!-- text page -->
    29     <div class="col-main">
    30       <div class="ruler">
    31         <form class="autosubmit" tal:attributes="action viewerUrl">
    32           <input type="hidden" tal:define="params python:here.getParams('pn', None)"
    33             tal:repeat="param params" tal:attributes="name param; value python:params[param]" />
    34         page
    35         <a tal:condition="leftest" tal:attributes="href python:here.getLink('pn',leftest)">|&lt;</a>
    36         <span tal:condition="not:leftest">|&lt;</span>
    37         <a tal:condition="left" tal:attributes="href python:here.getLink('pn',left)">&lt;</a>
    38         <span tal:condition="not:left">&lt;</span>
    39         <input class="autosubmit" size="3" type="text" name="pn" tal:attributes="value pn" />
    40         <tal:block tal:define="originalPage pageinfo/pageNumberOrig | nothing"
    41                tal:condition="python:originalPage!=None">
    42           (<span tal:replace="originalPage"/><span tal:define="originalPageNorm pageinfo/pageNumberOrigNorm | nothing" tal:condition="python:originalPageNorm!=None">[<span tal:replace="originalPageNorm"/>]</span>)     
     30            <!-- text page -->
     31            <div class="col-main">
     32              <div class="ruler">
     33                <form class="autosubmit" tal:attributes="action viewerUrl">
     34                  <input type="hidden" tal:define="params python:here.getParams('pn', None)"
     35                         tal:repeat="param params" tal:attributes="name param; value python:params[param]" />
     36                  page
     37                  <a tal:condition="leftest" tal:attributes="href python:here.getLink('pn',leftest)">|&lt;</a>
     38                  <span tal:condition="not:leftest">|&lt;</span>
     39                  <a tal:condition="left" tal:attributes="href python:here.getLink('pn',left)">&lt;</a>
     40                  <span tal:condition="not:left">&lt;</span>
     41                  <input class="autosubmit" size="3" type="text" name="pn" tal:attributes="value pn" />
     42                  <tal:block tal:define="originalPage pageinfo/pageNumberOrig | nothing"
     43                             tal:condition="python:originalPage!=None">
     44                    (<span tal:replace="originalPage"/><span tal:define="originalPageNorm pageinfo/pageNumberOrigNorm | nothing" tal:condition="python:originalPageNorm!=None">
     45                    [<span tal:replace="originalPageNorm"/>]</span>)     
     46                  </tal:block>
     47                  <input type="submit" value="Go" />
     48                  of
     49                  <span tal:replace="numPages"/>
     50                  <a tal:condition="right" tal:attributes="href python:here.getLink('pn',right)">&gt;</a>
     51                  <span tal:condition="not:right">&gt;</span>
     52                  <a tal:condition="rightest" tal:attributes="href python:here.getLink('pn',rightest)">&gt;|</a>
     53                  <span tal:condition="not:rightest">&gt;|</span>
     54                </form>
     55              </div> <!-- ruler -->
     56              <ul class="switcher">
     57                <li>
     58                  <a tal:attributes="href python:here.getLink('viewMode','images')">Image</a>
     59                </li>
     60                <li class="sel">Text</li>
     61              </ul>
     62              <div class="content">
     63                <div class="pageHeaderTitle" tal:condition="exists:pageinfo/pageHeaderTitle" tal:content="structure pageinfo/pageHeaderTitle"/>
     64                <tal:block tal:replace="structure textPage"/>
     65              </div>
     66            </div> <!-- col-main -->
     67           
     68            <!-- right-side options -->
     69            <div class="col-right">
     70              <!--"BEGIN TEXT DISPLAY"  -->
     71              <div class="options">
     72                <h4>Text display</h4>
     73                <form tal:attributes="action viewerUrl" class="autosubmit">
     74                  <input type="hidden" tal:define="params python:here.getParams(params={'viewType':None})" tal:repeat="param params" tal:attributes="name param; value python:params[param]"/>
     75                  <input class="autosubmit" type="radio" name="viewType" value="" tal:attributes="checked python:viewType!='xml'"/> Text<br/>
     76                  <span class="optionsText" tal:condition="python:viewType!='xml'">
     77                    &nbsp;&nbsp;<input type="checkbox" class="autosubmit" name="viewType" value="dict" tal:attributes="checked python:viewType=='dict'"/> Dictionary<br/>
     78                  </span>
     79                  <span class="optionsText" tal:condition="python:viewType!='xml' and docinfo.get('numPlaces',0)">
     80                    &nbsp;&nbsp;<input type="checkbox" class="autosubmit" name="viewType" value="gis" tal:attributes="checked python:viewType=='gis'"/> Places<br/>
     81                  </span> <input type="radio" class="autosubmit" name="viewType" tal:attributes="value string:xml; checked python:viewType=='xml'"/> XML<br/>
     82                  <input type="submit" value="Go!"/>
     83                </form>
     84              </div>
     85              <!--"END TEXT DISPLAY"-->
     86             
     87              <!--"BEGIN TEXT SIZE"-->
     88              <div class="options">
     89                <h4>Text size</h4>
     90                <div class="fsizer">
     91                  &nbsp;
     92                  <a href="javascript:fontSize(12);" class="fs_sml">S</a>
     93                  <a href="javascript:fontSize(14);" class="fs_med">M</a>
     94                  <a href="javascript:fontSize(16);" class="fs_lrg">L</a>
     95                </div>
     96              </div>
     97              <!--"END TEXT SIZE"-->   
     98             
     99              <!--"BEGIN DICTIONARY OVERVIEW"-->
     100              <div class="options" tal:condition="python:viewType=='dict'">
     101                <h4>Dictionary view</h4>
     102                <form name="f3" action="">
     103                  <input type="radio" name="r3"/>Tab<br/>
     104                  <input type="radio" name="r3"/>Window<br/>
     105                </form>
     106              </div>
     107              <!--"END DICTIONARY OVERVIEW"-->
     108             
     109              <!--"BEGIN TEXT NORMALIZATION"-->
     110              <div class="options" tal:condition="python:viewType!='xml'">
     111                <h4>Text normalization</h4>
     112                <form tal:attributes="action viewerUrl" class="autosubmit"
     113                      tal:define="norm python:pageinfo.get('characterNormalization','regPlusNorm');">
     114                  <input type="hidden" tal:define="params python:here.getParams('characterNormalization',None)" tal:repeat="param params" tal:attributes="name param; value python:params[param]"/>
     115                  <input type="radio" class="autosubmit" name="characterNormalization" value="orig" tal:attributes="checked python:norm=='orig'"/> Original<br/>
     116                  <input type="radio" class="autosubmit" name="characterNormalization" value="reg" tal:attributes="checked python:norm=='reg'"/> Regularized<br/>
     117                  <input type="radio" class="autosubmit" name="characterNormalization" value="regPlusNorm" tal:attributes="checked python:norm=='regPlusNorm'"/> Normalized<br/>
     118                  <input type="submit" value="Go!"/>
     119                </form>
     120              </div>
     121              <!--"END TEXT NORMALIZATION"-->
     122             
     123              <!--"BEGIN PLACES"-->
     124              <div class="options" tal:condition="python:viewType=='gis'"> 
     125                <tal:block tal:define="gisPlaces python:here.getGisPlaces(docinfo=docinfo, pageinfo=pageinfo); gisAllPlaces python:here.getAllGisPlaces(docinfo=docinfo, pageinfo=pageinfo);">
     126                  <span><b>Places</b></span><br/>(Link to extern:)<br/>
     127                  <span>Page</span>
     128                  <span style="float:right">
     129                    <a tal:attributes="href python:'http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/db/mpdl/%s?id=%s&format=%s'%(name,gisPlaces,'gis')" target="_blank">
     130                      <img src="images/arrow.png" alt=""/>
     131                    </a>
     132                  </span><br/>
     133                  <span>Book</span>
     134                  <span style="float:right">
     135                    <a tal:attributes="href python:'http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/db/mpdl/%s?format=%s'%(name,'gis')" target="_blank">
     136                      <img src="images/arrow.png" alt=""/>
     137                    </a>
     138                  </span><br/>
     139                </tal:block>
     140              </div>
     141              <!--"END PLACES"-->   
     142            </div> <!-- col-right -->
     143           
     144          </div> <!-- page-body -->
     145          <div class="page_body" tal:condition="python:not here.isAccessible(docinfo)">
     146            <div class="errortext">Sorry, access to this document is restricted.</div>
     147          </div>
    43148        </tal:block>
    44         <input type="submit" value="Go" />
    45         of
    46         <span tal:replace="numPages"/>
    47         <a tal:condition="right" tal:attributes="href python:here.getLink('pn',right)">&gt;</a>
    48         <span tal:condition="not:right">&gt;</span>
    49         <a tal:condition="rightest" tal:attributes="href python:here.getLink('pn',rightest)">&gt;|</a>
    50         <span tal:condition="not:rightest">&gt;|</span>
    51         </form>
    52       </div> <!-- ruler -->
    53       <ul class="switcher">
    54         <li>
    55             <a tal:attributes="href python:here.getLink('viewMode','images')">Image</a>
    56         </li>
    57         <li class="sel">Text</li>
    58       </ul>
    59       <div class="content">
    60         <div class="pageHeaderTitle" tal:condition="exists:pageinfo/pageHeaderTitle" tal:content="structure pageinfo/pageHeaderTitle"/>
    61         <tal:block tal:replace="structure textPage"/>
    62       </div>
    63     </div> <!-- col-main -->
    64    
    65     <!-- right-side options -->
    66     <div class="col-right">
    67         <!--"BEGIN TEXT DISPLAY"  -->
    68         <div class="options">
    69         <h3>Text display</h3>
    70         <form tal:attributes="action viewerUrl" class="autosubmit">
    71               <input type="hidden" tal:define="params python:here.getParams(params={'viewType':None})" tal:repeat="param params" tal:attributes="name param; value python:params[param]"/>
    72           <input class="autosubmit" type="radio" name="viewType" value="" tal:attributes="checked python:viewType!='xml'"/> Text<br/>
    73               <span class="optionsText" tal:condition="python:viewType!='xml'">
    74                 &nbsp;&nbsp;<input type="checkbox" class="autosubmit" name="viewType" value="dict" tal:attributes="checked python:viewType=='dict'"/> Dictionary<br/>
    75               </span>
    76               <span class="optionsText" tal:condition="python:viewType!='xml' and docinfo.get('numPlaces',0)">
    77                 &nbsp;&nbsp;<input type="checkbox" class="autosubmit" name="viewType" value="gis" tal:attributes="checked python:viewType=='gis'"/> Places<br/>
    78               </span> <input type="radio" class="autosubmit" name="viewType" tal:attributes="value string:xml; checked python:viewType=='xml'"/> XML<br/>
    79               <input type="submit" value="Go!"/>
    80         </form>
    81       </div>
    82       <!--"END TEXT DISPLAY"-->
    83      
    84       <!--"BEGIN TEXT SIZE"-->
    85       <div class="options">
    86         <h4>Text size</h4>
    87         <div class="fsizer">
    88           &nbsp;
    89           <a href="javascript:fontSize(12);" class="fs_sml">A</a>
    90           <a href="javascript:fontSize(14);" class="fs_med">A</a>
    91           <a href="javascript:fontSize(16);" class="fs_lrg">A</a>
    92         </div>
    93       </div>
    94       <!--"END TEXT SIZE"-->   
    95      
    96       <!--"BEGIN DICTIONARY OVERVIEW"-->
    97       <div class="options" tal:condition="python:viewType=='dict'">
    98         <h4>Dictionary view</h4>
    99         <form name="f3" action="">
    100           <input type="radio" name="r3"/>Tab<br/>
    101           <input type="radio" name="r3"/>Window<br/>
    102         </form>
    103       </div>
    104       <!--"END DICTIONARY OVERVIEW"-->
    105      
    106       <!--"BEGIN TEXT NORMALIZATION"-->
    107       <div class="options" tal:condition="python:viewType!='xml'">
    108         <h4>Text normalization</h4>
    109         <form tal:attributes="action viewerUrl" class="autosubmit"
    110                   tal:define="norm python:pageinfo.get('characterNormalization','regPlusNorm');">
    111               <input type="hidden" tal:define="params python:here.getParams('characterNormalization',None)" tal:repeat="param params" tal:attributes="name param; value python:params[param]"/>
    112           <input type="radio" class="autosubmit" name="characterNormalization" value="orig" tal:attributes="checked python:norm=='orig'"/> Original<br/>
    113           <input type="radio" class="autosubmit" name="characterNormalization" value="reg" tal:attributes="checked python:norm=='reg'"/> Regularized<br/>
    114           <input type="radio" class="autosubmit" name="characterNormalization" value="regPlusNorm" tal:attributes="checked python:norm=='regPlusNorm'"/> Normalized<br/>
    115               <input type="submit" value="Go!"/>
    116         </form>
    117       </div>
    118          <!--"END TEXT NORMALIZATION"-->
    119          
    120           <!--"BEGIN PLACES"-->
    121           <div class="options" tal:condition="python:viewType=='gis'"> 
    122             <tal:block tal:define="gisPlaces python:here.getGisPlaces(docinfo=docinfo, pageinfo=pageinfo); gisAllPlaces python:here.getAllGisPlaces(docinfo=docinfo, pageinfo=pageinfo);">
    123               <span><b>Places</b></span><BR/>(Link to extern:)<BR/>
    124               <span>Page</span>
    125           <span style="float:right">
    126         <a tal:attributes="href python:'http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/db/mpdl/%s?id=%s&format=%s'%(name,gisPlaces,'gis')" target="_blank">
    127           <img src="images/arrow.png" alt=""/>
    128         </a>
    129           </span><BR/>
    130               <span>Book</span>
    131               <span style="float:right">
    132             <a tal:attributes="href python:'http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/db/mpdl/%s?format=%s'%(name,'gis')" target="_blank">
    133           <img src="images/arrow.png" alt=""/>
    134             </a>
    135           </span><BR/>
    136           </tal:block>
    137         </div>
    138           <!--"END PLACES"-->   
    139     </div> <!-- col-right -->
    140    
    141   </div> <!-- page-body -->
    142   <div class="page_body" tal:condition="python:not here.isAccessible(docinfo)">
    143     <div class="errortext">Sorry, access to this document is restricted.</div>
    144   </div>
    145   </tal:block>
    146 </body>
    147 <body tal:condition="not:numPages">
    148   <div class="errortext">Sorry, document doesn't exist.</div>
    149 </body>
    150 </html>
     149      </body>
     150      <body tal:condition="not:numPages">
     151        <div class="errortext">Sorry, document doesn't exist.</div>
     152      </body>
     153    </html>
Note: See TracChangeset for help on using the changeset viewer.