version 1.5, 2004/04/01 10:39:15
|
version 1.26, 2004/06/07 17:56:55
|
Line 1
|
Line 1
|
|
|
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
from Products.PageTemplates.PageTemplate import PageTemplate |
from Products.PageTemplates.PageTemplate import PageTemplate |
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate |
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate |
Line 11 import os
|
Line 12 import os
|
import re |
import re |
import string |
import string |
import urllib |
import urllib |
|
import types |
from Globals import package_home |
from Globals import package_home |
|
|
def getString(self,key,default=''): |
def sendFile(self, filename, type): |
try: |
"""sends an object or a local file (in the product) as response""" |
return self.REQUEST[key] |
paths = filename.split('/') |
except: |
object = self |
return default |
# look for an object called filename |
|
for path in paths: |
|
if hasattr(object, path): |
class zogiLib_navTemplate(ZopePageTemplate): |
object = getattr(object, path) |
"""pageTemplate Objekt""" |
|
meta_type="zogiLib_navTemplate" |
|
|
|
_default_content_fn = os.path.join(package_home(globals()), |
|
'zpt/zogiLib_NavTemplateDefault.zpt') |
|
|
|
manage_options=ZopePageTemplate.manage_options+( |
|
{'label':'Copy to Filesystem','action':'copyContent'}, |
|
) |
|
|
|
def getPath(self): |
|
"""get path""" |
|
return getPath(self,'thumbtemplate.templ') |
|
|
|
## def changeECHO_pageTemplateWeightForm(self): |
|
## """change""" |
|
## pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_pageTemplateWeight.zpt').__of__(self) |
|
## return pt() |
|
|
|
## def changeECHO_pageTemplateWeight(self,weight,content_type,RESPONSE=None): |
|
## """change""" |
|
## self.weight=weight |
|
## self.content_type=content_type |
|
|
|
## if RESPONSE is not None: |
|
## RESPONSE.redirect('manage_main') |
|
|
|
|
|
def copyContent(self): |
|
"""copycontent to path""" |
|
|
|
return "copied to:"+copyContent(self,'thumbtemplate.templ') |
|
|
|
|
|
def manage_addZogiLib_NavTemplateForm(self): |
|
"""Form for adding""" |
|
pt=PageTemplateFile('Products/zogiLib/zpt/AddZogilib_NavTemplate.zpt').__of__(self) |
|
return pt() |
|
|
|
|
|
|
|
|
|
def manage_addZogiLib_NavTemplate(self, id,title=None, text=None, |
|
REQUEST=None, submit=None): |
|
"Add a Page Template with optional file content." |
|
|
|
|
|
id = str(id) |
|
if REQUEST is None: |
|
self._setObject(id, zogilib_NavTemplate(id, text)) |
|
ob = getattr(self, id) |
|
|
|
if title: |
|
ob.pt_setTitle(title) |
|
return ob |
|
else: |
|
file = REQUEST.form.get('file') |
|
headers = getattr(file, 'headers', None) |
|
if headers is None or not file.filename: |
|
zpt = zogilib_NavTemplate(id) |
|
else: |
|
zpt = zogilib_NavTemplate(id, file, headers.get('content_type')) |
|
|
|
self._setObject(id, zpt) |
|
ob = getattr(self, id) |
|
|
|
|
|
try: |
|
u = self.DestinationURL() |
|
except AttributeError: |
|
u = REQUEST['URL1'] |
|
|
|
if submit == " Add and Edit ": |
|
u = "%s/%s" % (u, quote(id)) |
|
REQUEST.RESPONSE.redirect(u+'/manage_main') |
|
return '' |
|
|
|
|
|
|
|
def readNavTemp(fileName): |
|
"""navtemp""" |
|
|
|
|
|
if os.path.exists(fileName+"/index.meta"): |
|
dom=xml.dom.minidom.parse(fileName+"/index.meta") |
|
else: |
else: |
return None |
object = None |
|
break |
|
if object: |
try: |
# if the object exists then send it |
navTag=getText(dom.getElementsByTagName('zogilibtemplate')[0].childNodes) |
return object.index_html(self.REQUEST.REQUEST, self.REQUEST.RESPONSE) |
except: |
else: |
navTag=None |
# send a local file with the given content-type |
return navTag |
fn = os.path.join(package_home(globals()), filename) |
|
self.REQUEST.RESPONSE.setHeader("Content-Type", type) |
|
self.REQUEST.RESPONSE.write(file(fn).read()) |
|
return |
|
|
class zogiLib_mainTemplate(ZopePageTemplate): |
def browserCheck(self): |
"""pageTemplate Objekt""" |
"""check the browsers request to find out the browser type""" |
meta_type="zogiLib_mainTemplate" |
bt = {} |
|
ua = self.REQUEST.get_header("HTTP_USER_AGENT") |
|
bt['ua'] = ua |
def __init__(self, id, text=None, content_type=None, version="book"): |
bt['isIE'] = string.find(ua, 'MSIE') > -1 |
|
bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1) and not bt['isIE'] |
default_content_string="zpt/zogiLibMain_%s.zpt"%version |
nav = ua[string.find(ua, '('):] |
self._default_content_fn = os.path.join(package_home(globals()),default_content_string) |
ie = string.split(nav, "; ")[1] |
self.id = str(id) |
if string.find(ie, "MSIE") > -1: |
self.ZBindings_edit(self._default_bindings) |
bt['versIE'] = string.split(ie, " ")[1] |
if text is None: |
bt['isMac'] = string.find(ua, 'Macintosh') > -1 |
text = open(self._default_content_fn).read() |
bt['isWin'] = string.find(ua, 'Windows') > -1 |
self.pt_edit(text, content_type) |
bt['isIEWin'] = bt['isIE'] and bt['isWin'] |
|
bt['isIEMac'] = bt['isIE'] and bt['isMac'] |
|
bt['staticHTML'] = False |
|
|
|
return bt |
|
|
def manage_addZogiLibMainTemplateForm(self): |
def manage_addZogiLibMainTemplateForm(self): |
"""Form for adding""" |
"""Form for adding""" |
pt=PageTemplateFile('Products/ECHO_content/zpt/AddOSAS_thumbTemplate.zpt').__of__(self) |
#FIXME:??? |
|
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/AddOSAS_thumbTemplate.zpt')).__of__(self) |
return pt() |
return pt() |
|
|
|
|
Line 143 def manage_addZogiLibMainTemplateForm(se
|
Line 67 def manage_addZogiLibMainTemplateForm(se
|
def manage_addZogiLibMainTemplate(self, id,title=None, text=None, |
def manage_addZogiLibMainTemplate(self, id,title=None, text=None, |
REQUEST=None, submit=None): |
REQUEST=None, submit=None): |
"Add a Page Template with optional file content." |
"Add a Page Template with optional file content." |
|
#FIXME:??? |
|
|
id = str(id) |
id = str(id) |
if REQUEST is None: |
if REQUEST is None: |
self._setObject(id, zogiLib_mainTemplate(id, text)) |
self._setObject(id, zogiLib_mainTemplate(id, text)) |
Line 180 class zogiImage(Image):
|
Line 103 class zogiImage(Image):
|
"""einzelnes Image""" |
"""einzelnes Image""" |
meta_type="zogiImage" |
meta_type="zogiImage" |
|
|
|
manage_options=ZopePageTemplate.manage_options+( |
|
{'label':'Main config','action':'changeZogiImageForm'}, |
|
) |
|
|
|
|
def __init__(self,id,title,baseUrl,queryString,content_type='',precondition=''): |
def __init__(self,id,title,baseUrl,queryString,content_type='',precondition=''): |
Line 197 class zogiImage(Image):
|
Line 123 class zogiImage(Image):
|
|
|
def changeZogiImageForm(self): |
def changeZogiImageForm(self): |
"""Main configuration""" |
"""Main configuration""" |
pt=PageTemplateFile('Products/zogiLib/zpt/changeZogiImageForm.zpt').__of__(self) |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiImageForm.zpt')).__of__(self) |
return pt() |
return pt() |
|
|
def changeZogiImage(self,title,baseUrl, queryString,RESPONSE=None): |
def changeZogiImage(self,title,baseUrl, queryString,RESPONSE=None): |
Line 210 class zogiImage(Image):
|
Line 136 class zogiImage(Image):
|
RESPONSE.redirect('manage_main') |
RESPONSE.redirect('manage_main') |
|
|
|
|
manage_options=ZopePageTemplate.manage_options+( |
|
{'label':'Main config','action':'changeZogiImageForm'}, |
|
) |
|
|
|
|
|
|
|
|
|
def index_html(self, REQUEST, RESPONSE): |
def index_html(self, REQUEST, RESPONSE): |
""" |
""" |
Modified version of OFS/Image.py |
Modified version of OFS/Image.py |
Line 483 class zogiImage(Image):
|
Line 402 class zogiImage(Image):
|
|
|
def manage_addZogiImageForm(self): |
def manage_addZogiImageForm(self): |
"""Form for adding""" |
"""Form for adding""" |
pt=PageTemplateFile('Products/zogiLib/zpt/addZogiImage.zpt').__of__(self) |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiImage.zpt')).__of__(self) |
return pt() |
return pt() |
|
|
|
|
Line 501 class zogiLib(Folder):
|
Line 420 class zogiLib(Folder):
|
|
|
meta_type="zogiLib" |
meta_type="zogiLib" |
|
|
def getDlInfo(self): |
manage_options = Folder.manage_options+( |
"""DLInfo""" |
{'label':'Main Config','action':'changeZogiLibForm'}, |
paramH={} |
) |
baseUrl=re.sub("servlet/Scaler","/dlInfo-xml.jsp",self.digilibBaseUrl) |
|
|
|
url=urllib.urlopen(baseUrl+self.REQUEST['QUERY_STRING']) |
|
dom=xml.dom.minidom.parse(url) |
|
params=dom.getElementsByTagName('parameter') |
|
for param in params: |
|
paramH[param.getAttribute('name')]=param.getAttribute('value') |
|
return paramH |
|
|
|
def getPageNumTotal(self): |
|
"""pagenums""" |
|
return self.getDlInfo()['pt'] |
|
|
|
|
|
def generateImageFolder(self): |
|
"""images ablegen""" |
|
self.manage_addFolder('images') |
|
pathName=os.path.join(package_home(globals()),'images') |
|
for image in os.listdir(pathName): |
|
try: |
|
|
|
fn=file(os.path.join(pathName,image)) |
|
self.images.manage_addImage(image,fn) |
|
except: |
|
print "ZOGILIB not importet:",image |
|
|
|
|
|
|
|
|
|
def __init__(self, id,title,digilibBaseUrl, localFileBase,version="book"): |
def __init__(self, id, title, digilibBaseUrl, localFileBase, version="book", basePath=""): |
"""init""" |
"""init""" |
|
|
self.id=id |
self.id=id |
self.title=title |
self.title=title |
self.digilibBaseUrl=digilibBaseUrl |
self.digilibBaseUrl=digilibBaseUrl |
self.localFileBase=localFileBase |
self.localFileBase=localFileBase |
#self._setObject('topTemplate',zogiLib_navTemplate(id='topTemplate')) |
self.basePath=basePath |
self._setObject('mainTemplate',zogiLib_mainTemplate(id='mainTemplate',version=version)) |
self.layout=version |
self.generateImageFolder() |
|
|
|
|
|
manage_options = Folder.manage_options+( |
|
{'label':'Main Config','action':'changeZogiLibForm'}, |
|
) |
|
|
|
def option_js(self): |
|
"""option_js""" |
|
ret="""function setParam(e) { |
|
if (document.all) s=e.srcElement; |
|
else s=e.target; |
|
|
|
if (window.opener) window.opener.location="%s/setParam?"+s.name+'='+s.value; |
|
else document.location="%s/setParam?"+s.name+'='+s.value; |
|
location |
|
}"""%(self.REQUEST['URL1'],self.REQUEST['URL1']) |
|
return ret |
|
|
|
|
|
def navigation_js(self): |
|
"""Javascript""" |
|
|
|
return file("../lib/python/Products/zogiLib/js/navigation.js").read() |
|
|
|
|
|
|
|
def generateTopJavaScript(self): |
|
"""generate script""" |
|
ret="""var baseUrl = '%s'; """% self.REQUEST['URL0'] |
|
ret+="""newParameter('fn', '%s', '', 1); |
|
newParameter('pn', '%s', '1', 1); |
|
newParameter('ws', '%s', '1.0', 1); |
|
newParameter('mo', '%s', '', 1); |
|
newParameter('mk', '%s', '', 3); |
|
newParameter('wx', '%s', '0.0', 2); |
|
newParameter('wy', '%s', '0.0', 2); |
|
newParameter('ww', '%s', '1.0', 2); |
|
newParameter('wh', '%s', '1.0', 2); |
|
newParameter('pt', '%s', '%s', 9); |
|
newParameter('brgt', '%s', '0.0', 1); |
|
newParameter('cont', '%s', '0.0', 1); |
|
newParameter('rot', '%s', '0.0', 1); |
|
newParameter('rgba', '%s', '', 1); |
|
newParameter('rgbm', '%s', '', 1); |
|
newParameter('ddpix', '%s', '', 9); |
|
newParameter('ddpiy', '%s', '', 9);"""%(getString(self,'fn'), |
|
getString(self,'pn',1), |
|
getString(self,'ws',1.0), |
|
getString(self,'mo',''), |
|
getString(self,'mk',''), |
|
getString(self,'wx',0.0), |
|
getString(self,'wy',0.0), |
|
getString(self,'ww',1.0), |
|
getString(self,'wh',1.0), |
|
getString(self,'pt',100),getString(self,'pt',100), |
|
getString(self,'brgt',0.0), |
|
getString(self,'cont',0.0), |
|
getString(self,'rot',0.0), |
|
getString(self,'rgba','0/0/0'), |
|
getString(self,'rgbm','0/0/0'), |
|
getString(self,'ddpix',0.0), |
|
getString(self,'ddpiy',0.0) |
|
) |
|
|
|
ret+=""" |
|
|
|
var wwidth, wheight; |
|
if (self.innerHeight) // all except Explorer |
|
{ |
|
wwidth = self.innerWidth; |
|
wheight = self.innerHeight; |
|
} |
|
else if (document.documentElement && document.documentElement.clientHeight) |
|
// Explorer 6 Strict Mode |
|
{ |
|
wwidth = document.documentElement.clientWidth; |
|
wheight = document.documentElement.clientHeight; |
|
} |
|
else if (document.body) // other Explorers |
|
{ |
|
wwidth = document.body.clientWidth; |
|
wheight = document.body.clientHeight; |
|
} |
|
|
|
document.id="digilib" |
|
|
|
""" |
def getDLInfo(self): |
return ret |
"""get DLInfo from digilib server""" |
|
paramH={} |
|
baseUrl=re.sub("servlet/Scaler","dlInfo-xml.jsp",self.digilibBaseUrl) |
|
try: |
|
url=urllib.urlopen(baseUrl+self.REQUEST['QUERY_STRING']) |
|
dom=xml.dom.minidom.parse(url) |
|
params=dom.getElementsByTagName('parameter') |
|
for param in params: |
|
paramH[param.getAttribute('name')]=param.getAttribute('value') |
|
return paramH |
|
except: |
|
return null |
|
|
|
|
|
def createHeadJS(self): |
|
"""generate all javascript tags for head""" |
|
self.checkQuery() |
|
bt = self.REQUEST.SESSION['browserType'] |
|
if bt['staticHTML']: |
|
return |
|
|
|
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_head_js')).__of__(self) |
|
return pt() |
|
|
|
def createParamJS(self): |
|
"""generate javascript for parameters only""" |
|
self.checkQuery() |
|
bt = self.REQUEST.SESSION['browserType'] |
|
if bt['staticHTML']: |
|
return |
|
|
|
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_param_js')).__of__(self) |
|
return pt() |
|
|
|
|
def generateScalerImg(self,requestString): |
def createScalerImg(self, requestString=None, bottom=0, side=0, width=500, height=500): |
"""generate Scaler Tag""" |
"""generate Scaler IMG Tag""" |
retStr=self.digilibBaseUrl+requestString |
self.checkQuery() |
jS="""<script type="text/javascript"> |
bt = self.REQUEST.SESSION['browserType'] |
document.write("<img id=\\\"pic\\\" src=\\\"%s&dw="+wwidth+"&dh="+wheight+"\\\"/>")</script>"""%retStr |
# override with parameters from session |
return jS |
if self.REQUEST.SESSION.has_key('scalerDiv'): |
|
(requestString, bottom, side, width, height) = self.REQUEST.SESSION['scalerDiv'] |
|
# if not explicitly defined take normal request |
|
if not requestString: |
|
requestString = self.getAllDLParams() |
|
url = self.digilibBaseUrl+requestString |
|
# construct bottom and side insets |
|
b_par = "" |
|
s_par = "" |
|
if (bottom != 0) or (side != 0): |
|
b_par = "-" + str(int(bottom)) |
|
s_par = "-" + str(int(side)) |
|
tag = "" |
|
if bt['staticHTML']: |
|
tag += '<div id="scaler"><img id="pic" src="%s&dw=%i&dh=%i" /></div>'%(url, int(width-side), int(height-bottom)) |
|
else: |
|
if bt['isN4']: |
|
# N4 needs layers |
|
tag += '<ilayer id="scaler">' |
|
else: |
|
tag += '<div id="scaler">' |
|
tag += '<script type="text/javascript">' |
|
tag += "var ps = bestPicSize(getElement('scaler'));" |
|
# write img tag with javascript |
|
tag += 'document.write(\'<img id="pic" src="%s&dw=\'+(ps.width%s)+\'&dh=\'+(ps.height%s)+\'" />\');'%(url, s_par, b_par) |
|
tag += '</script>' |
|
if bt['isN4']: |
|
tag += '</ilayer>' |
|
else: |
|
tag += '</div>' |
|
return tag |
|
|
|
def createScalerDiv(self, requestString = None, bottom = 0, side = 0, width=500, height=500): |
|
"""generate scaler img and table with navigation arrows""" |
|
self.checkQuery() |
|
if requestString != None or bottom != 0 or side != 0: |
|
self.REQUEST.SESSION['scalerDiv'] = (requestString, bottom, side, width, height) |
|
else: |
|
if self.REQUEST.SESSION.has_key('scalerDiv'): |
|
# make shure to remove unused parameter |
|
del self.REQUEST.SESSION['scalerDiv'] |
|
|
def changeZogiLibForm(self): |
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/zogilib_img_div')).__of__(self) |
"""Main configuration""" |
|
pt=PageTemplateFile('Products/zogiLib/zpt/changeZogiLibForm.zpt').__of__(self) |
|
return pt() |
return pt() |
|
|
def changeZogiLib(self,title,digilibBaseUrl, localFileBase,RESPONSE=None): |
def createAuxDiv(self): |
"""change it""" |
"""generate other divs""" |
self.title=title |
self.checkQuery() |
self.digilibBaseUrl=digilibBaseUrl |
bt = self.REQUEST.SESSION['browserType'] |
self.localFileBase=localFileBase |
if bt['staticHTML']: |
|
return |
|
if bt['isN4']: |
|
f = 'zpt/zogilib_divsN4.zpt' |
|
else: |
|
f = 'zpt/zogilib_divs.zpt' |
|
pt=PageTemplateFile(os.path.join(package_home(globals()),f)).__of__(self) |
|
return pt() |
|
|
if RESPONSE is not None: |
|
RESPONSE.redirect('manage_main') |
|
|
|
|
def option_js(self): |
|
"""option_js""" |
|
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/option_js')).__of__(self) |
|
return pt() |
|
|
def nav_html(self,fileName): |
def dl_lib_js(self): |
"""navigations frame""" |
"""javascript""" |
|
return sendFile(self, 'js/dl_lib.js', 'text/plain') |
|
|
|
def js_lib_js(self): |
|
"""javascript""" |
|
return sendFile(self, 'js/js_lib.js', 'text/plain') |
|
|
# suche nach index.meta mit zogilib thumb info |
def optionwindow(self): |
|
"""showoptions""" |
|
self.checkQuery() |
|
bt = self.REQUEST.SESSION['browserType'] |
|
if bt['staticHTML']: |
|
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow_static.zpt')).__of__(self) |
|
else: |
|
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow.zpt')).__of__(self) |
|
return pt() |
|
|
templ=readNavTemp(self.localFileBase+"/"+fileName) |
def mark1(self): |
if not templ: |
"""mark image""" |
templ=readNavTemp(self.localFileBase+"/"+fileName.split("/")[0]) |
return sendFile(self, 'images/mark1.gif', 'image/gif') |
if not templ: |
|
return self.topTemplate.document_src() |
def mark2(self): |
|
"""mark image""" |
|
return sendFile(self, 'images/mark2.gif', 'image/gif') |
|
|
|
def mark3(self): |
|
"""mark image""" |
|
return sendFile(self, 'images/mark3.gif', 'image/gif') |
|
|
|
def mark4(self): |
|
"""mark image""" |
|
return sendFile(self, 'images/mark4.gif', 'image/gif') |
|
|
|
def mark5(self): |
|
"""mark image""" |
|
return sendFile(self, 'images/mark5.gif', 'image/gif') |
|
|
|
def mark6(self): |
|
"""mark image""" |
|
return sendFile(self, 'images/mark6.gif', 'image/gif') |
|
|
|
def mark7(self): |
|
"""mark image""" |
|
return sendFile(self, 'images/mark7.gif', 'image/gif') |
|
|
|
def mark8(self): |
|
"""mark image""" |
|
return sendFile(self, 'images/mark8.gif', 'image/gif') |
|
|
|
def corner1(self): |
|
"""mark image""" |
|
return sendFile(self, 'images/olinks.gif', 'image/gif') |
|
|
|
def corner2(self): |
|
"""mark image""" |
|
return sendFile(self, 'images/orechts.gif', 'image/gif') |
|
|
|
def corner3(self): |
|
"""mark image""" |
|
return sendFile(self, 'images/ulinks.gif', 'image/gif') |
|
|
|
def corner4(self): |
|
"""mark image""" |
|
return sendFile(self, 'images/urechts.gif', 'image/gif') |
|
|
|
def up_img(self): |
|
"""mark image""" |
|
return sendFile(self, 'images/up.gif', 'image/gif') |
|
|
|
def down_img(self): |
|
"""mark image""" |
|
return sendFile(self, 'images/down.gif', 'image/gif') |
|
|
|
def left_img(self): |
|
"""mark image""" |
|
return sendFile(self, 'images/left.gif', 'image/gif') |
|
|
|
def right_img(self): |
|
"""mark image""" |
|
return sendFile(self, 'images/right.gif', 'image/gif') |
|
|
return urllib.urlopen(templ).read() |
|
|
|
|
|
def index_html(self): |
def index_html(self): |
"""main action""" |
"""main action""" |
|
self.checkQuery() |
|
bt = self.REQUEST.SESSION['browserType'] |
|
tp = "zogiLibMainTemplate" |
|
if hasattr(self, tp): |
|
pt = getattr(self, tp) |
|
else: |
|
tpt = self.layout |
|
if bt['staticHTML']: |
|
tpt = "static" |
|
|
|
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogiLibMain_%s'%tpt)).__of__(self) |
|
|
#pt=PageTemplateFile('Products/zogiLib/zpt/zogiLibMain_image.zpt').__of__(self) |
return pt() |
#return pt() |
|
return self.mainTemplate() |
|
|
|
def storeQuery(self): |
|
"""storeQuery in session""" |
|
self.REQUEST.SESSION['query']={} |
|
for fm in self.REQUEST.form.keys(): |
|
self.REQUEST.SESSION['query'][fm]=self.REQUEST.form[fm] |
|
|
|
self.REQUEST.SESSION['dlInfo']=self.getDlInfo() |
|
|
|
def getParam(self,param): |
def storeQuery(self, more = None): |
"""Gebe Parameter aus""" |
"""storeQuery in session""" |
|
dlParams = {} |
|
for fm in self.REQUEST.form.keys(): |
|
dlParams[fm] = self.REQUEST.form[fm] |
|
# look for more |
|
if more: |
|
for fm in more.split('&'): |
try: |
try: |
return self.REQUEST.SESSION['query'][param] |
pv = fm.split('=') |
|
dlParams[pv[0]] = pv[1] |
except: |
except: |
return None |
pass |
|
|
def getPageNum(self): |
|
"""PAgenum""" |
|
pn=self.getParam('pn') |
|
if pn: |
|
return pn |
|
else: |
|
return 1 |
|
|
|
def biggerWS(self): |
|
"""ws+1""" |
|
ws=self.getParam('ws') |
|
if ws: |
|
return int(ws)+1 |
|
else: |
|
return 2 |
|
|
|
def options(self): |
# parse digilib mode parameter |
"""showoptions""" |
if 'mo' in dlParams: |
pt=PageTemplateFile('Products/zogiLib/zpt/optionwindow.zpt').__of__(self) |
if len(dlParams['mo']) > 0: |
return pt() |
modes=dlParams['mo'].split(',') |
|
else: |
|
modes=[] |
|
|
|
self.REQUEST.SESSION['query'] = dlParams |
|
self.REQUEST.SESSION['dlModes'] = modes |
|
self.REQUEST.SESSION['dlInfo'] = self.getDLInfo() |
|
if not self.REQUEST.SESSION.has_key('browserType'): |
|
self.REQUEST.SESSION['browserType'] = browserCheck(self) |
|
|
|
|
def smallerWS(self): |
|
"""ws-11""" |
|
ws=self.getParam('ws') |
|
if ws: |
|
if int(ws)==1: |
|
return |
return |
else: |
|
return int(ws)-1 |
|
else: |
|
return 1 |
|
|
|
|
|
def setParam(self,pn=None,ws=None,rot=None,brgt=None,cont=None): |
|
"""setze Parameter""" |
|
ret="" |
|
|
|
if brgt: |
|
self.REQUEST.SESSION['query']['brgt']=brgt |
|
|
|
if cont: |
|
self.REQUEST.SESSION['query']['cont']=cont |
|
|
|
if pn: |
def checkQuery(self): |
self.REQUEST.SESSION['query']['pn']=pn |
"""check if the query has been stored""" |
|
if not (self.REQUEST.SESSION and self.REQUEST.SESSION.has_key('query')) : |
if ws: |
print "ZOGILIB: have to store query!!" |
self.REQUEST.SESSION['query']['ws']=ws |
self.storeQuery() |
|
return |
if rot: |
|
self.REQUEST.SESSION['query']['rot']=rot |
|
|
|
for param in self.REQUEST.SESSION['query'].keys(): |
|
|
|
ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&" |
|
|
|
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret) |
|
|
|
|
def zogilibPath(self, otherbase=None): |
|
"""returns an URL to the zogiLib instance""" |
|
url = self.REQUEST['URL1'] |
|
# should end with "/" |
|
if len(url) > 0 and url[-1] != '/': |
|
url += '/' |
|
if type(otherbase) is str: |
|
url += otherbase |
|
else: |
|
url += self.basePath |
|
# should end with "/" |
|
if len(url) > 0 and url[-1] != '/': |
|
url += '/' |
|
return url |
|
|
def mirrorPage(self,mi): |
def getDLParam(self, param): |
"""mirror""" |
"""returns parameter""" |
ret="" |
|
try: |
try: |
splitted=self.REQUEST.SESSION['query']['mo'].split(',') |
return self.REQUEST.SESSION['query'][param] |
except: |
except: |
splitted=[] |
return |
|
|
if mi=="h": |
|
|
|
if 'hmir' in splitted: |
|
splitted.remove('hmir') |
|
else: |
|
splitted.append('hmir') |
|
|
|
if mi=="v": |
|
|
|
if 'vmir' in splitted: |
|
splitted.remove('vmir') |
|
else: |
|
splitted.append('vmir') |
|
|
|
|
|
self.REQUEST.SESSION['query']['mo']=string.join(splitted,",") |
|
|
|
|
|
|
|
|
|
for param in self.REQUEST.SESSION['query'].keys(): |
|
|
|
ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&" |
|
|
|
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret) |
|
|
|
def decode(self,strR): |
|
"""decode &""" |
|
|
|
return re.sub('\&','\&',strR) |
def setDLParam(self, param, value): |
|
"""sets parameter""" |
|
self.REQUEST.SESSION['query'][param] = value |
|
return |
|
|
def wholePage(self): |
def getAllDLParams(self): |
"""zoom out""" |
"""parameter string for digilib""" |
|
dlParams = self.REQUEST.SESSION['query'] |
|
# save modes |
|
modes = self.REQUEST.SESSION['dlModes'] |
|
dlParams['mo'] = string.join(modes, ',') |
|
# assemble query string |
ret="" |
ret="" |
|
for param in dlParams.keys(): |
|
val = str(dlParams[param]) |
|
if val != "": |
|
ret += param + "=" + val + "&" |
|
# omit trailing "&" |
|
return ret.rstrip('&') |
|
|
self.REQUEST.SESSION['query']['ww']=1 |
|
self.REQUEST.SESSION['query']['wh']=1 |
|
self.REQUEST.SESSION['query']['wx']=0 |
|
self.REQUEST.SESSION['query']['wy']=0 |
|
|
|
for param in self.REQUEST.SESSION['query'].keys(): |
|
|
|
ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&" |
|
|
|
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret) |
def setDLParams(self,pn=None,ws=None,rot=None,brgt=None,cont=None): |
|
"""setze Parameter""" |
|
|
def prevPage(self,pn=None): |
self.setDLParam('brgt', brgt) |
"""next page""" |
self.setDLParam('cont', cont) |
ret="" |
self.setDLParam('ws', ws) |
|
self.setDLParam('rot', rot) |
|
|
if pn and pn>0: |
if pn: |
pn=str(int(pn)-1) |
# unmark |
|
self.setDLParam('mk', None) |
|
self.setDLParam('pn', pn) |
|
|
|
return self.display() |
|
|
self.REQUEST.form['pn']=pn |
|
|
|
for param in self.REQUEST.form.keys(): |
def display(self): |
|
"""(re)display page""" |
|
params = self.getAllDLParams() |
|
if self.basePath: |
|
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?'+params) |
|
else: |
|
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params) |
|
|
ret+=param+"="+str(self.REQUEST.form[param])+"&" |
|
|
|
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret) |
def setStaticHTML(self, static=True): |
|
"""sets the preference to static HTML""" |
|
self.checkQuery() |
|
self.REQUEST.SESSION['browserType']['staticHTML'] = static |
|
return |
|
|
def firstPage(self): |
def isStaticHTML(self): |
"""erste Seite""" |
"""returns if the page is using static HTML only""" |
return self.setParam(pn="1") |
self.checkQuery() |
|
return self.REQUEST.SESSION['browserType']['staticHTML'] |
|
|
def lastPage(self): |
def getPT(self): |
"""letzte Seite""" |
"""pagenums""" |
|
di = self.REQUEST.SESSION['dlInfo'] |
|
if di: |
|
return int(di['pt']) |
|
else: |
|
return 1 |
|
|
|
def getPN(self): |
|
"""Pagenum""" |
|
pn = self.getDLParam('pn') |
|
try: |
|
return int(pn) |
|
except: |
|
return 1 |
|
|
def nextPage(self,pn=None): |
def getBiggerWS(self): |
"""next page""" |
"""ws+1""" |
ret="" |
ws = self.getDLParam('ws') |
|
try: |
|
return float(ws)+0.5 |
|
except: |
|
return 1.5 |
|
|
|
def getSmallerWS(self): |
|
"""ws-1""" |
|
ws=self.getDLParam('ws') |
try: |
try: |
pn=str(int(pn)+1) |
return max(float(ws)-0.5, 1) |
except: |
except: |
pn=str(2) |
return 1 |
|
|
|
def hasMode(self, mode): |
|
"""returns if mode is in the diglib mo parameter""" |
|
return (mode in self.REQUEST.SESSION['dlModes']) |
|
|
|
def hasNextPage(self): |
|
"""returns if there is a next page""" |
|
pn = self.getPN() |
|
pt = self.getPT() |
|
return (pn < pt) |
|
|
|
def hasPrevPage(self): |
|
"""returns if there is a previous page""" |
|
pn = self.getPN() |
|
return (pn > 1) |
|
|
|
def canMoveLeft(self): |
|
"""returns if its possible to move left""" |
|
wx = float(self.getDLParam('wx') or 0) |
|
return (wx > 0) |
|
|
|
def canMoveRight(self): |
|
"""returns if its possible to move right""" |
|
wx = float(self.getDLParam('wx') or 0) |
|
ww = float(self.getDLParam('ww') or 1) |
|
return (wx + ww < 1) |
|
|
|
def canMoveUp(self): |
|
"""returns if its possible to move up""" |
|
wy = float(self.getDLParam('wy') or 0) |
|
return (wy > 0) |
|
|
|
def canMoveDown(self): |
|
"""returns if its possible to move down""" |
|
wy = float(self.getDLParam('wy') or 0) |
|
wh = float(self.getDLParam('wh') or 1) |
|
return (wy + wh < 1) |
|
|
|
|
|
def dl_StaticHTML(self): |
|
"""set rendering to static HTML""" |
|
self.checkQuery() |
|
self.REQUEST.SESSION['browserType']['staticHTML'] = True |
|
return self.display() |
|
|
|
def dl_DynamicHTML(self): |
|
"""set rendering to dynamic HTML""" |
|
self.checkQuery() |
|
self.REQUEST.SESSION['browserType']['staticHTML'] = False |
|
return self.display() |
|
|
|
def dl_HMirror(self): |
|
"""mirror action""" |
|
modes = self.REQUEST.SESSION['dlModes'] |
|
if 'hmir' in modes: |
|
modes.remove('hmir') |
|
else: |
|
modes.append('hmir') |
|
|
|
return self.display() |
|
|
|
def dl_VMirror(self): |
|
"""mirror action""" |
|
modes = self.REQUEST.SESSION['dlModes'] |
|
if 'vmir' in modes: |
|
modes.remove('vmir') |
|
else: |
|
modes.append('vmir') |
|
|
|
return self.display() |
|
|
|
def dl_Zoom(self, z): |
|
"""general zoom action""" |
|
ww1 = float(self.getDLParam('ww') or 1) |
|
wh1 = float(self.getDLParam('wh') or 1) |
|
wx = float(self.getDLParam('wx') or 0) |
|
wy = float(self.getDLParam('wy') or 0) |
|
ww2 = ww1 * z |
|
wh2 = wh1 * z |
|
wx += (ww1 - ww2) / 2 |
|
wy += (wh1 - wh2) / 2 |
|
ww2 = max(min(ww2, 1), 0) |
|
wh2 = max(min(wh2, 1), 0) |
|
wx = max(min(wx, 1), 0) |
|
wy = max(min(wy, 1), 0) |
|
self.setDLParam('ww', ww2) |
|
self.setDLParam('wh', wh2) |
|
self.setDLParam('wx', wx) |
|
self.setDLParam('wy', wy) |
|
return self.display() |
|
|
|
def dl_ZoomIn(self): |
|
"""zoom in action""" |
|
z = 0.7071 |
|
return self.dl_Zoom(z) |
|
|
|
def dl_ZoomOut(self): |
|
"""zoom out action""" |
|
z = 1.4142 |
|
return self.dl_Zoom(z) |
|
|
|
def dl_Move(self, dx, dy): |
|
"""general move action""" |
|
ww = float(self.getDLParam('ww') or 1) |
|
wh = float(self.getDLParam('wh') or 1) |
|
wx = float(self.getDLParam('wx') or 0) |
|
wy = float(self.getDLParam('wy') or 0) |
|
wx += dx * 0.5 * ww |
|
wy += dy * 0.5 * wh |
|
wx = max(min(wx, 1), 0) |
|
wy = max(min(wy, 1), 0) |
|
self.setDLParam('wx', wx) |
|
self.setDLParam('wy', wy) |
|
return self.display() |
|
|
|
def dl_MoveLeft(self): |
|
"""move left action""" |
|
return self.dl_Move(-1, 0) |
|
|
|
def dl_MoveRight(self): |
|
"""move left action""" |
|
return self.dl_Move(1, 0) |
|
|
|
def dl_MoveUp(self): |
|
"""move left action""" |
|
return self.dl_Move(0, -1) |
|
|
|
def dl_MoveDown(self): |
|
"""move left action""" |
|
return self.dl_Move(0, 1) |
|
|
|
def dl_WholePage(self): |
|
"""zoom out action""" |
|
self.setDLParam('ww', 1) |
|
self.setDLParam('wh', 1) |
|
self.setDLParam('wx', 0) |
|
self.setDLParam('wy', 0) |
|
return self.display() |
|
|
|
def dl_PrevPage(self): |
|
"""next page action""" |
|
pn = self.getPN() - 1 |
|
if pn < 1: |
|
pn = 1 |
|
self.setDLParam('pn', pn) |
|
# unmark |
|
self.setDLParam('mk', None) |
|
return self.display() |
|
|
|
def dl_NextPage(self): |
|
"""next page action""" |
|
pn = self.getPN() + 1 |
|
pt = self.getPT() |
|
if pn > pt: |
|
pn = pt |
|
self.setDLParam('pn', pn) |
|
# unmark |
|
self.setDLParam('mk', None) |
|
return self.display() |
|
|
|
def dl_FirstPage(self): |
|
"""first page action""" |
|
self.setDLParam('pn', 1) |
|
# unmark |
|
self.setDLParam('mk', None) |
|
return self.display() |
|
|
|
def dl_LastPage(self): |
|
"""last page action""" |
|
self.setDLParam('pn', self.getPT()) |
|
# unmark |
|
self.setDLParam('mk', None) |
|
return self.display() |
|
|
|
def dl_Unmark(self): |
|
"""action to remove last mark""" |
|
mk = self.getDLParam('mk') |
|
if mk: |
|
marks = mk.split(',') |
|
marks.pop() |
|
mk = string.join(marks, ',') |
|
self.setDLParam('mk', mk) |
|
return self.display() |
|
|
|
|
self.REQUEST.form['pn']=pn |
|
|
|
for param in self.REQUEST.form.keys(): |
def changeZogiLibForm(self): |
ret+=param+"="+str(self.REQUEST.form[param])+"&" |
"""Main configuration""" |
|
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self) |
|
return pt() |
|
|
|
def changeZogiLib(self,title,digilibBaseUrl, localFileBase, version, basePath, RESPONSE=None): |
|
"""change it""" |
|
self.title=title |
|
self.digilibBaseUrl=digilibBaseUrl |
|
self.localFileBase=localFileBase |
|
self.basePath = basePath |
|
self.layout=version |
|
|
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret) |
if RESPONSE is not None: |
|
RESPONSE.redirect('manage_main') |
|
|
|
|
def manage_addZogiLibForm(self): |
def manage_addZogiLibForm(self): |
"""interface for adding zogilib""" |
"""interface for adding zogilib""" |
pt=PageTemplateFile('Products/zogiLib/zpt/addZogiLibForm').__of__(self) |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self) |
return pt() |
return pt() |
|
|
def manage_addZogiLib(self,id,title,digilibBaseUrl, localFileBase,version="book",RESPONSE=None): |
def manage_addZogiLib(self,id,title,digilibBaseUrl, localFileBase,version="book",basePath="",RESPONSE=None): |
"""add dgilib""" |
"""add dgilib""" |
newObj=zogiLib(id,title,digilibBaseUrl, localFileBase, version) |
newObj=zogiLib(id,title,digilibBaseUrl, localFileBase, version, basePath) |
self.Destination()._setObject(id,newObj) |
self.Destination()._setObject(id,newObj) |
if RESPONSE is not None: |
if RESPONSE is not None: |
RESPONSE.redirect('manage_main') |
RESPONSE.redirect('manage_main') |