[TransWarp] peak.web and forms

Roché Compaan roche at upfrontsystems.co.za
Mon Aug 4 15:49:44 EDT 2003


When I get the time I'm working on web forms for PEAK. I would like to
outline the basic idea and invite some comments before I go ahead with
the implementation. Luckily there are implementations that one can learn
from such as Formulator for Zope2 and Zope3's browser forms. I am keen
to work on a PEAK implementation because of it's UML support and the
possibility to manipulate forms in UML. 

At the moment I have a set of widgets that knows how to render
themselves as HTML eg.:

>>> from widget import *
>>> w = TextWidget()
>>> w.css_class = 'text'
>>> w.size = 10
>>> w.maxlength = 10
>>> print w.render('key', 'Pete')
'<input class="text" name="key" maxlength="10" type="text" value="Pete" size="10"  />'
>>> 
>>> w = ListWidget()
>>> w.items = ['1','2','3']
>>> print w.render('key', '2')
'<select size="5" name="key" >
<option value="1" >1</option>
<option value="2" selected="selected">2</option>
<option value="3" >3</option>
</select>'
>>> 

Before I get to form generation it should be possible to build a
BrowserView in pure python. A BrowserView is a collection of widgets
with a binding to a model.Element. I don't want to call it a
BrowserForm because it does not only render HTML forms - it can also
render non-editable views

A BrowserView introspects the element to supply its widgets with data.
No layout or look and feel is set on a BrowserView - that is the
responsibility of the template rendering the view. Templates will have
access to a set of domlets that knows how to render a BrowserView, maybe
something like:

    <table domlet="browserview:foo">
    <tr define="widget">
    <th domlet="text:title">widget title</th>
    <td domlet="render">rendered widget</td>
    </tr>
    </table>

If a HTML form is submitted your app can call validate on the
BrowserView with the request as parameter to validate all fields. The
validated result can then be applied to the element the BrowserView is
bounded to. If there are validation errors your app can use them to
re-render a template with appropriate error messages. At this point
rendering a widget should show the input last provided by the user - ie.
the form should be sticky.

How does this sound?

-- 
Roché Compaan
Upfront Systems                 http://www.upfrontsystems.co.za



More information about the PEAK mailing list