Plone Integration with YAFOWIL
YAFOWIL is a form library for Python. This is its Plone Integration package
yafowil.plone offers different levels of integration for Plone:
Addon widgets may provide custom javascripts, CSS, images and so on.
This package registers the directories containing these assets as resource directories. Thus they can be accessed from the webbrowser. The registration schema is ++resource++MODULENAME/....
The "YAFOWIL Form Library" GenericSetup profile registers all resources related to so called "resource groups" in the CSS and Javascript registries.
This resource groups must be enabled explicitly(!). The resource groups configuration happens via the portal registry.
You need to provide a Generic setup profile containing a registry.xml with the resource groups configuration, e.g.:
The record name maps to the YAFOWIL resource group name.
Take a look into registry.xml of the yafowil.plone:profiles/demoresources profile for more examples.
The YAFOWIL autoform profile registers a bunch of addons and may be used a a reference.
The package adds an translation method for Zope2 i18n messages. It's added using by defining a global preprocessor
This package registers a global preprocessor for YAFOWIL. It wraps the Zope2 request by an own request instance providing the behavior expected by YAFOWIL.
File Uploads provided by Zope2 as ZPublisher.HTTPRequest.Fileupload objects are turned into a python dict with the keys:
This package ships with base forms to be extended.
The following form base classes are available:
An in practice implementation may look like:
Convenience code for creating YAML forms:
Form classes inherit from Products.Five.BrowserPage, thus they must be registered via ZCML browser:page directive:
Forms build with this base form classes need a template in order to insert such a form in a layout. It must be called inside a wrapper template `myform.yaml`:
When not using one of the BaseForms, the CSS/JS resources for YAFOWIL are not loaded automatically.
Add the following lines in order to load it:
To write into the database in Plone a CSRF protection authenticator key must be provided as a hidden form field. This can be done by adding a plumbing behavior to the forms created as above.
EXPERIMENTAL:
Autoform features are not feature complete yet and can be considered as late alpha/early beta in YAFOWL 4.x. We plan to move it to a stable state in the 4.x series. With lots of care, it can be used in production.
YAFOWIL can be used as an drop-in replacement for the z3c.form based and plone.autoform generated forms.
There is a profile called YAFOWIL Autoform (in XML: yafowil.plone:autoform). By installing the profile, all needed to enable YAFOWIL rendered forms is installed. To finally activate autoform rendering for a content-type, one of the provided YAFOWIL Autoform behaviors has to be activated on the content-type.
YAFOWIL offers a layer to read z3c.form zope.schema annotations and build forms from this information.
Furthermore it offers an own zope.schema annotations named factory and factory_callable to build rich custom YAFOWIL forms without any z3c.form references.
Examples can be found within the bda.plone.yafowil_autoform_example behavior
There are two behaviors available.
If you're interested to dig deeper: The detailed YAFOWIL documentation is available. Read it and learn how to create your example application with YAFOWIL.
The sources are in a GIT DVCS with its main branches at github.
We'd be happy to see many forks and pull-requests to make YAFOWIL even better.