inheritance part2

This commit is contained in:
age 2006-08-20 16:33:52 +00:00
parent 447958e685
commit c14d5cfbd7
2 changed files with 80 additions and 55 deletions

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python
import os,sys
import CryptoBox
try:
import cherrypy
except:
@ -11,38 +12,28 @@ try:
except:
print "could not import clearsilver modules! Try apt-get install python-clearsilver."
class clearsilver:
def __init__(self):
pass
def render(self,cs_path,settings = {},hdf_path = ""):
"""
render a clearsilver template and return the result.
gets:
- path to clearsilver template
- dictionary with settings (optional)
- path to hdf dataset (optional)
"""
hdf=neo_util.HDF()
if hdf_path != "":
hdf.readFile(hdf_path)
for key in settings.keys():
hdf.setValue(key,str(settings[key]))
cs= neo_cs.CS(hdf)
cs.parseFile(cs_path)
return cs.render()
class CryptoBoxSite:
'''this is the motherclass of all cbx sites
class CryptoBoxSite(CryptoBox.CryptoBoxProps):
put the stuff in her, that every site will need access to'''
def print_foo(self):
'''a stupid demo method'''
self.cbx_inheritance_test()
print "fooooooooooooobaaaaaaaaaaaaaaaaaaaar"
class CryptoBoxSites(CryptoBox.CryptoBoxProps, CryptoBoxSite):
'''
'''
def index(self,action="show_status",page="",weblang="",device="", type=""):
#PROPOSAL:
#cherrypy could create nice paths like http://crypto.box/doc/,
#but that would require an update of the links in the templates.
#is the style worth it?
#is the style worth it? - yes :)
self.print_foo() # this method was inherited by CryptoBoxSite, be careful not to overwrite methods unwanted..
#sanitize input
page = self.sanitize_input(page)
@ -150,7 +141,7 @@ class CryptoBoxSite(CryptoBox.CryptoBoxProps):
#go render stuff
cs = clearsilver()
cs = CryptoBoxRenderSite()
content = cs.render(TemplateDir+"/main.cs",settings,LangDir+"/"+Language+".hdf")
return content
@ -160,19 +151,40 @@ class CryptoBoxSite(CryptoBox.CryptoBoxProps):
return data
index.exposed = True
class CryptoBoxRenderSite:
def render(self,cs_path,settings = {},hdf_path = ""):
"""
render a clearsilver template and return the result.
gets:
- path to clearsilver template
- dictionary with settings (optional)
- path to hdf dataset (optional)
"""
hdf=neo_util.HDF()
if hdf_path != "":
hdf.readFile(hdf_path)
for key in settings.keys():
hdf.setValue(key,str(settings[key]))
cs= neo_cs.CS(hdf)
cs.parseFile(cs_path)
return cs.render()
##############################################################
cherrypy.root = CryptoBoxSite()
#expose static content:
#I currently have no idea how to cleanly extract the stylesheet path from
#the config object without an extra CryptoBox.CryptoBoxProps instance.
#perhaps put config handling into a seperate class in CryptoBox.py?
cherrypy.config.configMap.update(
{
"/cryptobox.css": {
"staticFilter.on" : True,
"staticFilter.file": os.path.abspath("../www-data/cryptobox.css" )
if __name__ == "__main__":
cherrypy.root = CryptoBoxSites()
#expose static content:
#I currently have no idea how to cleanly extract the stylesheet path from
#the config object without an extra CryptoBox.CryptoBoxProps instance.
#perhaps put config handling into a seperate class in CryptoBox.py?
cherrypy.config.configMap.update(
{
"/cryptobox.css": {
"staticFilter.on" : True,
"staticFilter.file": os.path.abspath("../www-data/cryptobox.css" )
}
})
cherrypy.server.start()
cherrypy.server.start()