version 1.25, 2004/06/04 16:07:49
|
version 1.31, 2004/07/16 13:47:50
|
Line 15 import urllib
|
Line 15 import urllib
|
import types |
import types |
from Globals import package_home |
from Globals import package_home |
|
|
def getString(self,key,default=''): |
ZOGIVERSION = "0.9.5 ROC:25.6.2004" |
try: |
|
return self.REQUEST[key] |
def cropf(f): |
except: |
"""returns a float with reduced precision""" |
return default |
return float(int(f * 10000)/10000.0) |
|
|
|
|
def sendFile(self, filename, type): |
def sendFile(self, filename, type): |
"""sends an object or a local file (in the product) as response""" |
"""sends an object or a local file (in the product) as response""" |
Line 42 def sendFile(self, filename, type):
|
Line 43 def sendFile(self, filename, type):
|
self.REQUEST.RESPONSE.write(file(fn).read()) |
self.REQUEST.RESPONSE.write(file(fn).read()) |
return |
return |
|
|
class BrowserCheck: |
def browserCheck(self): |
"""check the browsers request to find out the browser type""" |
"""check the browsers request to find out the browser type""" |
|
bt = {} |
def __init__(self, zope): |
ua = self.REQUEST.get_header("HTTP_USER_AGENT") |
self.ua = zope.REQUEST.get_header("HTTP_USER_AGENT") |
bt['ua'] = ua |
self.isIE = string.find(self.ua, 'MSIE') > -1 |
bt['isIE'] = string.find(ua, 'MSIE') > -1 |
self.isN4 = (string.find(self.ua, 'Mozilla/4.') > -1) and not self.isIE |
bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1) and not bt['isIE'] |
self.nav = self.ua[string.find(self.ua, '('):] |
nav = ua[string.find(ua, '('):] |
ie = string.split(self.nav, "; ")[1] |
ie = string.split(nav, "; ")[1] |
if string.find(ie, "MSIE") > -1: |
if string.find(ie, "MSIE") > -1: |
self.versIE = string.split(ie, " ")[1] |
bt['versIE'] = string.split(ie, " ")[1] |
self.isMac = string.find(self.ua, 'Macintosh') > -1 |
bt['isMac'] = string.find(ua, 'Macintosh') > -1 |
self.isWin = string.find(self.ua, 'Windows') > -1 |
bt['isWin'] = string.find(ua, 'Windows') > -1 |
self.isIEWin = self.isIE and self.isWin |
bt['isIEWin'] = bt['isIE'] and bt['isWin'] |
self.isIEMac = self.isIE and self.isMac |
bt['isIEMac'] = bt['isIE'] and bt['isMac'] |
|
bt['staticHTML'] = False |
|
|
def manage_addZogiLibMainTemplateForm(self): |
|
"""Form for adding""" |
|
#FIXME:??? |
|
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/AddOSAS_thumbTemplate.zpt')).__of__(self) |
|
return pt() |
|
|
|
|
|
|
|
|
|
def manage_addZogiLibMainTemplate(self, id,title=None, text=None, |
|
REQUEST=None, submit=None): |
|
"Add a Page Template with optional file content." |
|
#FIXME:??? |
|
id = str(id) |
|
if REQUEST is None: |
|
self._setObject(id, zogiLib_mainTemplate(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_mainTemplate(id) |
|
else: |
|
zpt = zogiLib_mainTemplate(id, file, headers.get('content_type')) |
|
|
|
self._setObject(id, zpt) |
|
ob = getattr(self, id) |
|
|
|
|
return bt |
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 '' |
|
|
|
|
|
class zogiImage(Image): |
class zogiImage(Image): |
Line 428 class zogiLib(Folder):
|
Line 388 class zogiLib(Folder):
|
{'label':'Main Config','action':'changeZogiLibForm'}, |
{'label':'Main Config','action':'changeZogiLibForm'}, |
) |
) |
|
|
def __init__(self, id, title, digilibBaseUrl, localFileBase, version="book", basePath=""): |
def __init__(self, id, title, digilibBaseUrl, localFileBase, version="book", basePath="", dlTarget=None): |
"""init""" |
"""init""" |
|
|
self.id=id |
self.id=id |
Line 437 class zogiLib(Folder):
|
Line 397 class zogiLib(Folder):
|
self.localFileBase=localFileBase |
self.localFileBase=localFileBase |
self.basePath=basePath |
self.basePath=basePath |
self.layout=version |
self.layout=version |
|
if dlTarget: |
|
self.dlTarget = dlTarget |
|
else: |
|
self.dlTarget = "digilib" |
|
|
|
def version(self): |
|
"""version information""" |
|
return ZOGIVERSION |
|
|
def getDLInfo(self): |
def getDLInfo(self): |
"""get DLInfo from digilib server""" |
"""get DLInfo from digilib server""" |
Line 456 class zogiLib(Folder):
|
Line 423 class zogiLib(Folder):
|
|
|
def createHeadJS(self): |
def createHeadJS(self): |
"""generate all javascript tags for head""" |
"""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) |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_head_js')).__of__(self) |
return pt() |
return pt() |
|
|
def createParamJS(self): |
def createParamJS(self): |
"""generate javascript for parameters only""" |
"""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) |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogilib_param_js')).__of__(self) |
return pt() |
return pt() |
|
|
|
|
def createScalerImg(self, requestString = None, bottom = 0, side = 0): |
def createScalerImg(self, requestString=None, bottom=0, side=0, width=500, height=500): |
"""generate Scaler IMG Tag""" |
"""generate Scaler IMG Tag""" |
self.checkQuery() |
self.checkQuery() |
bt = self.REQUEST.SESSION['browserType'] |
bt = self.REQUEST.SESSION['browserType'] |
# override with parameters from session |
# override with parameters from session |
if self.REQUEST.SESSION.has_key('scalerDiv'): |
if self.REQUEST.SESSION.has_key('scalerDiv'): |
(requestString, bottom, side) = self.REQUEST.SESSION['scalerDiv'] |
(requestString, bottom, side, width, height) = self.REQUEST.SESSION['scalerDiv'] |
# if not explicitly defined take normal request |
# if not explicitly defined take normal request |
if not requestString: |
if not requestString: |
requestString = self.getAllDLParams() |
requestString = self.getAllDLParams() |
Line 483 class zogiLib(Folder):
|
Line 460 class zogiLib(Folder):
|
b_par = "-" + str(int(bottom)) |
b_par = "-" + str(int(bottom)) |
s_par = "-" + str(int(side)) |
s_par = "-" + str(int(side)) |
tag = "" |
tag = "" |
if bt.isN4: |
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 |
# N4 needs layers |
tag += '<ilayer id="scaler">' |
tag += '<ilayer id="scaler">' |
else: |
else: |
Line 493 class zogiLib(Folder):
|
Line 473 class zogiLib(Folder):
|
# write img tag with javascript |
# 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 += 'document.write(\'<img id="pic" src="%s&dw=\'+(ps.width%s)+\'&dh=\'+(ps.height%s)+\'" />\');'%(url, s_par, b_par) |
tag += '</script>' |
tag += '</script>' |
if bt.isN4: |
if bt['isN4']: |
tag += '</ilayer>' |
tag += '</ilayer>' |
else: |
else: |
tag += '</div>' |
tag += '</div>' |
return tag |
return tag |
|
|
def createScalerDiv(self, requestString = None, bottom = 0, side = 0): |
def createScalerDiv(self, requestString = None, bottom = 0, side = 0, width=500, height=500): |
"""generate scaler img and table with navigation arrows""" |
"""generate scaler img and table with navigation arrows""" |
self.checkQuery() |
self.checkQuery() |
if requestString != None or bottom != 0 or side != 0: |
if requestString != None or bottom != 0 or side != 0: |
self.REQUEST.SESSION['scalerDiv'] = (requestString, bottom, side) |
self.REQUEST.SESSION['scalerDiv'] = (requestString, bottom, side, width, height) |
else: |
else: |
if self.REQUEST.SESSION.has_key('scalerDiv'): |
if self.REQUEST.SESSION.has_key('scalerDiv'): |
|
# make shure to remove unused parameter |
del self.REQUEST.SESSION['scalerDiv'] |
del self.REQUEST.SESSION['scalerDiv'] |
|
|
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/zogilib_img_div')).__of__(self) |
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/zogilib_img_div')).__of__(self) |
return pt() |
return pt() |
|
|
Line 514 class zogiLib(Folder):
|
Line 496 class zogiLib(Folder):
|
"""generate other divs""" |
"""generate other divs""" |
self.checkQuery() |
self.checkQuery() |
bt = self.REQUEST.SESSION['browserType'] |
bt = self.REQUEST.SESSION['browserType'] |
if bt.isN4: |
if bt['staticHTML']: |
|
return |
|
if bt['isN4']: |
f = 'zpt/zogilib_divsN4.zpt' |
f = 'zpt/zogilib_divsN4.zpt' |
else: |
else: |
f = 'zpt/zogilib_divs.zpt' |
f = 'zpt/zogilib_divs.zpt' |
Line 523 class zogiLib(Folder):
|
Line 507 class zogiLib(Folder):
|
|
|
|
|
def option_js(self): |
def option_js(self): |
"""option_js""" |
"""javascript""" |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/option_js')).__of__(self) |
return sendFile(self, 'js/option.js', 'text/plain') |
return pt() |
|
|
|
def dl_lib_js(self): |
def dl_lib_js(self): |
"""javascript""" |
"""javascript""" |
Line 537 class zogiLib(Folder):
|
Line 520 class zogiLib(Folder):
|
|
|
def optionwindow(self): |
def optionwindow(self): |
"""showoptions""" |
"""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: |
|
finds=self.ZopeFind(self,obj_ids=['viewingTools.zpt']) |
|
if finds: |
|
|
|
return finds[0][1]() |
|
else: |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow.zpt')).__of__(self) |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow.zpt')).__of__(self) |
return pt() |
return pt() |
|
|
Line 608 class zogiLib(Folder):
|
Line 601 class zogiLib(Folder):
|
|
|
def index_html(self): |
def index_html(self): |
"""main action""" |
"""main action""" |
|
self.checkQuery() |
|
bt = self.REQUEST.SESSION['browserType'] |
tp = "zogiLibMainTemplate" |
tp = "zogiLibMainTemplate" |
if hasattr(self, tp): |
if hasattr(self, tp): |
pt = getattr(self, tp) |
pt = getattr(self, tp) |
else: |
else: |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogiLibMain_%s'%self.layout)).__of__(self) |
tpt = self.layout |
|
if bt['staticHTML']: |
|
tpt = "static" |
|
|
|
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/zogiLibMain_%s'%tpt)).__of__(self) |
|
|
return pt() |
return pt() |
|
|
|
|
Line 629 class zogiLib(Folder):
|
Line 629 class zogiLib(Folder):
|
pv = fm.split('=') |
pv = fm.split('=') |
dlParams[pv[0]] = pv[1] |
dlParams[pv[0]] = pv[1] |
except: |
except: |
print "ouch!" |
pass |
|
|
# parse digilib mode parameter |
# parse digilib mode parameter |
if 'mo' in dlParams: |
if 'mo' in dlParams: |
if len(dlParams['mo']) > 0: |
if len(dlParams['mo']) > 0: |
Line 640 class zogiLib(Folder):
|
Line 641 class zogiLib(Folder):
|
self.REQUEST.SESSION['query'] = dlParams |
self.REQUEST.SESSION['query'] = dlParams |
self.REQUEST.SESSION['dlModes'] = modes |
self.REQUEST.SESSION['dlModes'] = modes |
self.REQUEST.SESSION['dlInfo'] = self.getDLInfo() |
self.REQUEST.SESSION['dlInfo'] = self.getDLInfo() |
self.REQUEST.SESSION['browserType'] = BrowserCheck(self) |
if not self.REQUEST.SESSION.has_key('browserType'): |
|
self.REQUEST.SESSION['browserType'] = browserCheck(self) |
|
|
|
return |
|
|
def checkQuery(self): |
def checkQuery(self): |
"""check if the query has been stored""" |
"""check if the query has been stored""" |
if not (self.REQUEST.SESSION): |
if not (self.REQUEST.SESSION and self.REQUEST.SESSION.has_key('query')) : |
print "ZOGILIB: have to store query!!" |
print "ZOGILIB: have to store query!!" |
self.storeQuery |
self.storeQuery() |
return |
return |
|
|
def zogilibPath(self, otherbase=None): |
def zogilibPath(self, otherbase=None): |
Line 685 class zogiLib(Folder):
|
Line 689 class zogiLib(Folder):
|
# assemble query string |
# assemble query string |
ret = "" |
ret = "" |
for param in dlParams.keys(): |
for param in dlParams.keys(): |
|
if dlParams[param] is None: continue |
val = str(dlParams[param]) |
val = str(dlParams[param]) |
if val != "": |
if val != "": |
ret += param + "=" + val + "&" |
ret += param + "=" + val + "&" |
|
|
# omit trailing "&" |
# omit trailing "&" |
return ret.rstrip('&') |
return ret.rstrip('&') |
|
|
Line 716 class zogiLib(Folder):
|
Line 722 class zogiLib(Folder):
|
else: |
else: |
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params) |
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params) |
|
|
|
|
|
def getDLTarget(self): |
|
"""returns dlTarget""" |
|
self.checkQuery() |
|
s = self.dlTarget |
|
# s = 'dl' |
|
# if self.getDLParam('fn'): |
|
# s += "_" + self.getDLParam('fn') |
|
# if self.getDLParam('pn'): |
|
# s += "_" + self.getDLParam('pn') |
|
return s |
|
|
|
def setStaticHTML(self, static=True): |
|
"""sets the preference to static HTML""" |
|
self.checkQuery() |
|
self.REQUEST.SESSION['browserType']['staticHTML'] = static |
|
return |
|
|
|
def isStaticHTML(self): |
|
"""returns if the page is using static HTML only""" |
|
self.checkQuery() |
|
return self.REQUEST.SESSION['browserType']['staticHTML'] |
|
|
def getPT(self): |
def getPT(self): |
"""pagenums""" |
"""pagenums""" |
di = self.REQUEST.SESSION['dlInfo'] |
di = self.REQUEST.SESSION['dlInfo'] |
Line 736 class zogiLib(Folder):
|
Line 765 class zogiLib(Folder):
|
"""ws+1""" |
"""ws+1""" |
ws = self.getDLParam('ws') |
ws = self.getDLParam('ws') |
try: |
try: |
return int(ws)+1 |
return float(ws)+0.5 |
except: |
except: |
return 2 |
return 1.5 |
|
|
def getSmallerWS(self): |
def getSmallerWS(self): |
"""ws-1""" |
"""ws-1""" |
ws=self.getDLParam('ws') |
ws=self.getDLParam('ws') |
try: |
try: |
return max(int(ws)-1, 1) |
return max(float(ws)-0.5, 1) |
except: |
except: |
return 1 |
return 1 |
|
|
Line 786 class zogiLib(Folder):
|
Line 815 class zogiLib(Folder):
|
return (wy + wh < 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): |
def dl_HMirror(self): |
"""mirror action""" |
"""mirror action""" |
modes = self.REQUEST.SESSION['dlModes'] |
modes = self.REQUEST.SESSION['dlModes'] |
Line 820 class zogiLib(Folder):
|
Line 861 class zogiLib(Folder):
|
wh2 = max(min(wh2, 1), 0) |
wh2 = max(min(wh2, 1), 0) |
wx = max(min(wx, 1), 0) |
wx = max(min(wx, 1), 0) |
wy = max(min(wy, 1), 0) |
wy = max(min(wy, 1), 0) |
self.setDLParam('ww', ww2) |
self.setDLParam('ww', cropf(ww2)) |
self.setDLParam('wh', wh2) |
self.setDLParam('wh', cropf(wh2)) |
self.setDLParam('wx', wx) |
self.setDLParam('wx', cropf(wx)) |
self.setDLParam('wy', wy) |
self.setDLParam('wy', cropf(wy)) |
return self.display() |
return self.display() |
|
|
def dl_ZoomIn(self): |
def dl_ZoomIn(self): |
Line 846 class zogiLib(Folder):
|
Line 887 class zogiLib(Folder):
|
wy += dy * 0.5 * wh |
wy += dy * 0.5 * wh |
wx = max(min(wx, 1), 0) |
wx = max(min(wx, 1), 0) |
wy = max(min(wy, 1), 0) |
wy = max(min(wy, 1), 0) |
self.setDLParam('wx', wx) |
self.setDLParam('wx', cropf(wx)) |
self.setDLParam('wy', wy) |
self.setDLParam('wy', cropf(wy)) |
return self.display() |
return self.display() |
|
|
def dl_MoveLeft(self): |
def dl_MoveLeft(self): |
Line 926 class zogiLib(Folder):
|
Line 967 class zogiLib(Folder):
|
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self) |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self) |
return pt() |
return pt() |
|
|
def changeZogiLib(self,title,digilibBaseUrl, localFileBase, version, basePath, RESPONSE=None): |
def changeZogiLib(self,title,digilibBaseUrl, localFileBase, version, basePath, dlTarget, RESPONSE=None): |
"""change it""" |
"""change it""" |
self.title=title |
self.title=title |
self.digilibBaseUrl=digilibBaseUrl |
self.digilibBaseUrl=digilibBaseUrl |
self.localFileBase=localFileBase |
self.localFileBase=localFileBase |
self.basePath = basePath |
self.basePath = basePath |
self.layout=version |
self.layout=version |
|
if dlTarget: |
|
self.dlTarget = dlTarget |
|
else: |
|
self.dlTarget = "digilib" |
|
|
if RESPONSE is not None: |
if RESPONSE is not None: |
RESPONSE.redirect('manage_main') |
RESPONSE.redirect('manage_main') |
Line 943 def manage_addZogiLibForm(self):
|
Line 988 def manage_addZogiLibForm(self):
|
pt=PageTemplateFile(os.path.join(package_home(globals()), '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",basePath="",RESPONSE=None): |
def manage_addZogiLib(self,id,title,digilibBaseUrl, localFileBase,version="book",basePath="",dlTarget="digilib",RESPONSE=None): |
"""add dgilib""" |
"""add dgilib""" |
newObj=zogiLib(id,title,digilibBaseUrl, localFileBase, version, basePath) |
newObj=zogiLib(id,title,digilibBaseUrl, localFileBase, version, basePath, dlTarget) |
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') |
|
|
|
|
|
class zogiLibPageTemplate(ZopePageTemplate): |
|
"""pageTemplate Objekt""" |
|
meta_type="zogiLib_pageTemplate" |
|
|
|
|
|
## def __init__(self, id, text=None, contentType=None): |
|
## self.id = str(id) |
|
## self.ZBindings_edit(self._default_bindings) |
|
## if text is None: |
|
## text = open(self._default_cont).read() |
|
## self.pt_edit(text, contentType) |
|
|
|
def manage_addZogiLibPageTemplateForm(self): |
|
"""Form for adding""" |
|
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibPageTemplateForm')).__of__(self) |
|
return pt() |
|
|
|
def manage_addZogiLibPageTemplate(self, id='zogiLibMainTemplate', title=None, layout=None, text=None, |
|
REQUEST=None, submit=None): |
|
"Add a Page Template with optional file content." |
|
|
|
id = str(id) |
|
self._setObject(id, zogiLibPageTemplate(id)) |
|
ob = getattr(self, id) |
|
if not layout: layout = "book" |
|
ob.pt_edit(open(os.path.join(package_home(globals()),'zpt/zogiLibMain_%s.zpt'%layout)).read(),None) |
|
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 '' |