changeset 503:030251fe9dbc elementtree

more cleanup. made viewType into viewLayer and viewType=xml into viewMode=xml.
author casties
date Thu, 16 Feb 2012 14:30:01 +0100
parents daf36d0fcfee
children 454a42f4c369
files documentViewer.py zpt/viewer_images.zpt zpt/viewer_text.zpt zpt/viewer_xml.zpt
diffstat 4 files changed, 202 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/documentViewer.py	Thu Feb 16 13:53:27 2012 +0100
+++ b/documentViewer.py	Thu Feb 16 14:30:01 2012 +0100
@@ -115,6 +115,7 @@
 
     # templates and forms
     viewer_text = PageTemplateFile('zpt/viewer_text', globals())
+    viewer_xml = PageTemplateFile('zpt/viewer_xml', globals())
     viewer_images = PageTemplateFile('zpt/viewer_images', globals())
     viewer_index = PageTemplateFile('zpt/viewer_index', globals())
     toc_thumbs = PageTemplateFile('zpt/toc_thumbs', globals())
@@ -258,17 +259,17 @@
 
   
     security.declareProtected('View','index_html')
-    def index_html(self,url,mode="texttool",viewMode="auto",viewType=None,tocMode="thumbs",start=1,pn=1):
+    def index_html(self,url,mode="texttool",viewMode="auto",viewLayer=None,tocMode="thumbs",start=1,pn=1):
         """
         view page
         @param url: url which contains display information
         @param mode: defines how to access the document behind url 
-        @param viewMode: 'images': display images, 'text': display text, default is 'auto'
-        @param viewType: sub-type of viewMode, e.g. 'dict' for viewMode='text'
+        @param viewMode: 'images': display images, 'text': display text, 'xml': display xml, default is 'auto'
+        @param viewLayer: sub-type of viewMode, e.g. 'dict' for viewMode='text'
         @param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, none)
         """
         
-        logging.debug("documentViewer(index_html) mode=%s url=%s viewMode=%s viewType=%s start=%s pn=%s"%(mode,url,viewMode,viewType,start,pn))
+        logging.debug("documentViewer(index_html) mode=%s url=%s viewMode=%s viewLayer=%s start=%s pn=%s"%(mode,url,viewMode,viewLayer,start,pn))
         
         if not hasattr(self, 'template'):
             # this won't work
@@ -288,21 +289,21 @@
         if viewMode=="auto": 
             if docinfo.get('textURL', None) or docinfo.get('textURLPath', None): 
                 viewMode = "text"
-                viewType = "dict"
+                viewLayer = "dict"
             else:
                 viewMode = "images"
                 
         elif viewMode == "text_dict":
             # legacy fix
             viewMode = "text"
-            viewType = "dict"
+            viewLayer = "dict"
             
-        # stringify viewType
-        if isinstance(viewType, list):
-            logging.debug("index_html: viewType is list:%s"%viewType)
-            viewType = ','.join([t for t in viewType if t])
+        # stringify viewLayer
+        if isinstance(viewLayer, list):
+            logging.debug("index_html: viewLayer is list:%s"%viewLayer)
+            viewLayer = ','.join([t for t in viewLayer if t])
                         
-        pageinfo = self.getPageinfo(start=start, current=pn, docinfo=docinfo, viewMode=viewMode, viewType=viewType, tocMode=tocMode)
+        pageinfo = self.getPageinfo(start=start, current=pn, docinfo=docinfo, viewMode=viewMode, viewLayer=viewLayer, tocMode=tocMode)
                     
         # get template /template/viewer_$viewMode
         pt = getattr(self.template, 'viewer_%s'%viewMode, None)
@@ -703,12 +704,12 @@
         return docinfo
     
 
-    def getPageinfo(self, current=None, start=None, rows=None, cols=None, docinfo=None, viewMode=None, viewType=None, tocMode=None):
+    def getPageinfo(self, current=None, start=None, rows=None, cols=None, docinfo=None, viewMode=None, viewLayer=None, tocMode=None):
         """returns pageinfo with the given parameters"""
-        logging.debug("getPageInfo(current=%s, start=%s, rows=%s, cols=%s, viewMode=%s, viewType=%s, tocMode=%s)"%(current,start,rows,cols,viewMode,viewType,tocMode))
+        logging.debug("getPageInfo(current=%s, start=%s, rows=%s, cols=%s, viewMode=%s, viewLayer=%s, tocMode=%s)"%(current,start,rows,cols,viewMode,viewLayer,tocMode))
         pageinfo = {}
         pageinfo['viewMode'] = viewMode
-        pageinfo['viewType'] = viewType
+        pageinfo['viewLayer'] = viewLayer
         pageinfo['tocMode'] = tocMode
 
         current = getInt(current)
