"""Demonstrate the Quixote form class. """ import time from quixote.form import Form, StringWidget, PasswordWidget, \ RadiobuttonsWidget, SingleSelectWidget, MultipleSelectWidget, \ CheckboxWidget, FileWidget from quixote.form.css import BASIC_FORM_CSS class Topping: def __init__(self, name, cost): self.name = name self.cost = cost # in cents def __str__(self): return "%s: $%.2f" % (self.name, self.cost/100.) def __repr__(self): return "<%s at %08x: %s>" % (self.__class__.__name__, id(self), self) TOPPINGS = [Topping('cheese', 50), Topping('pepperoni', 110), Topping('green peppers', 75), Topping('mushrooms', 90), Topping('sausage', 100), Topping('anchovies', 30), Topping('onions', 25)] def form_demo(): # build form form = Form(enctype="multipart/form-data") # enctype for file upload form.add(StringWidget, "name", title="Your Name", size=20, required=True) form.add(PasswordWidget, "password", title="Password", size=20, maxlength=20, required=True) form.add(CheckboxWidget, "confirm", title="Are you sure?") form.add(RadiobuttonsWidget, "color", title="Eye color", options=['green', 'blue', 'brown', 'other']) form.add(SingleSelectWidget, "size", title="Size of pizza", value='medium', options=[('tiny', 'Tiny (4")'), ('small', 'Small (6")'), ('medium', 'Medium (10")'), ('large', 'Large (14")'), ('enormous', 'Enormous (18")')], size=1) # select widgets can use any type of object, no just strings form.add(MultipleSelectWidget, "toppings", title="Pizza Toppings", value=[TOPPINGS[0]], options=TOPPINGS, size=5) form.add(FileWidget, "file", title="Your Pizza Specification") form.add_hidden('time', value=time.time()) form.add_submit("go", "Go!") def render [html] (): """
| Name | Type | Value |
|---|---|---|
| %s | ' % widget.get_name() '%s | ' % getattr(value, str('__class__'), type(value)).__name__ '' if value is None: "None" elif isinstance(widget, FileWidget): repr(value) ' (%s bytes %s)' % (len(value.fp.read()), value.get_size()) else: repr(value) ' | ' '