[Twisted-web] Rendering forms from HTML templates using freeform

Donovan Preston twisted-web@twistedmatrix.com
Mon, 15 Dec 2003 14:02:30 -0500


On Dec 15, 2003, at 1:12 PM, Gavrie Philipson wrote:

> Hi,
>
> Is it possible to render freeform forms using HTML templates instead 
> of relying on the default freeform behavior?
>
> I need precise control of the layout of the forms -- using the default 
> list of boxes is not sufficient. Of course I can modify the 
> stylesheet, but I'm really looking for a way to design the form's 
> layout totally separately from the code.

Freeform will eventually use patterns, slots and keys declared in the 
template to assist it with the form layout/rendering process. Until 
then, there is nothing stopping you from producing your own forms. The 
freeform post location scheme is fairly simple to figure out, and the 
method argument names make a straight translation to input element 
names for the most part.

If you have a configurable object (an instance of a class which 
implements IConfigurable or declares it implements one or more 
subclasses of TypedInterface) which lives at the URL:

/foo/bar

You can call methods on bar by posting to:

/foo/bar/freeform_post:methodName

The input names are the same names as the parameter names to the method 
methodName. So if methodName looked like this:

def methodName(self, foo=formless.String(), bar=formless.Integer()): 
pass

We could pass arguments to this method by producing a form which looked 
like this:

<form action="/foo/bar/freeform_post:methodName">
	<input type="text" name="foo" />
	<input type="text" name="bar" />
</form>

It's also useful to have freeform render a form for you, copy the 
source into your favorite HTML editor, format it, and rearrange it from 
there.

However, in anticipation of freeform's coming ability to allow you to 
control the layout more precisely while still auto-creating the form, I 
would like to gather use cases. Can you please give me a few methods 
which you will be exposing to the web, and the precisely laid out forms 
which you would like to invoke those methods? If you give me real life 
use cases, I will be able to keep them in mind as I do the refactoring 
to support them, and probably write tests that ensure your use cases 
are covered properly in the future.

dp