#!/usr/bin/python2.4 import cgi import cgitb; cgitb.enable() import random from htmltmpl import TemplateManager, TemplateProcessor def main(): form = cgi.FieldStorage() media = Media(form) media.ui() class Media: def __init__(self, form): self.media = form.getvalue("media", "all") self.colours = ['green', 'blue', 'red', 'yellow'] self.media_type = ['all', 'aural', 'braille', 'handheld', 'print', 'projection', 'screen', 'tty', 'tv', 'embossed'] def ui(self): #print "Content-Type: text/html" print "Content-Type: application/xhtml+xml" print template = TemplateManager().prepare("basic.tmpl") tproc = TemplateProcessor() tproc.set("colour", random.choice(self.colours)) tproc.set("media", self.media) tproc.set("Media", [{'type': i} for i in self.media_type]) print tproc.process(template) if __name__ == "__main__": main()