@@ -730,7 +731,7 @@
             # numPages unknown - maybe we can get it from text page
             if docinfo.get('textURLPath', None):
                 # cache text page as well
-                pageinfo['textPage'] = self.getTextPage(mode=viewType, pn=current, docinfo=docinfo, pageinfo=pageinfo)
+                pageinfo['textPage'] = self.getTextPage(mode=viewLayer, pn=current, docinfo=docinfo, pageinfo=pageinfo)
                 np = int(docinfo.get('numPages', 0))
                 
         pageinfo['numgroups'] = int(np / grpsize)
--- a/zpt/viewer_images.zpt	Thu Feb 16 13:53:27 2012 +0100
+++ b/zpt/viewer_images.zpt	Thu Feb 16 14:30:01 2012 +0100
@@ -2,7 +2,7 @@
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml"
   tal:define="docinfo options/docinfo; pageinfo options/pageinfo; viewMode pageinfo/viewMode;
-              tocMode pageinfo/tocMode; viewType pageinfo/viewType; viewerUrl docinfo/viewerUrl;
+              tocMode pageinfo/tocMode; viewerUrl docinfo/viewerUrl;
               numPages docinfo/numPages | nothing; dlBaseUrl docinfo/digilibBaseUrl | nothing;">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
--- a/zpt/viewer_text.zpt	Thu Feb 16 13:53:27 2012 +0100
+++ b/zpt/viewer_text.zpt	Thu Feb 16 14:30:01 2012 +0100
@@ -2,7 +2,7 @@
           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml"
   tal:define="docinfo options/docinfo; pageinfo options/pageinfo; viewMode pageinfo/viewMode;
-              tocMode pageinfo/tocMode; viewType pageinfo/viewType; viewerUrl docinfo/viewerUrl;
+              tocMode pageinfo/tocMode; viewLayer pageinfo/viewLayer; viewerUrl docinfo/viewerUrl;
               rootUrl here/getDocumentViewerURL;
               numPages docinfo/numPages | nothing;">
 <head>
@@ -28,7 +28,7 @@
     tal:define="docpath docinfo/textURLPath;
                                pn pageinfo/pn; 
                                flowLtr python:pageinfo.get('pageFlow','ltr')!='rtl';
-                               textPage python:here.getTextPage(mode=viewType, pn=pn, docinfo=docinfo, pageinfo=pageinfo) or '[no text here]';">
+                               textPage python:here.getTextPage(mode=viewLayer, pn=pn, docinfo=docinfo, pageinfo=pageinfo) or '[no text here]';">
     <!-- header -->
     <div class="page-head">
       <metal:block metal:use-macro="here/template/common_template/macros/head" />
@@ -66,20 +66,21 @@
           <h4>Text display</h4>
           <form tal:attributes="action viewerUrl" class="autosubmit">
             <input type="hidden"
-              tal:define="params python:here.getParams(params={'viewType':None})"
+              tal:define="params python:here.getParams(params={'viewLayer':None,'viewMode':None})"
               tal:repeat="param params"
-              tal:attributes="name param; value python:params[param]" /> <input
-              class="autosubmit" type="radio" name="viewType" value=""
-              tal:attributes="checked python:viewType!='xml'" /> Text<br /> <span
-              class="optionsText" tal:condition="python:viewType!='xml'">
-              &nbsp;&nbsp;<input type="checkbox" class="autosubmit" name="viewType"
-              value="dict" tal:attributes="checked python:viewType=='dict'" /> Dictionary<br />
-            </span> <span class="optionsText"
-              tal:condition="python:viewType!='xml' and docinfo.get('numPlaces',0)">
-              &nbsp;&nbsp;<input type="checkbox" class="autosubmit" name="viewType"
-              value="gis" tal:attributes="checked python:viewType=='gis'" /> Places<br />
-            </span> <input type="radio" class="autosubmit" name="viewType"
-              tal:attributes="value string:xml; checked python:viewType=='xml'" /> XML<br />
+              tal:attributes="name param; value python:params[param]" /> 
+            <input class="autosubmit" type="radio" name="viewMode" value="text"
+              tal:attributes="checked python:viewMode=='text'" /> Text<br /> 
+            <span class="optionsText">
+              &nbsp;&nbsp;<input type="checkbox" class="autosubmit" name="viewLayer"
+              value="dict" tal:attributes="checked python:viewLayer=='dict'" /> Dictionary<br />
+            </span> 
+            <span class="optionsText" tal:condition="python:docinfo.get('numPlaces',0)">
+              &nbsp;&nbsp;<input type="checkbox" class="autosubmit" name="viewLayer"
+              value="gis" tal:attributes="checked python:viewLayer=='gis'" /> Places<br />
+            </span> 
+            <input type="radio" class="autosubmit" name="viewMode" value="xml"
+              tal:attributes="checked python:viewMode=='xml'" /> XML<br />
             <input type="submit" value="Go!" />
           </form>
         </div>
