diff --git a/helper.py b/helper.py index 1ebb761..2959ee0 100644 --- a/helper.py +++ b/helper.py @@ -1,56 +1,29 @@ import string,re,time +#clearsilver templates +import neo_cgi +import neo_util # you must import neo_cgi first... +import neo_cs # you must import neo_cgi first... + DEBUG = 1 -def header(): - """return html header""" - data = """ - - - WebGo - - - - - - -

WebGo

- +def cs_render(cs_path,settings = {},hdf_path = ""): """ - return data + render a clearsilver template and return the result. + gets: + - path to clearsilver template + - path to hdf dataset (optional) + - dictionary with settings (optional) + """ + + hdf=neo_util.HDF(hdf_path) + for key in settings.keys(): + hdf.setValue(key,settings[key]) + cs= neo_cs.CS(hdf) + cs.parseFile(cs_path) + return cs.render() -def debug(req,form, optstr = ""): - """ - print various debug infos, e.g. form content. - gets request, util.FieldStorage form, optional extra string. - returns nothing, writes with request.write. - """ - if DEBUG: - if optstr == "": - req.write("Debug: "+str(form.keys())+"
\n") - else: - req.write("Debug: "+optstr+"
\n") -def footer(display_buttons=0): - """return html footer""" - try: - username=form["username"] - sessionid=form["sessionid"] - except: #not logged in - username = "" - sessionid = "" - if display_buttons: - data = """ -
- - - -
""" % (sessionid, username) - else: - data = "" - data += """ - """ - return data # create a unique session id def generate_session_id(): diff --git a/login.py b/login.py index eba3f0f..6ff0847 100755 --- a/login.py +++ b/login.py @@ -4,10 +4,7 @@ from sets import Set as set from cherrypy import cpg from cherrypy.lib import httptools -#clearsilver templates -import neo_cgi -import neo_util # you must import neo_cgi first... -import neo_cs # you must import neo_cgi first... + """ def navigation_bar(req,form): @@ -75,11 +72,7 @@ class Login: """ print welcome message and html form. """ - hdf=neo_util.HDF() - hdf.setValue("Data.Message",message) - cs= neo_cs.CS(hdf) - cs.parseFile("templates/login_form.cs") - return cs.render() + return helper.cs_render("templates/login_form.cs",{"Data.Message":message}) def process_form(self,username,password): """ diff --git a/main.py b/main.py index 8b4edeb..dbee338 100755 --- a/main.py +++ b/main.py @@ -10,10 +10,7 @@ import neo_cs # you must import neo_cgi first... class WebGoSite: def index(self): - hdf=neo_util.HDF() - cs= neo_cs.CS(hdf) - cs.parseFile("templates/main.cs") - return cs.render() + return helper.cs_render("templates/main.cs") index.exposed = True