Zope Toolkit support for zeam.form
zeam.form.ztk help you to integrate zeam.form.base with the Zope Tool Kit. It provides:
- Form fields generation out of zope.schema fields, and zope.schema fields listed in a Zope interface,
- Widgets for those fields,
- Default action to Add, Edit a content, Cancel a current action by returning on the default view of a content.
Like zeam.form.base the focus is to have an API usable by the developer, not a support of theorical use-cases that you don’t need.
Let’s create a form to edit a content. Here we have an interface for our content:
from zope import schema, interface class IClan(interface.Interface): pass class IPerson(interface.Interface): first_name = schema.TextLine(title=u"First Name") last_name = schema.TextLine(title=u"Last Name") age = schema.Int(title=u"Age", required=False) single = schema.Bool(title=u"Is single ?", default=True)
We assume that a Person is in a Clan. We can implement a Person:
from persistence import Persistent class Person(Persistent): interface.implements(IPerson) first_name = None last_name = None age = None single = True
You can add a new Person in a clan like this:
import zeam.form.ztk as form class Add(form.Form): form.context(IClan) label = u"New person" fields = form.Fields(IPerson) actions = form.Actions( form.AddAction("Add", factory=Person), form.CancelAction("Cancel")) actions['add'].fieldName = 'last_name'
You can edit a Person like this:
class Edit(form.Form): form.context(IPerson) label = u"Change person details" fields = form.Fields(IPerson) actions = form.Actions( form.EditAction("Update"), form.CancelAction("Cancel")) ignoreContent = False
All the API of zeam.form.base is exported as well.
- Action which take an extra parameter, factory, to create an object stored on the content object. The created object is added with the help of INameChooser to get its identifier. The option fieldName will be used to lookup a value in the form data to give as potential identifier to INameChooser. Afterwards the created object is edited (like EditAction does) with the form data.
- Action which use the form data to change values on the content object, designated by the form fields, after validation of the form submission.
- Simple action which return on default view of the content without validating the form submission.
Currently supported fields:
- Date, Datetime: generate a text line input and parse/display the date using the locale,
- TextLine, Text, Boolean, URI, Email, and numbers (Int, Float …),
- Choice: generate a select or a radio boxes (widget mode radio),
- Collections: List, Set, Tuple in input and display mode:
- Collection of choices: generate a widget with a list of checkboxes,
- Collection of objects: generate a table to edit multiple objects,
- Other collection: generate a widget with generic add an remove actions.
For more documentation, please report to the doctests included in the code.
- Extended the Mock Library class to make it compatible with the newest fanstatic api.
- Introducing the “defaultFactory” attributes from zope.schema. It was necessary to hijack the default value computing from zope.schema DefaultProperty.
- Allow people to customize the disabled attributes on fields.
- Add a native email widget.
- Update fields to properly pass along zope.schema the contrainValue validator.
- Fix all fields to properly handle required (it got broken in the previous release for some fields).
- Update fields and widgets to no longer proxy zope.schema. Instead they do their own validation and are standalone (they can be created and used without zope.schema).
- Support more HTML 5 features, like for number fields, and extra attributes that can be inserted with the help of htmlAttributes, like placeholder…
- Add a CurrencyField, that can be used to display nicely currencies.
- Update API to use zeam.form.base 1.2.3.
- Adjust CheckboxWidgetExtractor to convert False input to bool False.
- Improve choice widgets, to make possible to customize the source of it. Add support for a IFormSourceBinder, that works like a IContextSourceBinder except it takes the form as parameter instead of the context (thus giving access to request as well for instance).
- Add a method delete to the data manager.
- Now use grokcore.chameleon instead of megrok.chameleon.
- Improve error reporting in collection widgets. Thanks to Novareto for the sponsorship.
- Add an validation option in collection widgets while adding and removing values from it. Thanks to Novareto for the sponsorship.
- If a collection widget is required, it will by default display one empty item in the collection when it is empty. That prevent an extra click to add it.
- Various fixes in InvariantsValidator.
- SchemaWidgetExtractor and SchemaField now catch Invalid exceptions.
- Add support for the HTML 5 attribute required in every template. Use the attribute novalidate on the form tag to disable it.
- Add a display widget for object and uri fields.
- Add an option valueLength to the date widgets. Any Zope formatter size can be use (short, medium …).
- Add a multiselect widget for multiple choices.
- Add a readonly widget.
- Add a display widget for booleans and collections.
- Add HTML5 widgets for URIs.
- Schema field can be adapted now, even if they don’t have a interface (if they provide an attribute __name__).
- Add more tests, fix issues in collection widgets, and invariant validator.
- Translations are all located in zeam.form.base.
- Update to use the last version of zeam.form.base.
- Add radio widget for choices.
- Add a display widgets for multiple choices.
- All fields have the field CSS class.
- Multiple choices widgets now properly respect the value of a vocabulary term.
- Updated entry points registrations to be compatible with latest zeam.form.base.
- Field wrapper registration is now made thanks to an entry point.
- Added invariants validation.
- Added A generic adaptive datamanager that can adapt the form content to one or several interfaces.
- Improve widget initialization, and testing layer support.
- Fix choice widgets when they are used with vocabulary factories.
- Initial release, with not all the widgets.