In a new Pyramid project we used deform to render forms. We did not really like it. (The reasons might be detailed in another post.)
To see if other form libraries do better I gave yafowil a try at our gocept Developer Punsch 3: yafowil comes with written documentation. To get a form in our Pyramid application I had to find out some things which are not so clearly documented:
- Let the project depend on yafowil.webob via setup.py as it contains the necessary WebOb integration.
- Import the
loader
from yafowil like below, to allow yafowil to register all its known components (even all the packages in the yafowil.wiget namespace). Otherwise I got strange errors. (The loader symbol is not needed at all in the rest of the code of the form.)
from yafowil import loader
- To get a value displayed in the rendered form use
value
keyword parameter in the factory like this:
form['name'] = factory('field:label:text', props=dict(label=u'name', required=True), value=value_getter)
value
can be a plain value or a function which gets the widget and the runtime data of the widget as parameters.
- Some widgets need JavaScript-Libraries. The integration with Pyramid or Fanstatic is not part of the framework.
yafowil.base.Factory.resources_for
could be a starting point. (I did not do this yet, so it might be wrong.)
Conclusion: yafowil looks like an interesting framework and after getting a starting point it should be useable in Pyramid, too. Maybe this post can help to ease it a bit.