Mercurial > hg > documentViewer
changeset 490:6f116b86a226 elementtree
more new template stuff. moved ImageFile index method to SrvTxtUtils
author | casties |
---|---|
date | Mon, 29 Aug 2011 16:39:50 +0200 |
parents | 55e3398e395e |
children | fe319aa0ba30 |
files | SrvTxtUtils.py documentViewer.py zpt/viewer_images.zpt zpt/viewer_text.zpt |
diffstat | 4 files changed, 185 insertions(+), 171 deletions(-) [+] |
line wrap: on
line diff
--- a/SrvTxtUtils.py Thu Aug 25 17:05:22 2011 +0200 +++ b/SrvTxtUtils.py Mon Aug 29 16:39:50 2011 +0200 @@ -1,12 +1,17 @@ """Utility methods for handling XML, reading HTTP, etc""" +from App.ImageFile import ImageFile +from App.Common import rfc1123_date + import sys +import os +import stat import urllib import urllib2 import logging -srvTxtUtilsVersion = "1.0" +srvTxtUtilsVersion = "1.3" def getInt(number, default=0): """returns always an int (0 in case of problems)""" @@ -15,14 +20,25 @@ except: return int(default) -def getText(node): +def getAt(array, idx, default=None): + """returns element idx from array or default (in case of problems)""" + try: + return array[idx] + except: + return default + +def getText(node, recursive=0): """returns all text content of a node and its subnodes""" if node is None: - return "" + return '' + # ElementTree: - text = node.text or "" + text = node.text or '' for e in node: - text += getText(e) + if recursive: + text += getText(e) + else: + text += e.text or '' if e.tail: text += e.tail @@ -81,3 +97,13 @@ raise IOError("ERROR fetching HTTP data from %s: %s"%(url,errmsg)) #return None + +def refreshingImageFileIndexHtml(self, REQUEST, RESPONSE): + """index_html method for App.ImageFile that updates the file info for each request.""" + stat_info = os.stat(self.path) + self.size = stat_info[stat.ST_SIZE] + self.lmt = float(stat_info[stat.ST_MTIME]) or time.time() + self.lmh = rfc1123_date(self.lmt) + # call original method + return ImageFile.index_html(self, REQUEST, RESPONSE) +
--- a/documentViewer.py Thu Aug 25 17:05:22 2011 +0200 +++ b/documentViewer.py Mon Aug 29 16:39:50 2011 +0200 @@ -2,8 +2,6 @@ from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate from Products.PageTemplates.PageTemplateFile import PageTemplateFile from App.ImageFile import ImageFile -from App.Common import rfc1123_date -#from Products.ZSimpleFile.ZSimpleFile import ZSimpleFile from AccessControl import ClassSecurityInfo from AccessControl import getSecurityManager from Globals import package_home @@ -11,7 +9,6 @@ import xml.etree.ElementTree as ET import os -import stat import sys import urllib import logging @@ -20,12 +17,7 @@ import re import string -from SrvTxtUtils import getInt, getText, getHttpData - -def logger(txt,method,txt2): - """logging""" - logging.info(txt+ txt2) - +from SrvTxtUtils import getInt, getText, getHttpData, refreshingImageFileIndexHtml def serializeNode(node, encoding="utf-8"): """returns a string containing node as XML""" @@ -106,15 +98,6 @@ # split by /, shorten, and reassemble return '/'.join(path.split('/')[0:-cnt]) -def devImageFileIndexHtml(self, REQUEST, RESPONSE): - """index_html method for App.ImageFile that updates the file info for each request.""" - stat_info = os.stat(self.path) - self.size = stat_info[stat.ST_SIZE] - self.lmt = float(stat_info[stat.ST_MTIME]) or time.time() - self.lmh = rfc1123_date(self.lmt) - # call original method - return ImageFile.index_html(self, REQUEST, RESPONSE) - ## ## documentViewer class ## @@ -148,7 +131,7 @@ info_xml = PageTemplateFile('zpt/info_xml', globals()) docuviewer_css = ImageFile('css/docuviewer.css',globals()) # make ImageFile better for development - docuviewer_css.index_html = devImageFileIndexHtml + docuviewer_css.index_html = refreshingImageFileIndexHtml thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals())
--- a/zpt/viewer_images.zpt Thu Aug 25 17:05:22 2011 +0200 +++ b/zpt/viewer_images.zpt Mon Aug 29 16:39:50 2011 +0200 @@ -50,7 +50,9 @@ first python:test(pn>1,1,None); last python:test(pn<numPages,numPages,None); left python:test(flowLtr,prev,next); right python:test(flowLtr,next,prev); leftest python:test(flowLtr,first,last); rightest python:test(flowLtr,last,first);"> - <div class="page-head" metal:use-macro="here/template/head_main/macros/main" /> + <div class="page-head"> + <metal:block metal:use-macro="here/template/head_main/macros/main" /> + </div> <div class="page-body" tal:condition="python:here.isAccessible(docinfo)"> <!--table of contents--> <div class="col-left">
--- a/zpt/viewer_text.zpt Thu Aug 25 17:05:22 2011 +0200 +++ b/zpt/viewer_text.zpt Mon Aug 29 16:39:50 2011 +0200 @@ -1,150 +1,153 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + "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; - 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"> -</head> -<body tal:condition="numPages"> - <tal:block tal:define="docpath docinfo/textURLPath; - pn pageinfo/pn; - flowLtr python:pageinfo.get('pageFlow','ltr')!='rtl'; - prev python:test(pn>1,pn-1,None); next python:test(pn<numPages,pn+1,None); - first python:test(pn>1,1,None); last python:test(pn<numPages,numPages,None); - left python:test(flowLtr,prev,next); right python:test(flowLtr,next,prev); - leftest python:test(flowLtr,first,last); rightest python:test(flowLtr,last,first); - textPage python:here.getTextPage(mode=viewType, pn=pn, docinfo=docinfo, pageinfo=pageinfo);"> - <div class="page-head" metal:use-macro="here/template/head_main/macros/main" /> - <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> + tal:define="docinfo options/docinfo; pageinfo options/pageinfo; viewMode pageinfo/viewMode; + tocMode pageinfo/tocMode; viewType pageinfo/viewType; viewerUrl docinfo/viewerUrl; + 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"> + </head> + <body tal:condition="numPages"> + <tal:block tal:define="docpath docinfo/textURLPath; + pn pageinfo/pn; + flowLtr python:pageinfo.get('pageFlow','ltr')!='rtl'; + prev python:test(pn>1,pn-1,None); next python:test(pn<numPages,pn+1,None); + first python:test(pn>1,1,None); last python:test(pn<numPages,numPages,None); + left python:test(flowLtr,prev,next); right python:test(flowLtr,next,prev); + leftest python:test(flowLtr,first,last); rightest python:test(flowLtr,last,first); + textPage python:here.getTextPage(mode=viewType, pn=pn, docinfo=docinfo, pageinfo=pageinfo);"> + <div class="page-head"> + <metal:block metal:use-macro="here/template/head_main/macros/main" /> + </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"> - <form class="autosubmit" tal:attributes="action viewerUrl"> - <input type="hidden" tal:define="params python:here.getParams('pn', None)" - tal:repeat="param params" tal:attributes="name param; value python:params[param]" /> - page - <a tal:condition="leftest" tal:attributes="href python:here.getLink('pn',leftest)">|<</a> - <span tal:condition="not:leftest">|<</span> - <a tal:condition="left" tal:attributes="href python:here.getLink('pn',left)"><</a> - <span tal:condition="not:left"><</span> - <input class="autosubmit" size="3" type="text" name="pn" tal:attributes="value pn" /> - <tal:block tal:define="originalPage pageinfo/pageNumberOrig | nothing" - tal:condition="python:originalPage!=None"> - (<span tal:replace="originalPage"/><span tal:define="originalPageNorm pageinfo/pageNumberOrigNorm | nothing" tal:condition="python:originalPageNorm!=None">[<span tal:replace="originalPageNorm"/>]</span>) + <!-- text page --> + <div class="col-main"> + <div class="ruler"> + <form class="autosubmit" tal:attributes="action viewerUrl"> + <input type="hidden" tal:define="params python:here.getParams('pn', None)" + tal:repeat="param params" tal:attributes="name param; value python:params[param]" /> + page + <a tal:condition="leftest" tal:attributes="href python:here.getLink('pn',leftest)">|<</a> + <span tal:condition="not:leftest">|<</span> + <a tal:condition="left" tal:attributes="href python:here.getLink('pn',left)"><</a> + <span tal:condition="not:left"><</span> + <input class="autosubmit" size="3" type="text" name="pn" tal:attributes="value pn" /> + <tal:block tal:define="originalPage pageinfo/pageNumberOrig | nothing" + tal:condition="python:originalPage!=None"> + (<span tal:replace="originalPage"/><span tal:define="originalPageNorm pageinfo/pageNumberOrigNorm | nothing" tal:condition="python:originalPageNorm!=None"> + [<span tal:replace="originalPageNorm"/>]</span>) + </tal:block> + <input type="submit" value="Go" /> + of + <span tal:replace="numPages"/> + <a tal:condition="right" tal:attributes="href python:here.getLink('pn',right)">></a> + <span tal:condition="not:right">></span> + <a tal:condition="rightest" tal:attributes="href python:here.getLink('pn',rightest)">>|</a> + <span tal:condition="not:rightest">>|</span> + </form> + </div> <!-- ruler --> + <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'"> + <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)"> + <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"> + + <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> - <input type="submit" value="Go" /> - of - <span tal:replace="numPages"/> - <a tal:condition="right" tal:attributes="href python:here.getLink('pn',right)">></a> - <span tal:condition="not:right">></span> - <a tal:condition="rightest" tal:attributes="href python:here.getLink('pn',rightest)">>|</a> - <span tal:condition="not:rightest">>|</span> - </form> - </div> <!-- ruler --> - <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"> - <h3>Text display</h3> - <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'"> - <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)"> - <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"> - - <a href="javascript:fontSize(12);" class="fs_sml">A</a> - <a href="javascript:fontSize(14);" class="fs_med">A</a> - <a href="javascript:fontSize(16);" class="fs_lrg">A</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> + </body> + <body tal:condition="not:numPages"> + <div class="errortext">Sorry, document doesn't exist.</div> + </body> + </html>