from WebKit.Page import Page from FunFormKit.Form import FormServlet, FormDefinition from FunFormKit import Field import random formDef = FormDefinition("CCWinner", [Field.TextField("randmax", maxLength=5, size=3, description="Upper border of random number wanted"), Field.SubmitButton("submit", description="Randomize me!", methodToInvoke="randomize_me")], ) class CCWinner(Page, FormServlet): def __init__(self): Page.__init__(self) FormServlet.__init__(self, [formDef]) def title(self): return "A random example.." def randomize_me(self, fields): maxrandnr = int(fields['randmax']) randnr = random.randrange(0, maxrandnr) self.write("Your random number between 0 and %d is %d
" % (maxrandnr, randnr)) def writeContent(self): submitted, data = self.processForm() rf = self.renderableForm() self.write(rf.htFormTable(bgcolor="#ddddff"))