cryptonas-branches/pythonrewrite/bin2/CryptoBoxWebserverRender.py
lars 528652afcb minor language fixes
one unittest fixed
settings for webserver improved
somme RFCs and TODOs added
2006-09-05 15:03:16 +00:00

42 lines
1.6 KiB
Python

import os
try:
import neo_cgi, neo_util, neo_cs
except ImportError:
raise ImportError("could not import clearsilver modules! Try apt-get install python-clearsilver.")
class CryptoBoxWebserverRender:
'''renders the site with clearsilver template and languagefile
'''
def render(self, website):
'''renders from clearsilver templates and returns the resulting html
Gets a dictionary with all settings, nessessary for rendering.
In fact the dictionary is a copy of the CryptoBoxWerbserverSite
object, that calls this render method. This might be bloat but
this way the render method has always a complete, actual set of values.
'''
website.log.info("rendering site: "+website.settings["Data.Action"])
cs_path = website.cbxPrefs["Locations"]["TemplateDir"]+"/main.cs"
if not os.access(cs_path, os.R_OK):
website.log.error("Couldn't read cs file: %s" % cs_path)
return "Couldn't read cs file: %s" % cs_path
#hdf_path = website.cbxPrefs["Locations"]["LangDir"]+"/"+website.cbxPrefs["WebSettings"]["Language"]+".hdf"
# use the user selected language ('Settings.Language') instead of the configured
hdf_path = website.cbxPrefs["Locations"]["LangDir"]+"/"+website.settings["Settings.Language"]+".hdf"
if not os.access(hdf_path, os.R_OK):
website.log.error("Couldn't read hdf file: %s" % hdf_path)
return "Couldn't read hdf file: %s" % hdf_path
hdf = neo_util.HDF()
hdf.readFile(hdf_path)
website.log.debug(website.settings)
for key in website.settings.keys():
hdf.setValue(key,str(website.settings[key]))
cs = neo_cs.CS(hdf)
cs.parseFile(cs_path)
return cs.render()