yafowil in a Pyramid project

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 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.

Author: Michael Howitz

I am a software developer at gocept in Halle (Saale). To develop software I mainly use Python, Zope, ZTK and Pyramid.

1 thought on “yafowil in a Pyramid project”

  1. Hi,

    nice to see more interest in yafowil.

    Referring the addon resources (Javascrips, CSS) – as you pointed out above, this resources are registered in yafowil.base.factory. Resources in general refer to a resource group and a theme (both are just string identifyers). I make heavy use of yafowil in cone.app, a pyramid based web app stub. The code collecting the yafowil resources to deliver and registering static views for them can be found here – https://github.com/bluedynamics/cone.app/blob/master/src/cone/app/__init__.py#L142 – you may adopt it to your needs.

    We also thought of providing all the addon resources via fanstatic, but we skipped this for now due to integration problems especially in Plone. It might be worth picking up this idea again but implement the fanstatic integration in a seperate addon package.

    Some might also be interested in a base form class providing form processing and rendering, in cone.app this is implemented like this – https://github.com/bluedynamics/cone.app/blob/master/src/cone/app/browser/form.py#L87

    Regards, Robert

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s