version 1.175.2.25, 2011/08/15 09:58:56
|
version 1.175.2.32, 2011/08/25 15:05:22
|
Line 1
|
Line 1
|
from OFS.Folder import Folder |
from OFS.Folder import Folder |
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate |
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate |
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
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 ClassSecurityInfo |
from AccessControl import getSecurityManager |
from AccessControl import getSecurityManager |
from Globals import package_home |
from Globals import package_home |
|
|
#from Ft.Xml import EMPTY_NAMESPACE, Parse |
|
#import Ft.Xml.Domlette |
|
|
|
import xml.etree.ElementTree as ET |
import xml.etree.ElementTree as ET |
|
|
import os.path |
import os |
|
import stat |
import sys |
import sys |
import urllib |
import urllib |
import logging |
import logging |
Line 105 def getParentPath(path, cnt=1):
|
Line 106 def getParentPath(path, cnt=1):
|
# split by /, shorten, and reassemble |
# split by /, shorten, and reassemble |
return '/'.join(path.split('/')[0:-cnt]) |
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 |
## documentViewer class |
Line 123 class documentViewer(Folder):
|
Line 132 class documentViewer(Folder):
|
|
|
# templates and forms |
# templates and forms |
viewer_text = PageTemplateFile('zpt/viewer_text', globals()) |
viewer_text = PageTemplateFile('zpt/viewer_text', globals()) |
|
viewer_images = PageTemplateFile('zpt/viewer_images', globals()) |
viewer_main = PageTemplateFile('zpt/viewer_main', globals()) |
viewer_main = PageTemplateFile('zpt/viewer_main', globals()) |
toc_thumbs = PageTemplateFile('zpt/toc_thumbs', globals()) |
toc_thumbs = PageTemplateFile('zpt/toc_thumbs', globals()) |
toc_text = PageTemplateFile('zpt/toc_text', globals()) |
toc_text = PageTemplateFile('zpt/toc_text', globals()) |
Line 135 class documentViewer(Folder):
|
Line 145 class documentViewer(Folder):
|
page_main_xml = PageTemplateFile('zpt/page_main_xml', globals()) |
page_main_xml = PageTemplateFile('zpt/page_main_xml', globals()) |
page_main_pureXml = PageTemplateFile('zpt/page_main_pureXml', globals()) |
page_main_pureXml = PageTemplateFile('zpt/page_main_pureXml', globals()) |
head_main = PageTemplateFile('zpt/head_main', globals()) |
head_main = PageTemplateFile('zpt/head_main', globals()) |
docuviewer_css = PageTemplateFile('css/docuviewer.css', globals()) |
|
info_xml = PageTemplateFile('zpt/info_xml', globals()) |
info_xml = PageTemplateFile('zpt/info_xml', globals()) |
|
docuviewer_css = ImageFile('css/docuviewer.css',globals()) |
|
# make ImageFile better for development |
|
docuviewer_css.index_html = devImageFileIndexHtml |
|
|
|
|
thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals()) |
thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals()) |
Line 348 class documentViewer(Folder):
|
Line 360 class documentViewer(Folder):
|
url = self.template.zogilib.getDLBaseUrl() |
url = self.template.zogilib.getDLBaseUrl() |
return url |
return url |
|
|
|
def getScalerUrl(self, fn=None, pn=None, dw=100, dh=100, docinfo=None): |
|
"""returns URL to digilib Scaler with params""" |
|
url = None |
|
if docinfo is not None: |
|
url = docinfo.get('imageURL', None) |
|
|
|
if url is None: |
|
url = "%s/servlet/Scaler?"%self.digilibBaseUrl |
|
if fn is None and docinfo is not None: |
|
fn = docinfo.get('imagePath','') |
|
|
|
url += "fn=%s"%fn |
|
|
|
if pn: |
|
url += "&pn=%s"%pn |
|
|
|
url += "&dw=%s&dh=%s"%(dw,dh) |
|
return url |
|
|
def getDocumentViewerURL(self): |
def getDocumentViewerURL(self): |
"""returns the URL of this instance""" |
"""returns the URL of this instance""" |
return self.absolute_url() |
return self.absolute_url() |
|
|
def getStyle(self, idx, selected, style=""): |
def getStyle(self, idx, selected, style=""): |
"""returns a string with the given style and append 'sel' if path == selected.""" |
"""returns a string with the given style and append 'sel' if idx == selected.""" |
#logger("documentViewer (getstyle)", logging.INFO, "idx: %s selected: %s style: %s"%(idx,selected,style)) |
#logger("documentViewer (getstyle)", logging.INFO, "idx: %s selected: %s style: %s"%(idx,selected,style)) |
if idx == selected: |
if idx == selected: |
return style + 'sel' |
return style + 'sel' |
Line 534 class documentViewer(Folder):
|
Line 565 class documentViewer(Folder):
|
# override image path from texttool with url |
# override image path from texttool with url |
docinfo['imagePath'] = url.replace('/mpiwg/online/', '', 1) |
docinfo['imagePath'] = url.replace('/mpiwg/online/', '', 1) |
|
|
|
|
|
|
# number of images from digilib |
# number of images from digilib |
if docinfo.get('imagePath', None): |
if docinfo.get('imagePath', None): |
docinfo['imageURL'] = self.digilibBaseUrl + "/servlet/Scaler?fn=" + docinfo['imagePath'] |
docinfo['imageURL'] = self.digilibBaseUrl + "/servlet/Scaler?fn=" + docinfo['imagePath'] |
Line 708 class documentViewer(Folder):
|
Line 737 class documentViewer(Folder):
|
|
|
current = getInt(current) |
current = getInt(current) |
pageinfo['current'] = current |
pageinfo['current'] = current |
|
pageinfo['pn'] = current |
rows = int(rows or self.thumbrows) |
rows = int(rows or self.thumbrows) |
pageinfo['rows'] = rows |
pageinfo['rows'] = rows |
cols = int(cols or self.thumbcols) |
cols = int(cols or self.thumbcols) |
Line 718 class documentViewer(Folder):
|
Line 748 class documentViewer(Folder):
|
start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1))) |
start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1))) |
# int(current / grpsize) * grpsize +1)) |
# int(current / grpsize) * grpsize +1)) |
pageinfo['start'] = start |
pageinfo['start'] = start |
pn = self.REQUEST.get('pn','1') |
|
pageinfo['pn'] = pn |
|
np = int(docinfo.get('numPages', 0)) |
np = int(docinfo.get('numPages', 0)) |
if np == 0: |
if np == 0: |
# numPages unknown - maybe we can get it from text page |
# numPages unknown - maybe we can get it from text page |
if docinfo.get('textURLPath', None): |
if docinfo.get('textURLPath', None): |
# cache text page as well |
# cache text page as well |
pageinfo['textPage'] = self.getTextPage(mode=viewType, pn=pn, docinfo=docinfo, pageinfo=pageinfo) |
pageinfo['textPage'] = self.getTextPage(mode=viewType, pn=current, docinfo=docinfo, pageinfo=pageinfo) |
np = int(docinfo.get('numPages', 0)) |
np = int(docinfo.get('numPages', 0)) |
|
|
pageinfo['numgroups'] = int(np / grpsize) |
pageinfo['numgroups'] = int(np / grpsize) |
Line 737 class documentViewer(Folder):
|
Line 766 class documentViewer(Folder):
|
# add zeroth page for two columns |
# add zeroth page for two columns |
pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft)) |
pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft)) |
pageinfo['pageZero'] = pageZero |
pageinfo['pageZero'] = pageZero |
pageinfo['pageList'] = self.getPageList(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np) |
pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np) |
|
|
|
# TODO: do we need this here? |
pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') |
pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') |
pageinfo['query'] = self.REQUEST.get('query','') |
pageinfo['query'] = self.REQUEST.get('query','') |
pageinfo['queryType'] = self.REQUEST.get('queryType','') |
pageinfo['queryType'] = self.REQUEST.get('queryType','') |
Line 764 class documentViewer(Folder):
|
Line 794 class documentViewer(Folder):
|
return pageinfo |
return pageinfo |
|
|
|
|
def getPageList(self, start=None, rows=None, cols=None, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0): |
def getPageBatch(self, start=1, rows=10, cols=2, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0): |
"""returns array of page informations for one screenfull of thumbnails""" |
"""returns dict with array of page informations for one screenfull of thumbnails""" |
|
batch = {} |
|
grpsize = rows * cols |
if maxIdx == 0: |
if maxIdx == 0: |
maxIdx = start + rows * cols |
maxIdx = start + grpsize |
|
|
|
nb = int(math.ceil(maxIdx / float(grpsize))) |
|
# list of all batch start and end points |
|
batches = [] |
|
if pageZero: |
|
ofs = 0 |
|
else: |
|
ofs = 1 |
|
|
|
for i in range(nb): |
|
s = i * grpsize + ofs |
|
e = min((i + 1) * grpsize + ofs - 1, maxIdx) |
|
batches.append({'start':s, 'end':e}) |
|
|
|
batch['batches'] = batches |
|
|
pages = [] |
pages = [] |
if pageZero and start == 1: |
if pageZero and start == 1: |
Line 792 class documentViewer(Folder):
|
Line 839 class documentViewer(Folder):
|
|
|
pages.append(row) |
pages.append(row) |
|
|
logging.debug("getPageList returns=%s"%(pages)) |
if start > 1: |
return pages |
batch['prevStart'] = max(start - grpsize, 1) |
|
else: |
|
batch['prevStart'] = None |
|
|
|
if start + grpsize < maxIdx: |
|
batch['nextStart'] = start + grpsize |
|
else: |
|
batch['nextStart'] = None |
|
|
|
batch['pages'] = pages |
|
return batch |
|
|
|
def getBatch(self, start=1, size=10, end=0, data=None, fullData=True): |
|
"""returns dict with information for one screenfull of data.""" |
|
batch = {} |
|
if end == 0: |
|
end = start + size |
|
|
|
nb = int(math.ceil(end / float(size))) |
|
# list of all batch start and end points |
|
batches = [] |
|
for i in range(nb): |
|
s = i * size + 1 |
|
e = min((i + 1) * size, end) |
|
batches.append({'start':s, 'end':e}) |
|
|
|
batch['batches'] = batches |
|
# list of elements in this batch |
|
this = [] |
|
j = 0 |
|
for i in range(start, min(start+size, end)): |
|
if data: |
|
if fullData: |
|
d = data[i] |
|
else: |
|
d = data[j] |
|
j += 1 |
|
|
|
else: |
|
d = i+1 |
|
|
|
this.append(d) |
|
|
|
batch['this'] = this |
|
if start > 1: |
|
batch['prevStart'] = max(start - size, 1) |
|
else: |
|
batch['prevStart'] = None |
|
|
|
if start + size < end: |
|
batch['nextStart'] = start + size |
|
else: |
|
batch['nextStart'] = None |
|
|
|
return batch |
|
|
|
|
security.declareProtected('View management screens','changeDocumentViewerForm') |
security.declareProtected('View management screens','changeDocumentViewerForm') |
Line 827 def manage_AddDocumentViewer(self,id,ima
|
Line 928 def manage_AddDocumentViewer(self,id,ima
|
|
|
if RESPONSE is not None: |
if RESPONSE is not None: |
RESPONSE.redirect('manage_main') |
RESPONSE.redirect('manage_main') |
|
|
## DocumentViewerTemplate class |
|
class DocumentViewerTemplate(ZopePageTemplate): |
|
"""Template for document viewer""" |
|
meta_type="DocumentViewer Template" |
|
|
|
|
|
def manage_addDocumentViewerTemplateForm(self): |
|
"""Form for adding""" |
|
pt=PageTemplateFile('zpt/addDocumentViewerTemplate', globals()).__of__(self) |
|
return pt() |
|
|
|
def manage_addDocumentViewerTemplate(self, id='viewer_main', title=None, text=None, |
|
REQUEST=None, submit=None): |
|
"Add a Page Template with optional file content." |
|
|
|
self._setObject(id, DocumentViewerTemplate(id)) |
|
ob = getattr(self, id) |
|
txt=file(os.path.join(package_home(globals()),'zpt/viewer_main.zpt'),'r').read() |
|
logging.info("txt %s:"%txt) |
|
ob.pt_edit(txt,"text/html") |
|
if title: |
|
ob.pt_setTitle(title) |
|
try: |
|
u = self.DestinationURL() |
|
except AttributeError: |
|
u = REQUEST['URL1'] |
|
|
|
u = "%s/%s" % (u, urllib.quote(id)) |
|
REQUEST.RESPONSE.redirect(u+'/manage_main') |
|
return '' |
|
|
|
|
|
|
|