Kevin Dangoor wrote:
> This is a great bit of input. Between Ronald's CatWalk, Ian Bicking's
> FormEncode ideas, bonono's CRUD interface, Robert Brewer's RESTful
> recipe for CherryPy and our discussions at the sprint, we've got a
> whole bunch of ideas for doing CRUD with TurboGears.
Hopefully we can consolidate some of these things. Part of why I'm just
calling the formencode.fields and formencode.formgen stuff
"experimental" is because I'm not insistant that they have a future in
that form, or that they might fold into another library or have another
library folded into them.
Some features I would find useful in CRUD/form generation, which I've
tried to touch on in these libraries:
* Simple way to override and tweak. In the case of generating
formencode.fields.Field objects, you can poke and rewrite the objects in
an imperative style after the form has been generated. I think it's
relatively hard to pass in sufficient options to modify the generation
itself, except for very specific aspects (like the field names). Old
FormEncode form generation tried this, and it's just messy and annoying.
* Way to unpack a form and use it in a template.
formencode.fields.Layout *doesn't* do this well right now, but it
should. I'd like to be able to do:
<form>
<?python
layout = form.layout
?>
<table>
<tr><td>First Name</td><td>Last Name</td></tr>
<tr>${layout.fname}</tr><td>${layout.lname}</td></tr>
</table>
</form>
And stuff like that, in addition to generating the complete form with
fieldsets and all that.
* Allow fields to add validators. For instance, a secure hidden field
can use the validators.SignedString validator, and just be implemented
as a hidden field. Or a date input validator could unpack dates into a
dictionary of {'year': ..., 'month': ...}, and then unpack them.
* variabledecode is the bomb if you want to make complex forms, in part
because of that unpacking and packing step that can make a bunch of
fields look like a single field to the validator (and to the model
layer), and because it make repeating fields pretty easy to use.
* Decentralized rule building, using generic functions. They are like
adapters and registered views and all that, only they are really easy.
I think they are easier than even a fairly naive ad hoc adaptation
system, and more powerful. You can implement simple
if-this-attribute-is-present systems using a rule that tests with
hasattr(). This can work right down to the column layer. This is what
sqlformgen does (though only for two column types so far -- proof of
concept).
But when it comes down to it, there's a lot of grunt work and
experimental programming that has to go on, to see how this stuff works
in realistic situations. I think false starts should be expected, and
that's fine as long as there's no premature commitment (which makes it a
little questionable for TG 0.9, IMHO -- unless you have a plan for how
deprecated features will work).