Annotation of zogiLib/zogiLib.py, revision 1.1
1.1 ! dwinter 1: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
! 2: from Products.PageTemplates.PageTemplate import PageTemplate
! 3: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
! 4:
! 5:
! 6: import xml.dom.minidom
! 7: from OFS.Folder import Folder
! 8: from xml_helpers import getText
! 9: import os
! 10: import re
! 11: import string
! 12: import urllib
! 13: from Globals import package_home
! 14:
! 15: def getString(self,key,default=''):
! 16: try:
! 17: return self.REQUEST[key]
! 18: except:
! 19: return default
! 20:
! 21:
! 22: class zogiLib_navTemplate(ZopePageTemplate):
! 23: """pageTemplate Objekt"""
! 24: meta_type="zogiLib_navTemplate"
! 25:
! 26: _default_content_fn = os.path.join(package_home(globals()),
! 27: 'zpt/zogiLib_NavTemplateDefault.zpt')
! 28:
! 29: manage_options=ZopePageTemplate.manage_options+(
! 30: {'label':'Copy to Filesystem','action':'copyContent'},
! 31: )
! 32:
! 33: def getPath(self):
! 34: """get path"""
! 35: return getPath(self,'thumbtemplate.templ')
! 36:
! 37: ## def changeECHO_pageTemplateWeightForm(self):
! 38: ## """change"""
! 39: ## pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_pageTemplateWeight.zpt').__of__(self)
! 40: ## return pt()
! 41:
! 42: ## def changeECHO_pageTemplateWeight(self,weight,content_type,RESPONSE=None):
! 43: ## """change"""
! 44: ## self.weight=weight
! 45: ## self.content_type=content_type
! 46:
! 47: ## if RESPONSE is not None:
! 48: ## RESPONSE.redirect('manage_main')
! 49:
! 50:
! 51: def copyContent(self):
! 52: """copycontent to path"""
! 53:
! 54: return "copied to:"+copyContent(self,'thumbtemplate.templ')
! 55:
! 56:
! 57: def manage_addZogiLib_NavTemplateForm(self):
! 58: """Form for adding"""
! 59: pt=PageTemplateFile('Products/ECHO_content/zpt/AddZogilib_NavTemplate.zpt').__of__(self)
! 60: return pt()
! 61:
! 62:
! 63:
! 64:
! 65: def manage_addZogiLib_NavTemplate(self, id,title=None, text=None,
! 66: REQUEST=None, submit=None):
! 67: "Add a Page Template with optional file content."
! 68:
! 69:
! 70: id = str(id)
! 71: if REQUEST is None:
! 72: self._setObject(id, zogilib_NavTemplate(id, text))
! 73: ob = getattr(self, id)
! 74:
! 75: if title:
! 76: ob.pt_setTitle(title)
! 77: return ob
! 78: else:
! 79: file = REQUEST.form.get('file')
! 80: headers = getattr(file, 'headers', None)
! 81: if headers is None or not file.filename:
! 82: zpt = zogilib_NavTemplate(id)
! 83: else:
! 84: zpt = zogilib_NavTemplate(id, file, headers.get('content_type'))
! 85:
! 86: self._setObject(id, zpt)
! 87: ob = getattr(self, id)
! 88:
! 89:
! 90: try:
! 91: u = self.DestinationURL()
! 92: except AttributeError:
! 93: u = REQUEST['URL1']
! 94:
! 95: if submit == " Add and Edit ":
! 96: u = "%s/%s" % (u, quote(id))
! 97: REQUEST.RESPONSE.redirect(u+'/manage_main')
! 98: return ''
! 99:
! 100: def readNavTemp(fileName):
! 101: """navtemp"""
! 102: print "HI reading",fileName
! 103:
! 104: if os.path.exists(fileName+"/index.meta"):
! 105: dom=xml.dom.minidom.parse(fileName+"/index.meta")
! 106: else:
! 107: return None
! 108:
! 109: print "dom",dom
! 110: try:
! 111: navTag=getText(dom.getElementsByTagName('zogilibtemplate')[0].childNodes)
! 112: except:
! 113: navTag=None
! 114: return navTag
! 115:
! 116:
! 117: class zogiLib(Folder):
! 118: """StandardElement"""
! 119:
! 120: meta_type="zogiLib"
! 121:
! 122: def generateImageFolder(self):
! 123: """images ablegen"""
! 124: self.manage_addFolder('images')
! 125: for image in os.listdir("../lib/python/Products/zogiLib/images"):
! 126: fn=file("../lib/python/Products/zogiLib/images/"+image)
! 127: print fn
! 128: self.images.manage_addImage(image,fn)
! 129:
! 130:
! 131: def __init__(self, id,title,zogilibBaseUrl, localFileBase):
! 132: """init"""
! 133:
! 134: self.id=id
! 135: self.title=title
! 136: self.zogilibBaseUrl=zogilibBaseUrl
! 137: self.localFileBase=localFileBase
! 138: self._setObject('topTemplate',zogiLib_navTemplate(id='topTemplate'))
! 139: self.generateImageFolder()
! 140:
! 141:
! 142: manage_options = Folder.manage_options+(
! 143: {'label':'Main Config','action':'changeZogiLibForm'},
! 144: )
! 145:
! 146: def navigation_js(self):
! 147: """Javascript"""
! 148:
! 149: return file("../lib/python/Products/zogiLib/js/navigation.js").read()
! 150:
! 151:
! 152: def generateTopJavaScript(self):
! 153: """generate script"""
! 154: ret="""var baseUrl = '%s'; """% self.REQUEST['URL0']
! 155: ret+="""newParameter('fn', '%s', '', 1);
! 156: newParameter('pn', '%s', '1', 1);
! 157: newParameter('ws', '%s', '1.0', 1);
! 158: newParameter('mo', '%s', '', 1);
! 159: newParameter('mk', '%s', '', 3);
! 160: newParameter('wx', '%s', '0.0', 2);
! 161: newParameter('wy', '%s', '0.0', 2);
! 162: newParameter('ww', '%s', '1.0', 2);
! 163: newParameter('wh', '%s', '1.0', 2);
! 164: newParameter('pt', '%s', '%s', 9);
! 165: newParameter('brgt', '%s', '0.0', 1);
! 166: newParameter('cont', '%s', '0.0', 1);
! 167: newParameter('rot', '%s', '0.0', 1);
! 168: newParameter('rgba', '%s', '', 1);
! 169: newParameter('rgbm', '%s', '', 1);
! 170: newParameter('ddpix', '%s', '', 9);
! 171: newParameter('ddpiy', '%s', '', 9);"""%(getString(self,'fn'),
! 172: getString(self,'pn',1),
! 173: getString(self,'ws',1.0),
! 174: getString(self,'mo',''),
! 175: getString(self,'mk',''),
! 176: getString(self,'wx',0.0),
! 177: getString(self,'wy',0.0),
! 178: getString(self,'ww',1.0),
! 179: getString(self,'wh',1.0),
! 180: getString(self,'pt',100),getString(self,'pt',100),
! 181: getString(self,'brgt',0.0),
! 182: getString(self,'cont',0.0),
! 183: getString(self,'rot',0.0),
! 184: getString(self,'rgba','0/0/0'),
! 185: getString(self,'rgbm','0/0/0'),
! 186: getString(self,'ddpix',0.0),
! 187: getString(self,'ddpiy',0.0)
! 188: )
! 189:
! 190: ret+="""
! 191:
! 192: var wwidth, wheight;
! 193: if (self.innerHeight) // all except Explorer
! 194: {
! 195: wwidth = self.innerWidth;
! 196: wheight = self.innerHeight;
! 197: }
! 198: else if (document.documentElement && document.documentElement.clientHeight)
! 199: // Explorer 6 Strict Mode
! 200: {
! 201: wwidth = document.documentElement.clientWidth;
! 202: wheight = document.documentElement.clientHeight;
! 203: }
! 204: else if (document.body) // other Explorers
! 205: {
! 206: wwidth = document.body.clientWidth;
! 207: wheight = document.body.clientHeight;
! 208: }
! 209:
! 210:
! 211: """
! 212: return ret
! 213:
! 214:
! 215:
! 216:
! 217:
! 218:
! 219:
! 220: def generateScalerImg(self,requestString):
! 221: """generate Scaler Tag"""
! 222: retStr=self.zogilibBaseUrl+requestString
! 223: jS="""<script type="text/javascript">
! 224: document.write("<img id=\\\"pic\\\" src=\\\"%s&dw="+wwidth+"&dh="+wheight+"\\\"/>")</script>"""%retStr
! 225: return jS
! 226:
! 227: def changeZogiLibForm(self):
! 228: """Main configuration"""
! 229: pt=PageTemplateFile('Products/zogiLib/zpt/changeZogiLibForm.zpt').__of__(self)
! 230: return pt()
! 231:
! 232: def changeZogiLib(self,title,zogilibBaseUrl, localFileBase,RESPONSE=None):
! 233: """change it"""
! 234: self.title=title
! 235: self.zogilibBaseUrl=zogilibBaseUrl
! 236: self.localFileBase=localFileBase
! 237:
! 238: if RESPONSE is not None:
! 239: RESPONSE.redirect('manage_main')
! 240:
! 241:
! 242: def nav_html(self,fileName):
! 243: """navigations frame"""
! 244:
! 245: # suche nach index.meta mit zogilib thumb info
! 246:
! 247: templ=readNavTemp(self.localFileBase+"/"+fileName)
! 248: if not templ:
! 249: templ=readNavTemp(self.localFileBase+"/"+fileName.split("/")[0])
! 250: if not templ:
! 251: return self.topTemplate.document_src()
! 252:
! 253: return urllib.urlopen(templ).read()
! 254:
! 255:
! 256: def index_html(self):
! 257: """main action"""
! 258:
! 259:
! 260: pt=PageTemplateFile('Products/zogiLib/zpt/zogiLibMain.zpt').__of__(self)
! 261: return pt()
! 262:
! 263: def storeQuery(self):
! 264: """storeQuery in session"""
! 265: self.REQUEST.SESSION['query']={}
! 266: for fm in self.REQUEST.form.keys():
! 267: self.REQUEST.SESSION['query'][fm]=self.REQUEST.form[fm]
! 268:
! 269: def setParam(self,pn=None,ws=None,rot=None):
! 270: """gotopage"""
! 271: ret=""
! 272:
! 273: if pn:
! 274: self.REQUEST.SESSION['query']['pn']=pn
! 275:
! 276: if ws:
! 277: self.REQUEST.SESSION['query']['ws']=ws
! 278:
! 279: if rot:
! 280: self.REQUEST.SESSION['query']['rot']=rot
! 281:
! 282: for param in self.REQUEST.SESSION['query'].keys():
! 283:
! 284: ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&"
! 285:
! 286: self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret)
! 287:
! 288: def mirrorPage(self,mi):
! 289: """mirror"""
! 290: ret=""
! 291: try:
! 292: splitted=self.REQUEST.SESSION['query']['mo'].split(',')
! 293: except:
! 294: splitted=[]
! 295:
! 296: if mi=="h":
! 297:
! 298: if 'hmir' in splitted:
! 299: splitted.remove('hmir')
! 300: else:
! 301: splitted.append('hmir')
! 302:
! 303: if mi=="v":
! 304:
! 305: if 'vmir' in splitted:
! 306: splitted.remove('vmir')
! 307: else:
! 308: splitted.append('vmir')
! 309:
! 310:
! 311: self.REQUEST.SESSION['query']['mo']=string.join(splitted,",")
! 312:
! 313:
! 314:
! 315:
! 316: for param in self.REQUEST.SESSION['query'].keys():
! 317:
! 318: ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&"
! 319:
! 320: self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret)
! 321:
! 322: def decode(self,strR):
! 323: """decode &"""
! 324: print re.sub('\&','\&',strR)
! 325: return re.sub('\&','\&',strR)
! 326:
! 327: def wholePage(self):
! 328: """zoom out"""
! 329: ret=""
! 330:
! 331: self.REQUEST.SESSION['query']['ww']=1
! 332: self.REQUEST.SESSION['query']['wh']=1
! 333: self.REQUEST.SESSION['query']['wx']=0
! 334: self.REQUEST.SESSION['query']['wy']=0
! 335:
! 336: for param in self.REQUEST.SESSION['query'].keys():
! 337:
! 338: ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&"
! 339:
! 340: self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret)
! 341:
! 342: def prevPage(self,pn=None):
! 343: """next page"""
! 344: ret=""
! 345:
! 346: if pn and pn>0:
! 347: pn=str(int(pn)-1)
! 348:
! 349:
! 350: self.REQUEST.form['pn']=pn
! 351: print "hi",self.REQUEST.form.keys()
! 352: for param in self.REQUEST.form.keys():
! 353: print param
! 354: ret+=param+"="+str(self.REQUEST.form[param])+"&"
! 355:
! 356: self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret)
! 357:
! 358:
! 359: def nextPage(self,pn=None):
! 360: """next page"""
! 361: ret=""
! 362:
! 363: try:
! 364: pn=str(int(pn)+1)
! 365: except:
! 366: pn=str(2)
! 367:
! 368: self.REQUEST.form['pn']=pn
! 369: print "hi",self.REQUEST.form.keys()
! 370: for param in self.REQUEST.form.keys():
! 371: print param
! 372: ret+=param+"="+str(self.REQUEST.form[param])+"&"
! 373:
! 374: self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret)
! 375:
! 376:
! 377: def manage_addZogiLibForm(self):
! 378: """interface for adding zogilib"""
! 379: pt=PageTemplateFile('Products/zogiLib/zpt/addZogiLibForm').__of__(self)
! 380: return pt()
! 381:
! 382: def manage_addZogiLib(self,id,title,zogilibBaseUrl, localFileBase,RESPONSE=None):
! 383: """add dgilib"""
! 384: newObj=zogiLib(id,title,zogilibBaseUrl, localFileBase)
! 385: self.Destination()._setObject(id,newObj)
! 386: if RESPONSE is not None:
! 387: RESPONSE.redirect('manage_main')
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>