@@ -97,7 +98,7 @@
         <!--"END TEXT SIZE"-->
 
         <!--"BEGIN DICTIONARY OVERVIEW"-->
-        <div class="options" tal:condition="python:viewType=='dict'">
+        <div class="options" tal:condition="python:viewLayer=='dict'">
           <h4>Dictionary view</h4>
           <form name="f3" action="">
             <input type="radio" name="r3" />Tab<br /> <input type="radio" name="r3" />Window<br />
@@ -106,7 +107,7 @@
         <!--"END DICTIONARY OVERVIEW"-->
 
         <!--"BEGIN TEXT NORMALIZATION"-->
-        <div class="options" tal:condition="python:viewType!='xml'">
+        <div class="options" tal:condition="python:viewLayer!='xml'">
           <h4>Text normalization</h4>
           <form tal:attributes="action viewerUrl" class="autosubmit"
             tal:define="norm python:pageinfo.get('characterNormalization','regPlusNorm');">
@@ -126,7 +127,7 @@
         <!--"END TEXT NORMALIZATION"-->
 
         <!--"BEGIN PLACES"-->
-        <div class="options" tal:condition="python:viewType=='gis'">
+        <div class="options" tal:condition="python:viewLayer=='gis'">
           <tal:block
             tal:define="gisPlaces python:here.getGisPlaces(docinfo=docinfo, pageinfo=pageinfo); gisAllPlaces python:here.getAllGisPlaces(docinfo=docinfo, pageinfo=pageinfo);">
             <span><b>Places</b></span>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/zpt/viewer_xml.zpt	Thu Feb 16 14:30:01 2012 +0100
