--- zogiLib/zogiLib.py 2004/06/22 13:35:50 1.28 +++ zogiLib/zogiLib.py 2004/06/25 16:59:45 1.30 @@ -15,7 +15,12 @@ import urllib import types from Globals import package_home -ZOGIVERSION = "0.9.4 ROC:22.6.2004" +ZOGIVERSION = "0.9.5 ROC:25.6.2004" + +def cropf(f): + """returns a float with reduced precision""" + return float(int(f * 10000)/10000.0) + def sendFile(self, filename, type): """sends an object or a local file (in the product) as response""" @@ -57,49 +62,6 @@ def browserCheck(self): return bt -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) - - - 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): """einzelnes Image""" @@ -722,7 +684,7 @@ class zogiLib(Folder): # assemble query string ret = "" for param in dlParams.keys(): - if dlParams[param] == None: continue + if dlParams[param] is None: continue val = str(dlParams[param]) if val != "": ret += param + "=" + val + "&" @@ -756,6 +718,17 @@ class zogiLib(Folder): 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() @@ -883,10 +856,10 @@ class zogiLib(Folder): 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) + self.setDLParam('ww', cropf(ww2)) + self.setDLParam('wh', cropf(wh2)) + self.setDLParam('wx', cropf(wx)) + self.setDLParam('wy', cropf(wy)) return self.display() def dl_ZoomIn(self): @@ -909,8 +882,8 @@ class zogiLib(Folder): 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) + self.setDLParam('wx', cropf(wx)) + self.setDLParam('wy', cropf(wy)) return self.display() def dl_MoveLeft(self): @@ -1016,3 +989,41 @@ def manage_addZogiLib(self,id,title,digi self.Destination()._setObject(id,newObj) if RESPONSE is not None: 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 ''