On 11/11/05, Levi <[EMAIL PROTECTED]> wrote:
> Kevin Dangoor wrote:
> >
> > Using Widgets
> > -------------
> >
> > Here's an example from the "first look":
> > widgets.TextField("age", default=0, validator=validators.Int())
>
> This might seem strange, but first thing that jumps out about this
> example is the "style" doesn't feel right. Or at least it doesn't feel
> consistent with sqlobject. Maybe something more like this:
>
> class MyForm (widgets.Form):
> age = widgets.TextField(
> default=0,
> validators=(
> validators.Int(min=4, max=12),
> validators.Required())
The example that you've put together here actually makes me think even
more that it should be the way it is now. Here's what I mean:
Form elements have "names". This is not for Python's sake: this is
part of the HTML that needs to be generated...
<input type="text" name="${name}">
My example didn't really have to have a form. You could take that
widget and plunk it straight into your Kid, if you wished.
Now, the declarative style, through a metaclass, *could* set the name
on the widgets and keep track of ordering. But, is it really that much
better than
form = TableForm(TextField('age'), TextField('name'))
And, I really like the fact that I have an instance here and not a
class. I still think that the form I've defined is a *thing* not a
*kind of thing*, which implies an instance and not a class.
Unfortunately, one way is not provably better than the other (emacs
vs. vi, anyone?). If people really prefer the declarative style, it
can certainly be made to work. It just feels less like "normal" OO
code to me.
(By the way, the way you define SQLObjects *is* normal OO, because in
those cases you are defining classes and not instances. FormEncode's
schemas are where the line gets blurred.)
> I still need to read about formencode, so I'm not sure if my list of
> validators even makes sense. Now that I think of it, composition (ala
> composite pattern) would probably beat lists for testability anyway.
FormEncode does provide ways to combine validators.
> > The validator is important because you can have something like a
> > select widget that needs to translate between IDs and names. Or, you
> > could have a repeating form element widget that takes in a collection
> > of data as its value.
>
> Hmm. I really need to go read about formencode.... (going now :)
It's a nice package... good thing to build on.
Kevin