On 13 November 2001, Jeff Rush said: > Is there an example of forms/widget usage anywhere? I've > wrestled with the source code and can't get it to do > anything but response 500. Try the attached -- this is one of the PTL modules from SPLAT!, a bug database I wrote to 1) showcase Quixote, 2) play with/learn about Berkeley DB, and 3) track the MEMS Exchange's bugs. So far #2 and #3 are goiing swimmingly, but I have yet to release SPLAT!, so #1 is not quite there yet. Sigh. Here's how it works: * _q_index() generates the bug index page, URL "/bugs" * two of the links from the bug index page are "/bugs/display" and "/bugs/filter", implemented by the display() and filter() templates in this module * display() calls gen_display_widgets() to create the widgets used in a form that allows the user to customize the bug index by changing how bugs are sorted and grouped. Those widgets are saved in the session object, because we're going to need them again when we process the form. * display() then creates a form, where much of the HTML is generated by calling 'render()' on the various widget objects created by gen_display_widgets() * the form is handled by the "/bugs/set_display" URL, implemented by the set_display() template. First thing it does is pull the widgets out of the session object, and then it calls parse() on each widget to get the widget value out. Then it tells the SPLAT! Preferences object the user's preferences (taken from the form value); this is used by _q_index(), next time we generate the bug index page. * finally, set_display() redirects to "/bugs" (URL_PREFIX), to show a new (differently sorted/group) bug index filter()/gen_filter_widgets()/set_filter() work similarly. There is certainly more than one way to do it; there are various minor weaknesses in this scheme, which I leave as an exercise to the reader to work out. (Hint: what happens if you try to access "/bugs/set_display" in a brand-new SPLAT! session?) Also, this doesn't use the Form class at all, because 1) I wanted to experiment with the Widgets on their own, and 2) I think Form is overkill here. I could be wrong; Form buys you a hell of a lot of useful stuff. The Widget class hierarchy does too. Together, they're a very powerful and useful combination. > The traceback complains about > a call to set_body(output) where output is not a string > and not a None either. Odd. I don't recall seeing that. If you keep getting it, please supply a full traceback. And if you figure out what you were doing wrong that caused such an obscure error, let us know; we'll try to make the error more obvious. (That's assuming this is your mistake... you might well have hit a bug!) Greg -- Greg Ward - software developer gward@mems-exchange.org MEMS Exchange http://www.mems-exchange.org