added a small function for using clearsilver.

This commit is contained in:
phear 2005-12-11 19:56:02 +00:00
parent 025f4824fb
commit 34420b0598
3 changed files with 22 additions and 59 deletions

View file

@ -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 = """
<html>
<head>
<title>WebGo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<link rel="stylesheet" media="screen" href="/default.css" type="text/css" />
</head>
<h1> WebGo </h1>
<body>
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())+"<br>\n")
else:
req.write("Debug: "+optstr+"<br>\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 = """
<form method="post">
<input type="hidden" name="sessionid" value="%s">
<input type="hidden" name="username" value="%s">
<input type=submit class="submit" name="logout" value="logout">
</form>""" % (sessionid, username)
else:
data = ""
data += """</body></html>
"""
return data
# create a unique session id
def generate_session_id():

View file

@ -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):
"""

View file

@ -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