durusmail: quixote-users: Customization of Quixote2 "Form" appearence
Customization of Quixote2 "Form" appearence
2008-04-04
2008-04-04
2008-04-06
2008-04-06
Re: Customization of Quixote2 "Form" appearence
2008-04-05
2008-04-05
2008-04-07
Customization of Quixote2 "Form" appearence
Mike Orr
2008-04-06
On Sat, Apr 5, 2008 at 11:12 PM, Ian Forbes  wrote:
>  How do other frameworks handle forms? Is there anything to be learnt
>  from the form code in QP. Is there anything equivalent in competing
>  frameworks like Tubogears and Pylons?

Pylons is lower level.  You write the form yourself and use
FormEncode/htmlfill to validate it.  Think of it as Quixote's
validators without the rendering part.  Also, the custom is to have a
separate submit method from the form-drawing method, with an @validate
decorator on the submit method.  If the validators fail, the decorator
calls the form-drawing method, then runs the HTML through htmlfill to
insert the error messages and existing form values.  It sounds more
complicated but it's also more flexible if you have custom form HTML.

TurboGears uses ToscaWidgets with FormEncode/htmlfill.  ToscaWidgets
is similar to the rendering part of quixote.form, with mini-templates
to render each widget and to place it in the form.  TW can also
remember Javscript/CSS dependencies and inject the needed links in the
 of the page.  ToscaWidgets is a general HTML/Javascript/CSS
bundler for standalone chunks, not just for forms.  The problem with
ToscaWidgets is it's poorly documented, which has limited its
acceptance outside TurboGears.

Django has its own form library 'newforms'.  It does both rendering
and validation.  I don't know how close the implementation is to
quixote.form.

I like the control flow of quixote.form and the widget encapsulation,
though in some apps I've had to bypass the form rendering and place
the widgets manually, or bypass the entire rendering and write the
forms manually.  This works fine with quixote.form; it will continue
to validate.  For composite widgets I make the main .value a tuple of
the subwidget values, and have the constructor call an
..create_children method that instantiates the subwidgets as 'self'
attributes.  The ._parse method then delegates to the subwidgets to
get the discrete values, form the tuple, and set the composite error
message.  The composite's .render method can render all the subwidgets
itself or delegate to them and plug the results into its own template.

FormEncode/htmlfill:  http://formencode.org/

ToscaWidgets:  http://toscawidgets.org/

http://wiki.pylonshq.com/display/toscawidgets/Using+twForms+with+Pylons.+Part+1

Django newforms:  http://www.djangoproject.com/documentation/newforms/

--
Mike Orr 
reply