@@ -0,0 +1,166 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+  tal:define="docinfo options/docinfo; pageinfo options/pageinfo; viewMode pageinfo/viewMode;
+              tocMode pageinfo/tocMode; viewType pageinfo/viewType; viewerUrl docinfo/viewerUrl;
+              rootUrl here/getDocumentViewerURL;
+              numPages docinfo/numPages | nothing;">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+  <title
+    tal:content="python:docinfo.get('creator',' ') + ' - ' + docinfo.get('title',' ')" />
+  <link rel="stylesheet" href="template/docuviewer_css" type="text/css" />
+  <script type="text/javascript" tal:attributes="src string:$rootUrl/template/jquery_js"></script>
+  <script type="text/javascript">
+            // <!--
+            $(document).ready(function() {
+                // autosubmit forms
+                $('form.autosubmit').find('.autosubmit').change(function() {
+                    this.form.submit();
+                });
+                $('form.autosubmit input[type="submit"]').hide();
+            });
+        // -->
+        </script>
+</head>
+<body tal:condition="numPages">
+  <tal:block
+    tal:define="docpath docinfo/textURLPath;
+                               pn pageinfo/pn; 
+                               flowLtr python:pageinfo.get('pageFlow','ltr')!='rtl';
+                               textPage python:here.getTextPage(mode=viewType, pn=pn, docinfo=docinfo, pageinfo=pageinfo) or '[no text here]';">
+    <!-- header -->
+    <div class="page-head">
+      <metal:block metal:use-macro="here/template/common_template/macros/head" />
+    </div>
+    <div class="page-body" tal:condition="python:here.isAccessible(docinfo)">
+      <!--table of contents-->
+      <div class="col-left">
+        <metal:block
+          metal:use-macro="python:path('here/template/toc_%s/macros/main'%tocMode)" />
+      </div>
+
+      <!-- text page -->
+      <div class="col-main">
+        <div class="ruler">
+          <metal:block metal:use-macro="here/template/common_template/macros/page_ruler" />
+        </div>
+        <ul class="switcher">
+          <li>
+            <a tal:attributes="href python:here.getLink('viewMode','images')">Image</a>
+          </li>
+          <li class="sel">Text</li>
+        </ul>
+        <div class="content">
+          <div class="pageHeaderTitle" tal:condition="exists:pageinfo/pageHeaderTitle"
+            tal:content="structure pageinfo/pageHeaderTitle" />
+          <tal:block tal:replace="structure textPage" />
+        </div>
+      </div>
+      <!-- col-main -->
+
+      <!-- right-side options -->
+      <div class="col-right">
+        <!--"BEGIN TEXT DISPLAY"  -->
+        <div class="options">
+          <h4>Text display</h4>
+          <form tal:attributes="action viewerUrl" class="autosubmit">
+            <input type="hidden"
+              tal:define="params python:here.getParams(params={'viewType':None})"
+              tal:repeat="param params"
+              tal:attributes="name param; value python:params[param]" /> <input
+              class="autosubmit" type="radio" name="viewType" value=""
+              tal:attributes="checked python:viewType!='xml'" /> Text<br /> <span
+              class="optionsText" tal:condition="python:viewType!='xml'">
+              &nbsp;&nbsp;<input type="checkbox" class="autosubmit" name="viewType"
+              value="dict" tal:attributes="checked python:viewType=='dict'" /> Dictionary<br />
+            </span> <span class="optionsText"
+              tal:condition="python:viewType!='xml' and docinfo.get('numPlaces',0)">
+              &nbsp;&nbsp;<input type="checkbox" class="autosubmit" name="viewType"
+              value="gis" tal:attributes="checked python:viewType=='gis'" /> Places<br />
+            </span> <input type="radio" class="autosubmit" name="viewType"
+              tal:attributes="value string:xml; checked python:viewType=='xml'" /> XML<br />
+            <input type="submit" value="Go!" />
+          </form>
+        </div>
+        <!--"END TEXT DISPLAY"-->
+
+        <!--"BEGIN TEXT SIZE"-->
+        <div class="options">
+          <h4>Text size</h4>
+          <div class="fsizer">
+            &nbsp; <a href="javascript:fontSize(12);" class="fs_sml">S</a> <a
+              href="javascript:fontSize(14);" class="fs_med">M</a> <a
+              href="javascript:fontSize(16);" class="fs_lrg">L</a>
+          </div>
+        </div>
+        <!--"END TEXT SIZE"-->
+
+        <!--"BEGIN DICTIONARY OVERVIEW"-->
+        <div class="options" tal:condition="python:viewType=='dict'">
+          <h4>Dictionary view</h4>
+          <form name="f3" action="">
+            <input type="radio" name="r3" />Tab<br /> <input type="radio" name="r3" />Window<br />
+          </form>
+        </div>
+        <!--"END DICTIONARY OVERVIEW"-->
+
+        <!--"BEGIN TEXT NORMALIZATION"-->
+        <div class="options" tal:condition="python:viewType!='xml'">
+          <h4>Text normalization</h4>
+          <form tal:attributes="action viewerUrl" class="autosubmit"
+            tal:define="norm python:pageinfo.get('characterNormalization','regPlusNorm');">
+            <input type="hidden"
+              tal:define="params python:here.getParams('characterNormalization',None)"
+              tal:repeat="param params"
+              tal:attributes="name param; value python:params[param]" /> <input
+              type="radio" class="autosubmit" name="characterNormalization" value="orig"
+              tal:attributes="checked python:norm=='orig'" /> Original<br /> <input
+              type="radio" class="autosubmit" name="characterNormalization" value="reg"
+              tal:attributes="checked python:norm=='reg'" /> Regularized<br /> <input
+              type="radio" class="autosubmit" name="characterNormalization"
+              value="regPlusNorm" tal:attributes="checked python:norm=='regPlusNorm'" />
+            Normalized<br /> <input type="submit" value="Go!" />
+          </form>
+        </div>
+        <!--"END TEXT NORMALIZATION"-->
+
+        <!--"BEGIN PLACES"-->
+        <div class="options" tal:condition="python:viewType=='gis'">
+          <tal:block
+            tal:define="gisPlaces python:here.getGisPlaces(docinfo=docinfo, pageinfo=pageinfo); gisAllPlaces python:here.getAllGisPlaces(docinfo=docinfo, pageinfo=pageinfo);">
+            <span><b>Places</b></span>
+            <br />(Link to extern:)<br />
+            <span>Page</span>
+            <span style="float: right"> <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"> <img src="images/arrow.png" alt="" />
+            </a>
+            </span>
+            <br />
+            <span>Book</span>
+            <span style="float: right"> <a
+              tal:attributes="href python:'http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/db/mpdl/%s?format=%s'%(name,'gis')"
+              target="_blank"> <img src="images/arrow.png" alt="" />
+            </a>
+            </span>
+            <br />
+          </tal:block>
+        </div>
+        <!--"END PLACES"-->
+      </div>
+      <!-- /col-right -->
+
+    </div>
+    <!-- /page-body -->
+
+    <div class="page-body" tal:condition="python:not here.isAccessible(docinfo)">
+      <div class="errortext">Sorry, access to this document is restricted.</div>
+    </div>
+
+  </tal:block>
+</body>
+<body tal:condition="not:numPages">
+  <div class="errortext">Sorry, document doesn't exist.</div>
+</body>
+</html>