Home - Python - CGI scripting and MySQL
#! /usr/local/bin/python
#
# html.py - routines for the printing of HTML widgets and forms
#
def par():
" Start a new HTML paragraph"
print "<p>"
def header (title):
" Print the header block for a cgi-generated web page"
print "Content-type: text/html"
print
print '<HTML>'
print '<META NAME=AUTHOR CONTENT="Boudewijn Rempt">'
print '<META NAME=GENERATOR CONTENT="npc">'
print '<TITLE>'
print title
print '</TITLE>'
def image (image):
print "<p align=center>"
print "<img src='" + image + "' align=center>"
print "<p align=left>"
def body():
" print a standard sequence for the opening of a body"
print '<BODY TEXT="#000000" BGCOLOR="#FFEBCD" LINK="#2E8B57" VLINK="#008B8B" ALINK="#DC143C">'
def coda_body():
" close the body "
print "<hr>"
par()
print "Optimized for Lynx"
print "<em>© Copyright 1999 Boudewijn Rempt.</em>"
print "</body>"
print "</html>"
def form (action):
print '<form action="' + str(action) + '" method="post">'
def coda_form():
print '</form>'
def hidden (id, value):
print
print "<input type='hidden', name='" + str(id) + "' value='" + str(value) + "'>"
def textbox (id, lable, text, size):
if size > 10:
print "<p>", lable, '<input type="text", size=' + str(size) + ' value="' + str(text) + '" name="' + str(id) + '">', '</p>'
def chkbox (id, lable, value):
print lable
print '<input type=checkbox name=' + str(id) + ' value=' + str(value)
if value == 'J' or value == 'Y' or value == 'j' or value == 'y':
print ' checked'
print '>'
def radio (id, lable, tbl, default):
par
print lable
for row in tbl:
par()
if str(row[0]) == str(default):
print '<input type=radio checked name="' + str(id) + '" value="' + str(row[0]) + '">' + str(row[1])
else:
print '<input type=radio name="' + str(id) + '" value="' + str(row[0]) + '">' + str(row[1])
def combobox (id, lable, tbl, rows, default):
print lable
print "<select name=" + str(id) + " size = " + str(rows) + ">"
for row in tbl:
if str(row[0])==str(default):
print "<option selected value=" + str(row[0]) + ">" + str(row[1])
else:
print "<option value=" + str(row[0]) + ">" + str(row[1] )
print "</select>"
def button (id, lable):
print '<input type="submit" value="' + str(lable) + '" name="' + str(id) + '">'
def head (level, title):
print "<h" + str(level) + " align=center>" + str(title) + "</h" + str(level) + ">"
def textarea (id, lable, text, rows, cols):
par;
print lable
print '<textarea name="' + str(id) + '" rows=' + str(rows),' cols=' + str(cols) + '>' + str(text) + '</textarea>'
print "</p>"
def txt (text):
par
print text
def test():
header ("dinges")
body ()
head (1,'Eerste niveau')
form ('test')
par
radio('test','testlbl',((1,'a'),(2,'b')),2)
par
combobox ('cmb','cmblbl',((1,'eerste optie'),(2,'tweede optie')), 0, 2)
coda_form()
coda_body()
Changes
© 2000 Boudewijn Rempt