added a small function for using clearsilver.
This commit is contained in:
parent
025f4824fb
commit
34420b0598
3 changed files with 22 additions and 59 deletions
65
helper.py
65
helper.py
|
@ -1,56 +1,29 @@
|
||||||
import string,re,time
|
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
|
DEBUG = 1
|
||||||
|
|
||||||
def header():
|
def cs_render(cs_path,settings = {},hdf_path = ""):
|
||||||
"""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>
|
|
||||||
"""
|
"""
|
||||||
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
|
# create a unique session id
|
||||||
def generate_session_id():
|
def generate_session_id():
|
||||||
|
|
11
login.py
11
login.py
|
@ -4,10 +4,7 @@ from sets import Set as set
|
||||||
from cherrypy import cpg
|
from cherrypy import cpg
|
||||||
from cherrypy.lib import httptools
|
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):
|
def navigation_bar(req,form):
|
||||||
|
@ -75,11 +72,7 @@ class Login:
|
||||||
"""
|
"""
|
||||||
print welcome message and html form.
|
print welcome message and html form.
|
||||||
"""
|
"""
|
||||||
hdf=neo_util.HDF()
|
return helper.cs_render("templates/login_form.cs",{"Data.Message":message})
|
||||||
hdf.setValue("Data.Message",message)
|
|
||||||
cs= neo_cs.CS(hdf)
|
|
||||||
cs.parseFile("templates/login_form.cs")
|
|
||||||
return cs.render()
|
|
||||||
|
|
||||||
def process_form(self,username,password):
|
def process_form(self,username,password):
|
||||||
"""
|
"""
|
||||||
|
|
5
main.py
5
main.py
|
@ -10,10 +10,7 @@ import neo_cs # you must import neo_cgi first...
|
||||||
|
|
||||||
class WebGoSite:
|
class WebGoSite:
|
||||||
def index(self):
|
def index(self):
|
||||||
hdf=neo_util.HDF()
|
return helper.cs_render("templates/main.cs")
|
||||||
cs= neo_cs.CS(hdf)
|
|
||||||
cs.parseFile("templates/main.cs")
|
|
||||||
return cs.render()
|
|
||||||
|
|
||||||
index.exposed = True
|
index.exposed = True
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue