=============
plone.z3cform
=============
plone.z3cform is a library that enables the use of `z3c.form`_ in Zope.
It depends only on Zope and z3c.form.
For Plone integration, there is also `plone.app.z3cform`_, which can be
installed to make the default form templates more Ploneish. That package
pulls in this one as a dependency.
In addition to pure interoperability support, a few patterns which are useful
in Zope 2 applications are implemented here.
.. contents:: Contents
Installation
============
To use this package, simply install it as a dependency of the package where
you are using forms, via the ``install_requires`` line in ``setup.py``. Then
loads its configuration via ZCML::
<include package="plone.z3cform" />
Standalone forms
================
If you are using Zope 2.12 or later, z3c.form forms will *almost* work
out of the box. However, two obstacles remain:
* The standard file upload data converter does not work with Zope 2, so
fields (like ``zope.schema.Bytes``) using the file widget will not work
correctly.
* z3c.form expects request values to be decoded to unicode strings by the
publisher, which does not happen in Zope 2.
To address the first problem, this package provides an override for the
standard data converter adapter (registered on the ``zope.schema.Bytes`` class
directly, so as to override the default, which is registered for the less
general ``IBytes`` interface). To address the second, it applies a monkey
patch to the ``update()`` methods of ``BaseForm`` and ``GroupForm`` from
``z3c.form`` which performs the necessary decoding in a way that is consistent
with the Zope 3-style publisher.
Note: If you override ``update()`` in your own form you must either call the
base class version or call the function ``plone.z3cform.z2.processInputs()``
on the request *before* any values in the request are used. For example::
from plone.z3cform.z2 import processInputs
from z3c.form import form
...
class MyForm(form.Form):
...
def update(self):
processInputs(self.request)
...
Other than that, you can create a form using standard `z3c.form`_ conventions.
For example::
from zope.interface import Interface
from zope import schema
from z3c.form import form, button
class IMyFormSchema(Interface):
field1 = schema.TextLine(title=u"A field")
field2 = schema.Int(title=u"Another field")
class MyForm(form.Form):
fields = field.Fields(IMyformSchema)
@button.buttonAndHandler(u'Submit')
def handleApply(self, action):
data, errors = self.extractData()
# do something
You can register this as a view in ZCML using the standard ``<browser:page />``
directive::
<browser:page
for="*"
name="my-form"
class=".forms.MyForm"
permission="zope2.View"
/>
A default template will be used to render the form. If you want to associate
a custom template, you should do so by setting the ``template`` class variable
instead of using the ``template`` attribute of the ZCML directive::
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
class MyForm(form.Form):
fields = field.Fields(IMyformSchema)
template = ViewPageTemplateFile('mytemplate.pt')
@button.buttonAndHandler(u'Submit')
def handleApply(self, action):
data, errors = self.extractData()
# do something
See below for more details about standard form macros.
Note that to render any of the standard widgets, you will also need to make
sure the request is marked with ``z3c.form.interfaces.IFormLayer``, as is
the norm with z3c.form. If you install `plone.app.z3cform`_ in Plone, that
is already done for you, but in other scenarios, you will need to do this
in whichever way Zope browser layers are normally applied.
Layout form wrapper
===================
In versions of Zope prior to 2.12, z3c.form instances cannot be registered
as views directly, because they do not support Zope 2 security (via the
acquisition mechanism). Whilst it may be possible to support this via custom
mix-ins, the preferred approach is to use a wrapper view, which separates the
rendering of the form from the page layout.
There are a few other reasons why you may want to use the wrapper view, even
in later versions of Zope:
* To support both an earlier version of Zope and Zope 2.12+
* To re-use the same form in multiple views or viewlets
* To use the ``IPageTemplate`` adapter lookup semantics from z3c.form to
provide a different default or override template for the overall page
layout, while retaining (or indeed customising independently) the default
layout of the form.
When using the wrapper view, you do *not* need to ensure your requests are
marked with ``IFormLayer``, as it is applied automatically during the
rendering of the wrapper view.
The easiest way to create a wrapper view is to call the ``wrap_form()``
function::
from zope.interface import Interface
from zope import schema
from z3c.form import form, button
from plone.z3cform import layout
class IMyFormSchema(Interface):
field1 = schema.TextLine(title=u"A field")
field2 = schema.Int(title=u"Another field")
class MyForm(form.Form):
fields = field.Fields(IMyformSchema)
@button.buttonAndHandler(u'Submit')
def handleApply(self, action):
data, errors = self.extractData()
# do something
MyFormView = layout.wrap_form(MyForm)
You can now register the (generated) ``MyFormView`` class as a browser view::
<browser:page
for="*"
name="my-form"
class=".forms.MyFormView"
permission="zope2.View"
/>
If you want to have more control, you can define the wrapper class manually.
You should derive from the default version to get the correct semantics. The
following is equivalent to the ``wrap_form()`` call above::
class MyFormView(layout.FormWrapper):
form = MyForm
You can of then add additional methods to the class, use a custom page
template, and so on.
The default ``FormWrapper`` class exposes a few methods and properties:
* ``update()`` is called to prepare the request and then update the wrapped
form.
* ``render()`` is called to render the wrapper view. If a template has
been set (normally via the ``template`` attribute of the
``<browser:page />`` directive), it will be rendered here. Otherwise,
a default page template is found by adapting the view (``self``) and
the request to ``zope.pagetemplate.interfaces.IPageTemplate``, in the
same way that ``z3c.form`` does for its views. A default template is
supplied with this package (and customised in `plone.app.z3cform`_ to
achieve a standard Plone look and feel).
* ``form`` is a class variable referring to the form class, as set above.
* ``form_instance`` is an instance variable set to the current form instance
once the view has been initialised.
When a form is rendered in a wrapper view, the form instance is temporarily
marked with ``plone.z3cform.interfaces.IWrappedForm`` (unless the form is
a subform), to allow custom adapter registrations. Specifically, this is used
to ensure that a form rendered "standalone" gets a full-page template applied,
while a form rendered in a wrapper is rendered using a template that renders
the form elements only.
Default templates and macros
============================
Several standard templates are provided with this package. These are all
registered as adapters from ``(view, request)`` to ``IPageTemplate``, as is
the convention in z3c.form. It therefore follows that these defaults can be
customised with an adapter override, e.g. for a specific browser layer. This
is useful if you want to override the standard rendering of all forms. If you
just want to provide a custom template for a particular form or wrapper view,
you can specify a template directly on the form or view, as shown above.
* ``templates/layout.pt`` is the default template for the layout wrapper view.
It uses the CMFDefault ``main_template`` and fills the ``header`` slot.
* ``templates/wrappedform.pt`` is the default template for wrapped forms.
It renders the ``titlelessform`` macro from the ``@@ploneform-macros`` view.
* ``templates/subform.pt`` is the default template for sub-forms.
It uses the macros in ``@@ploneform-macros`` view to render a heading,
top/bottom content (verbatim) and the fields and actions of the subform (but
does not) render the ``<form />`` tag itself.
* ``templates/form.pt`` is the default template for a standalone form. It uses
the macro ``context/@@standard_macros/page`` (supplied by Five and normally
delegating to CMF's ``main_template``) to render a form where the form label
is the page heading.
As hinted, this package also registers a view ``@@ploneform-macros``, which
contains a set of macros that be used to construct forms with a standard
layout, error message display, and so on. It contains the following macros:
* ``form`` is a full page form, including the label (output as an ``<h3 />``),
description, and all the elements of ``titlelessform``. It defines two
slots: ``title`` contains the label, and ``description`` contains the
description.
* ``titlelessform`` includes the form ``status`` at the top, the ``<form />``
element, and the contents of the ``fields`` and ``actions`` macros. It also
defines four slots: ``formtop`` is just inside the opening ``<form>`` tag;
``formbottom``` is just inside the closing ``</form>`` tag;
``fields`` contains the ``fields`` macro; and ``actions`` contains the
``actions`` macro.
* ``fields`` iterates over all widgets in the form and renders each, using the
contents of the ``field`` macro. It also defines one slot, ``field`` which
contains the ``field`` macro.
* ``field`` renders a single field. It expects the variable ``widget`` to be
defined in the TAL scope, referring to a z3c.form widget instance. It will
output an error message if there is a field validation error, a label,
a marker to say whether the field is required, the field description, and
the widget itself (normally just an ``<input />`` element).
* ``actions`` renders all actions (buttons) on the form. This normally results
in a row of ``<input type="submit" ... />`` elements.
Thus, to use the ``titlelessform`` macro, you could add something like the
following in a custom form template::
<metal:use use-macro="context/@@ploneform-macros/titlelessform" />
Note that all of the templates mentioned above are customised by
`plone.app.z3cform`_ to use standard Plone markup (but still retain the same
macros), so if you are using that package to configure this one, you should
look for the Plone-specific versions there.
Template factories
==================
If you want to provide an ``IPageTemplate`` adapter to customise the default
page template used for wrapper views, forms or sub-forms, this package
provides helper classes to create an adapter factory for that purpose. You
should use these instead of ``z3c.form.form.FormTemplateFactory`` and
(possibly) ``z3c.form.widget.WidgetTemplateFactory`` to get page templates
with Zope 2 semantics. These factories are also `Chameleon`_ aware, if you
have `five.pt`_ installed.
The most commonly used factory is
``plone.z3cform.templates.ZopeTwoFormTemplateFactory``, which can be used to
render a wrapper view or a standalone form.
To render a wrapped form, you can use
``plone.z3cform.templates.FormTemplateFactory``, which is closer to the
default ``z3c.form`` version, but adds Chameleon-awareness.
To render a widget, the default ``WidgetTemplateFactory`` from z3c.form should
suffice, but if you need Zope 2 semantics for any reason, you can use
``plone.z3cform.templates.ZopeTwoWidgetTemplateFactory``.
As an example, here are the default registrations from this package::
import z3c.form.interfaces
import plone.z3cform.interfaces
from plone.z3cform.templates import ZopeTwoFormTemplateFactory
from plone.z3cform.templates import FormTemplateFactory
path = lambda p: os.path.join(os.path.dirname(plone.z3cform.__file__), 'templates', p)
layout_factory = ZopeTwoFormTemplateFactory(path('layout.pt'),
form=plone.z3cform.interfaces.IFormWrapper
)
wrapped_form_factory = FormTemplateFactory(path('wrappedform.pt'),
form=plone.z3cform.interfaces.IWrappedForm,
)
# Default templates for the standalone form use case
standalone_form_factory = ZopeTwoFormTemplateFactory(path('form.pt'),
form=z3c.form.interfaces.IForm
)
subform_factory = FormTemplateFactory(path('subform.pt'),
form=z3c.form.interfaces.ISubForm
)
These are registered in ZCML like so::
<!-- Form templates for wrapped layout use case -->
<adapter factory=".templates.layout_factory" />
<adapter factory=".templates.wrapped_form_factory" />
<!-- Form templates for standalone form use case -->
<adapter factory=".templates.standalone_form_factory" />
<adapter factory=".templates.subform_factory" />
The widget traverser
====================
It is sometimes useful to be able to register a view on a *widget* and be
able to traverse to that view, for example during a background AJAX request.
As an example of widget doing this, see `plone.formwidget.autocomplete`_.
This package provides a ``++widget++`` namespace traversal adapter which can
be used for this purpose. It is looked up on either the form wrapper view,
or the form itself (in the case of standalone) forms. Thus, if you have a
form view called ``@@my-form``, with a field called ``myfield``, you could
traverse to the widget for that view using::
http://example.com/@@my-form/++widget++myfield
The widget may be on the form itself, or in a group (fieldset). If it exists
in multiple groups, the first one found will be used.
The example above will yield widget, but it is probably not publishable.
You would therefore commonly register a view on the widget itself and use
that. In this case, ``self.context`` in the view is the widget instance. Such
a view could be looked up with::
http://example.com/@@my-form/++widget++myfield/@@some-view
A caveat about security
-----------------------
In Zope 2.12 and later, the security machinery is aware of ``__parent__``
pointers. Thus, traversal and authorisation on ``@@some-view`` in the example
above will work just fine for a standard widget. In earlier versions of Zope,
you will need to mix acquisition into your widget (which rules out using any
of the standard ``z3c.form`` widgets). For example::
from Acquisition import Explicit
from z3c.form.widget import Widget
class MyWidget(Widget, Explicit):
...
Unfortunately, in Zope 2.12, this will cause some problems during traversal
unless you also mix acquisition into the view you registered on the widget
(``@@some-view`` above). Specifically, you will get an error as the publisher
tries to wrap the view in the widget.
To stay compatible with both Zope 2.12+ and earlier versions, you have two
options:
* Ensure that you mix acquisition into the view on the widget
* Ensure that the widget inherits from ``Explicit``, but does *not* provide
the ``IAcquirer`` interface. This tricks the publisiher into relying on
``__parent__`` pointers in Zope 2.12.
To do the latter, you can use ``implementsOnly()``, e.g.::
from zope.interface import implementsOnly
from Acquisition import Explicit
from z3c.form.widget import Widget
...
class MyWidget(Widget, Explicit):
implementsOnly(IMyWidget) # or just IWdget from z3c.form
...
.. _z3c.form: http://pypi.python.org/pypi/z3c.form
.. _plone.app.z3cform: http://pypi.python.org/pypi/plone.app.z3cform
.. _CMF: http://www.zope.org/Products/CMF
.. _Chameleon: http://pypi.python.org/pypi/Chameleon
.. _five.pt: http://pypi.python.org/pypi/five.pt
.. _plone.formwidget.autocomplete: http://pypi.python.org/pypi/plone.formwidget.autocomplete
Fieldsets and form extenders
============================
The ``plone.z3cform.fieldsets`` package provides support for z3c.form groups
(fieldsets) and other modifications via "extender" adapters. The idea is that
a third party component can modify the fields in the form and the way that
they are grouped and ordered.
This support relies on a mixin class, which is itself a subclass of
z3c.form's ``GroupForm``::
>>> from plone.z3cform.fieldsets import group, extensible
To use this, you have to mix it into another form as the *first* base class::
>>> from zope.annotation import IAttributeAnnotatable
>>> from z3c.form import form, field, tests, group
>>> from zope.interface import Interface
>>> from zope.interface import implementer
>>> from zope import schema
>>> class ITest(Interface):
... title = schema.TextLine(title=u"Title")
>>> @implementer(ITest, IAttributeAnnotatable)
... class Test(object):
... # avoid needing an acl_users for this test in Zope 2.10
... __allow_access_to_unprotected_subobjects__ = 1
...
... title = u""
... def getPhysicalRoot(self): # needed for template to acquire REQUEST in Zope 2.10
... return self
>>> class TestForm(extensible.ExtensibleForm, form.Form):
... fields = field.Fields(ITest)
Here, note the order of the base classes. Also note that we use an ordinary
set of fields directly on the form. This known as the default fieldset.
This form should work as-is, i.e. we can update it. First we need to fake a
request::
>>> from plone.z3cform.tests import TestRequest
>>> request = TestRequest()
>>> request.other = {}
>>> context = Test()
>>> context.REQUEST = request
>>> form = TestForm(context, request)
>>> form.update()
>>> list(form.fields.keys())
['title']
Now let's register an adapter that adds two new fields - one in the
default fieldset as the first field, and one in a new group. To do this,
we only need to register a named multi-adapter. However, we can use a
convenience base class to make it easier to manipulate the fields of the
form::
>>> from plone.z3cform.fieldsets.interfaces import IFormExtender
>>> from zope.component import adapter
>>> from zope.component import provideAdapter
>>> class IExtraBehavior(Interface):
... foo = schema.TextLine(title=u"Foo")
... bar = schema.TextLine(title=u"Bar")
... baz = schema.TextLine(title=u"Baz")
... fub = schema.TextLine(title=u"Fub")
... qux = schema.TextLine(title=u"Qux")
One plausible implementation is to use an annotation to store this data.
::
>>> from zope.annotation import factory
>>> from zope.annotation.attribute import AttributeAnnotations
>>> from persistent import Persistent
>>> @implementer(IExtraBehavior)
... @adapter(Test)
... class ExtraBehavior(Persistent):
...
...
... foo = u""
... bar = u""
... baz = u""
... fub = u""
... qux = u""
>>> ExtraBehavior = factory(ExtraBehavior)
>>> provideAdapter(ExtraBehavior)
>>> provideAdapter(AttributeAnnotations)
We can now write the extender. The base class gives us some helper methods
to add, remove and move fields. Here, we do a bit of unnecessary work just
to exercise these methods.
::
>>> @adapter(Test, TestRequest, TestForm) # context, request, form
... class ExtraBehaviorExtender(extensible.FormExtender):
...
... def __init__(self, context, request, form):
... self.context = context
... self.request = request
... self.form = form
...
... def update(self):
... # Add all fields from an interface
... self.add(IExtraBehavior, prefix="extra")
...
... # Remove the fub field
... self.remove('fub', prefix="extra")
...
... all_fields = field.Fields(IExtraBehavior, prefix="extra")
...
... # Insert fub again, this time at the top
... self.add(all_fields.select("fub", prefix="extra"), index=0)
...
... # Move 'baz' above 'fub'
... self.move('baz', before='fub', prefix='extra', relative_prefix='extra')
...
... # Move 'foo' after 'bar' - here we specify prefix manually
... self.move('foo', after='extra.bar', prefix='extra')
...
... # Remove 'bar' and re-insert into a new group
... self.remove('bar', prefix='extra')
... self.add(all_fields.select('bar', prefix='extra'), group='Second')
...
... # Move 'baz' after 'bar'. This means it also moves group.
... self.move('extra.baz', after='extra.bar')
...
... # Remove 'qux' and re-insert into 'Second' group,
... # then move it before 'baz'
... self.remove('qux', prefix='extra')
... self.add(all_fields.select('qux', prefix='extra'), group='Second')
... self.move('qux', before='baz', prefix='extra', relative_prefix='extra')
>>> provideAdapter(factory=ExtraBehaviorExtender, name=u"test.extender")
With this in place, let's update the form once again::
>>> form = TestForm(context, request)
>>> form.update()
At this point, we should have a set of default fields that represent the
ones set in the adapter::
>>> list(form.fields.keys())
['extra.fub', 'title', 'extra.foo']
And we should have one group created by the group factory::
>>> form.groups # doctest: +ELLIPSIS
(<plone.z3cform.fieldsets.group.Group object at ...>,)
Note that the created group is of a subtype of the standard z3c.form group,
which has got support for a separate label and description as well as a
canonical name::
>>> isinstance(form.groups[0], group.Group)
True
This should have the group fields provided by the adapter as well::
>>> list(form.groups[0].fields.keys())
['extra.bar', 'extra.qux', 'extra.baz']
CRUD (Create, Read, Update and Delete) forms
============================================
This module provides an abstract base class to create CRUD forms.
By default, such forms provide a tabular view of multiple objects, whose
attributes can be edited in-place.
Please refer to the ``ICrudForm`` interface for more details.
>>> from plone.z3cform.crud import crud
Setup
-----
>>> from plone.z3cform.tests import setup_defaults
>>> setup_defaults()
A simple form
-------------
First, let's define an interface and a class to play with:
>>> from zope import interface, schema
>>> class IPerson(interface.Interface) :
... name = schema.TextLine()
... age = schema.Int()
>>> @interface.implementer(IPerson)
... class Person(object):
... def __init__(self, name=None, age=None):
... self.name, self.age = name, age
... def __repr__(self):
... return "<Person with name=%r, age=%r>" % (self.name, self.age)
For this test, we take the the name of our persons as keys in our
storage:
>>> storage = {'Peter': Person(u'Peter', 16),
... 'Martha': Person(u'Martha', 32)}
Our simple form looks like this:
>>> class MyForm(crud.CrudForm):
... update_schema = IPerson
...
... def get_items(self):
... return sorted(storage.items(), key=lambda x: x[1].name)
...
... def add(self, data):
... person = Person(**data)
... storage[str(person.name)] = person
... return person
...
... def remove(self, id_item):
... id, item = id_item
... del storage[id]
This is all that we need to render a combined edit add form containing
all our items:
>>> class FakeContext(object):
... def absolute_url(self):
... return 'http://nohost/context'
>>> fake_context = FakeContext()
>>> from plone.z3cform.tests import TestRequest
>>> print(MyForm(fake_context, TestRequest())()) \
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<div class="crud-form">...Martha...Peter...</div>
Editing items with our form
---------------------------
Before we start with editing objects, let's log all events that the
form fires for us:
>>> from zope.lifecycleevent.interfaces import IObjectModifiedEvent
>>> from plone.z3cform.tests import create_eventlog
>>> log = create_eventlog(IObjectModifiedEvent)
>>> request = TestRequest()
>>> request.form['crud-edit.Martha.widgets.select-empty-marker'] = u'1'
>>> request.form['crud-edit.Peter.widgets.select-empty-marker'] = u'1'
>>> request.form['crud-edit.Martha.widgets.name'] = u'Martha'
>>> request.form['crud-edit.Martha.widgets.age'] = u'55'
>>> request.form['crud-edit.Peter.widgets.name'] = u'Franz'
>>> request.form['crud-edit.Peter.widgets.age'] = u'16'
>>> request.form['crud-edit.form.buttons.edit'] = u'Apply changes'
>>> html = MyForm(fake_context, request)()
>>> "Successfully updated" in html
True
Two modified events should have been fired:
>>> event1, event2 = log.pop(), log.pop()
>>> storage['Peter'] in (event1.object, event2.object)
True
>>> storage['Martha'] in (event1.object, event2.object)
True
>>> log
[]
If we don't make any changes, we'll get a message that says so:
>>> html = MyForm(fake_context, request)()
>>> "No changes made" in html
True
>>> log
[]
Now that we renamed Peter to Franz, it would be also nice to have
Franz use 'Franz' as the id in the storage, wouldn't it?
>>> storage['Peter']
<Person with name='Franz', age=16>
We can override the CrudForm's ``before_update`` method to perform a
rename whenever the name of a person is changed:
>>> class MyRenamingForm(MyForm):
... def before_update(self, item, data):
... if data['name'] != item.name:
... del storage[item.name]
... storage[str(data['name'])] = item
Let's rename Martha to Maria. This will give her another key in our
storage:
>>> request.form['crud-edit.Martha.widgets.name'] = u'Maria'
>>> html = MyRenamingForm(fake_context, request)()
>>> "Successfully updated" in html
True
>>> log.pop().object == storage['Maria']
True
>>> log
[]
>>> sorted(storage.keys())
['Maria', 'Peter']
Next, we'll submit the form for edit, but we'll make no changes.
Instead, we'll select one time. This shouldn't do anything, since we
clicked the 'Apply changes' button:
>>> request.form['crud-edit.Maria.widgets.name'] = u'Maria'
>>> request.form['crud-edit.Maria.widgets.age'] = u'55'
>>> request.form['crud-edit.Maria.widgets.select'] = [u'selected']
>>> html = MyRenamingForm(fake_context, request)()
>>> "No changes" in html
True
>>> log
[]
And what if we do have changes *and* click the checkbox?
>>> request.form['crud-edit.Maria.widgets.age'] = u'50'
>>> html = MyRenamingForm(fake_context, request)()
>>> "Successfully updated" in html
True
>>> log.pop().object == storage['Maria']
True
>>> log
[]
If we omit the name, we'll get an error:
>>> request.form['crud-edit.Maria.widgets.name'] = u''
>>> html = MyRenamingForm(fake_context, request)()
>>> "There were some errors" in html
True
>>> "Required input is missing" in html
True
We expect an error message in the title cell of Maria:
>>> checkbox_pos = html.index('crud-edit.Maria.widgets.select-empty-marker')
>>> "Required input is missing" in html[checkbox_pos:]
True
Delete an item with our form
----------------------------
We can delete an item by selecting the item we want to delete and
clicking the "Delete" button:
>>> request = TestRequest()
>>> request.form['crud-edit.Peter.widgets.select'] = ['selected']
>>> request.form['crud-edit.form.buttons.delete'] = u'Delete'
>>> html = MyForm(fake_context, request)()
>>> "Successfully deleted items" in html
True
>>> 'Franz' in html
False
>>> storage
{'Maria': <Person with name='Maria', age=50>}
Add an item with our form
-------------------------
>>> from zope.lifecycleevent.interfaces import IObjectCreatedEvent
>>> from plone.z3cform.tests import create_eventlog
>>> log = create_eventlog(IObjectCreatedEvent)
>>> request = TestRequest()
>>> request.form['crud-add.form.widgets.name'] = u'Daniel'
>>> request.form['crud-add.form.widgets.age'] = u'28'
>>> request.form['crud-add.form.buttons.add'] = u'Add'
>>> html = MyForm(fake_context, request)()
>>> "Item added successfully" in html
True
Added items should show up right away:
>>> "Daniel" in html
True
>>> storage['Daniel']
<Person with name='Daniel', age=28>
>>> log.pop().object == storage['Daniel']
True
>>> log
[]
What if we try to add "Daniel" twice? Our current implementation of
the add form will simply overwrite the data:
>>> save_daniel = storage['Daniel']
>>> html = MyForm(fake_context, request)()
>>> "Item added successfully" in html
True
>>> save_daniel is storage['Daniel']
False
>>> log.pop().object is storage['Daniel']
True
Let's implement a class that prevents this:
>>> class MyCarefulForm(MyForm):
... def add(self, data):
... name = data['name']
... if name not in storage:
... return super(MyCarefulForm, self).add(data)
... else:
... raise schema.ValidationError(
... u"There's already an item with the name '%s'" % name)
>>> save_daniel = storage['Daniel']
>>> html = MyCarefulForm(fake_context, request)()
>>> "Item added successfully" in html
False
>>> "There's already an item with the name 'Daniel'" in html
True
>>> save_daniel is storage['Daniel']
True
>>> len(log) == 0
True
Render some of the fields in view mode
--------------------------------------
We can implement in our form a ``view_schema`` attribute, which will
then be used to view information in our form's table. Let's say we
wanted the name of our persons to be viewable only in the table:
>>> from z3c.form import field
>>> class MyAdvancedForm(MyForm):
... update_schema = field.Fields(IPerson).select('age')
... view_schema = field.Fields(IPerson).select('name')
... add_schema = IPerson
>>> print(MyAdvancedForm(fake_context, TestRequest())()) \
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<div class="crud-form">...Daniel...Maria...</div>
We can still edit the age of our Persons:
>>> request = TestRequest()
>>> request.form['crud-edit.Maria.widgets.age'] = u'40'
>>> request.form['crud-edit.Daniel.widgets.age'] = u'35'
>>> request.form['crud-edit.form.buttons.edit'] = u'Apply Changes'
>>> html = MyAdvancedForm(fake_context, request)()
>>> "Successfully updated" in html
True
>>> storage['Maria'].age
40
>>> storage['Daniel'].age
35
We can still add a Person using both name and age:
>>> request = TestRequest()
>>> request.form['crud-add.form.widgets.name'] = u'Thomas'
>>> request.form['crud-add.form.widgets.age'] = u'28'
>>> request.form['crud-add.form.buttons.add'] = u'Add'
>>> html = MyAdvancedForm(fake_context, request)()
>>> "Item added successfully" in html
True
>>> len(storage)
3
>>> storage['Thomas']
<Person with name='Thomas', age=28>
Our form can also contain links to our items:
>>> class MyAdvancedLinkingForm(MyAdvancedForm):
... def link(self, item, field):
... if field == 'name':
... return 'http://en.wikipedia.org/wiki/%s' % item.name
>>> print(MyAdvancedLinkingForm(fake_context, TestRequest())()) \
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<div class="crud-form">...
...<a href="http://en.wikipedia.org/wiki/Daniel"...
...<a href="http://en.wikipedia.org/wiki/Maria"...
...<a href="http://en.wikipedia.org/wiki/Thomas"...
</div>
What if we wanted the name to be both used for linking to the item
*and* for edit? We can just include the title field twice:
>>> class MyAdvancedLinkingForm(MyAdvancedLinkingForm):
... update_schema = IPerson
... view_schema = field.Fields(IPerson).select('name')
... add_schema = IPerson
>>> print(MyAdvancedLinkingForm(fake_context, TestRequest())()) \
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<div class="crud-form">...
...<a href="http://en.wikipedia.org/wiki/Thomas"...Thomas...</a>...
</div>
We can now change Thomas's name and see the change reflected in the
Wikipedia link immediately:
>>> request = TestRequest()
>>> for name in 'Daniel', 'Maria', 'Thomas':
... request.form['crud-edit.%s.widgets.name' % name] = storage[name].name
... request.form['crud-edit.%s.widgets.age' % name] = storage[name].age
>>> request.form['crud-edit.Thomas.widgets.name'] = u'Dracula'
>>> request.form['crud-edit.form.buttons.edit'] = u'Apply Changes'
>>> print(MyAdvancedLinkingForm(fake_context, request)()) \
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<div class="crud-form">...
...<a href="http://en.wikipedia.org/wiki/Dracula"...Dracula...</a>...
</div>
>>> storage['Thomas'].name = u'Thomas'
Don't render one part
---------------------
What if we wanted our form to display only one part, that is, only the
add *or* the edit form. Our CrudForm can implement
``editform_factory`` and ``addform_factory`` to override one or both
forms. Setting one of these to ``crud.NullForm`` will make them
disappear:
>>> class OnlyEditForm(MyForm):
... addform_factory = crud.NullForm
>>> html = OnlyEditForm(fake_context, TestRequest())()
>>> 'Edit' in html, 'Add' in html
(True, False)
>>> class OnlyAddForm(MyForm):
... editform_factory = crud.NullForm
>>> html = OnlyAddForm(fake_context, TestRequest())()
>>> 'Edit' in html, 'Add' in html
(False, True)
Render only in view, and define own actions
-------------------------------------------
Sometimes you want to present a list of items, possibly in view mode
only, and have the user select one or more of the items to perform
some action with them. We'll present a minimal example that does this
here.
We can simply leave the ``update_schema`` class attribute out (it
defaults to ``None``). Furthermore, we'll need to override the
ediform_factory with our custom version that provides other buttons
than the 'edit' and 'delete' ones:
>>> from pprint import pprint
>>> from z3c.form import button
>>> class MyEditForm(crud.EditForm):
... @button.buttonAndHandler(u'Capitalize', name='capitalize')
... def handle_capitalize(self, action):
... self.status = u"Please select items to capitalize first."
... selected = self.selected_items()
... if selected:
... self.status = u"Capitalized items"
... for id, item in selected:
... item.name = item.name.upper()
>>> class MyCustomForm(crud.CrudForm):
... view_schema = IPerson
... editform_factory = MyEditForm
... addform_factory = crud.NullForm # We don't want an add part.
...
... def get_items(self):
... return sorted(storage.items(), key=lambda x: x[1].name)
>>> request = TestRequest()
>>> html = MyCustomForm(fake_context, TestRequest())()
>>> "Delete" in html, "Apply changes" in html, "Capitalize" in html
(False, False, True)
>>> pprint(storage)
{'Daniel': <Person with name='Daniel', age=35>,
'Maria': <Person with name='Maria', age=40>,
'Thomas': <Person with name='Thomas', age=28>}
>>> request.form['crud-edit.Thomas.widgets.select'] = ['selected']
>>> request.form['crud-edit.form.buttons.capitalize'] = u'Capitalize'
>>> html = MyCustomForm(fake_context, request)()
>>> "Capitalized items" in html
True
>>> pprint(storage)
{'Daniel': <Person with name='Daniel', age=35>,
'Maria': <Person with name='Maria', age=40>,
'Thomas': <Person with name='THOMAS', age=28>}
We *cannot* use any of the other buttons:
>>> del request.form['crud-edit.form.buttons.capitalize']
>>> request.form['crud-edit.form.buttons.delete'] = u'Delete'
>>> html = MyCustomForm(fake_context, request)()
>>> "Successfully deleted items" in html
False
>>> 'Thomas' in storage
True
Customizing sub forms
---------------------
The EditForm class allows you to specify an editsubform_factory-a class
inherits from EditSubForm. This allows you to say, override the crud-row.pt
page template and customize the look of the fields.
>>> import zope.schema
>>> class MyCustomEditSubForm(crud.EditSubForm):
...
... def _select_field(self):
... """I want to customize the field that it comes with..."""
... select_field = field.Field(
... zope.schema.TextLine(__name__='select',
... required=False,
... title=u'select'))
... return select_field
>>> class MyCustomEditForm(MyEditForm):
... editsubform_factory = MyCustomEditSubForm
>>> class MyCustomFormWithCustomSubForm(MyCustomForm):
... editform_factory = MyCustomEditForm
>>> request = TestRequest()
>>> html = MyCustomFormWithCustomSubForm(fake_context, TestRequest())()
Still uses same form as before
>>> "Delete" in html, "Apply changes" in html, "Capitalize" in html
(False, False, True)
Just changes the widget used for selecting...
>>> 'type="checkbox"' in html
False
Using batching
--------------
The CrudForm base class supports batching. When setting the
``batch_size`` attribute to a value greater than ``0``, we'll only get
as many items displayed per page.
>>> class MyBatchingForm(MyForm):
... batch_size = 2
>>> request = TestRequest()
>>> html = MyBatchingForm(fake_context, request)()
>>> "Daniel" in html, "Maria" in html
(True, True)
>>> "THOMAS" in html
False
Make sure, the batch link to the next page is available
>>> 'crud-edit.form.page=1' in html
True
Show next page and check content
>>> request = TestRequest(QUERY_STRING='crud-edit.form.page=1')
>>> request.form['crud-edit.form.page'] = '1'
>>> html = MyBatchingForm(fake_context, request)()
>>> "Daniel" in html, "Maria" in html
(False, False)
>>> "THOMAS" in html
True
The form action also includes the batch page information so
the correct set of subforms can be processed::
>>> print(html) \
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<BLANKLINE>
...
<form action="http://nohost/context?crud-edit.form.page=1"
method="post"...
Let's change Thomas' age on the second page:
>>> request.form['crud-edit.Thomas.widgets.name'] = u'Thomas'
>>> request.form['crud-edit.Thomas.widgets.age'] = '911'
>>> request.form['crud-edit.form.buttons.edit'] = u'Apply changes'
>>> html = MyBatchingForm(fake_context, request)()
>>> "Successfully updated" in html
True
>>> "911" in html
True
Changelog
=========
.. You should *NOT* be adding new change log entries to this file.
You should create a file in the news directory instead.
For helpful instructions, please see:
https://github.com/plone/plone.releaser/blob/master/ADD-A-NEWS-ITEM.rst
.. towncrier release notes start
2.0.2 (2023-10-07)
------------------
Internal:
- Update configuration files.
[plone devs] (cfffba8c)
2.0.1 (2023-03-21)
------------------
Internal:
- Update configuration files.
[plone devs] (a533099d)
2.0.0 (2022-11-23)
------------------
Bug fixes:
- Final release for Plone 6.0.0. [maurits] (#600)
2.0.0b1 (2022-06-23)
--------------------
Bug fixes:
- Fix traversal to `z3c.form.widget.MultiWidget` widgets.
[petschki] (#22)
2.0.0a3 (2022-05-24)
--------------------
Bug fixes:
- cleanup crud-table markup
[petschki] (#21)
2.0.0a2 (2022-03-23)
--------------------
New features:
- compatibility with z3c.form >= 4.x
[petschki] (#20)
2.0.0a1 (2021-04-21)
--------------------
Breaking changes:
- Update for Plone 6 with Bootstrap markup
Refs PLIP https://github.com/plone/Products.CMFPlone/issues/3061
[petschki, ale-rt, agitator] (#16)
1.1.3 (2020-06-16)
------------------
Bug fixes:
- Copy the HTTPRequest._decode from Zope4 because it is going away in Zope5 (#13)
1.1.2 (2020-04-21)
------------------
Bug fixes:
- Buttons in crud-table should be list items.
[erral] (#9)
1.1.1 (2019-10-12)
------------------
Bug fixes:
- Fix edit/delete in paginated crud-forms [fRiSi]
1.1.0 (2019-04-09)
------------------
New features:
- Change license to GPLv2
[petschki]
- Enable ``:record[s]`` fields in ``z2.processInputs``
[petschki]
- Cosmetic tweaks.
[gforcada]
1.0.0 (2018-11-04)
------------------
New features:
- Support for Python 3
[pbauer, davilima6, ale-rt, jensens]
Bug fixes:
- Test cleanup.
[jensens]
- Rename folder templates to pagetemplates, because of ZCML browser directive warnings.
[jensens]
- Removal of tuple parameter unpacking in method definition (Fixes #14)
[ale-rt]
- Provide an up-to-date bootstrap.py
[ale-rt]
- Use the adapter and implementer decorators
[ale-rt]
0.9.1 (2017-09-03)
------------------
Bug fixes:
- Remove deprecated __of__ calls on BrowserViews
[MrTango]
0.9.0 (2016-05-25)
------------------
New:
- Enable groups aka fieldsets to be orderable.
[jensens]
Fixes:
- Fix batching navigation in CRUD form.
[petschki]
- Added two missing German translations.
One of those fixes https://github.com/plone/Products.CMFPlone/issues/1580
[jensens]
- QA: pep8. [maurits, thet]
0.8.1 (2015-01-22)
------------------
- Feature: take group class from parent-form if given. If not given it uses
the default class.
[jensens]
- Added Ukrainian translation
[kroman0]
- Added Italian translation
[giacomos]
0.8.0 (2012-08-30)
------------------
* Remove backwards-compatibility code for Zope < 2.12
[davisagli]
* Use plone.testing for functional test layer support.
[hannosch]
* Use ViewPageTemplateFile from zope.browserpage.
[hannosch]
* Use form action URL as given by the view, instead of implementing it
in the template as a call to the ``getURL`` method of the request.
[malthe]
* Use plone.batching for batches instead of z3c.batching
[tom_gross]
0.7.8 - 2011-09-24
------------------
* Do not display h1 element if there is no label on view.
[thomasdesvenain]
* Add Chinese translation.
[jianaijun]
0.7.7 - 2011-06-30
------------------
* Avoid rendering a wrapped form if a redirect has already occurred after
updating it.
[davisagli]
* Remove <a name=""/> elements from inside the CRUD table TBODY element
they were otherwise unused (and illegal in that location of the HTML content
model).
[mj]
0.7.6 - 2011-05-17
------------------
* Add ability to find widgets with non-integer names in lists. This shouldn't
generally be something that happens, and ideally should be removed if
DataGridField looses it's 'AA' and 'TT' rows.
[lentinj]
0.7.5 - 2011-05-03
------------------
* Fix traversal tests on Zope 2.10 to handle TraversalError instead of
LocationError.
[elro]
* Fix traversal.py syntax to be python2.4 compatible.
* Revert [120798] as it breaks on Zope2.10 / Plone 3.3. We can deal with Zope
2.14 in 0.8.x.
[elro]
0.7.4 - 2011-05-03
------------------
* Define 'hidden' within field macro.
[elro]
* Ignore "form.widgets." if ++widget++ path begins with it.
[lentinj]
* Rework traverser to handle lists and subforms
[lentinj]
* Only search a group's widgets if they exist. collective.z3cform.wizard doesn't
create widgets for pages/groups other than the current one
[lentinj, elro]
* Deal with forward compatibility with Zope 2.14.
* Adds Brazilian Portuguese translation.
[davilima6]
0.7.3 - 2011-03-02
------------------
* Handle wrong fieldnames more cleanly in the ++widget++ traverser.
[elro]
0.7.2 - 2011-02-17
------------------
* Make sure the CRUD add form doesn't use a standalone template.
[davisagli]
0.7.1 - 2011-01-18
---------------------
* Add zope.app.testing to test dependencies so that it continues to work under
Zope 2.13.
[esteele]
0.7.0 - 2010-08-04
------------------
* Add a marker interface which can be used by widgets to defer any security
checks they may be doing when they are set up during traversal with the
++widgets++ namespace
[dukebody]
* Fix re-ordering of fields not in the default fieldset. Thanks to Thomas
Buchberger for the patch.
[optilude]
* Added Norwegian translation.
[regebro]
0.6.0 - 2010-04-20
------------------
* In the CRUD table, fix odd/even labels, which were reversed.
[limi]
* Added slots to the ``titlelessform`` macro. See ``README.txt`` for details.
[optilude, davisagli]
* Remove the distinction between wrapped and unwrapped subforms. A subform is
always wrapped by the form that contains it, and can use a Zope 3 page
template.
[davisagli]
* Fixed tests in Plone 3.
[davisagli]
* Fixed tests in Plone 4
[optilude]
* Made it possible to distinguish wrapped and unwrapped forms via the
IWrappedForm marker interface.
[optilude]
* Made it possible to use z3c.form forms without a FormWrapper in Plone 4.
[optilude]
0.5.10 - 2010-02-01
-------------------
* A z3c.form.form.AddForm do a redirect in its render method.
So we have to render the form to see if we have a redirection.
In the case of redirection, we don't render the layout at all.
This version remove the contents method on FormWrapper,
it's now an attribute set during the FormWrapper.update.
This change fixes status message not shown because it was consumed by
the never shown rendered form.
[vincentfretin]
0.5.9 - 2010-01-08
------------------
* Fix security problem with the ++widget++ namespace
[optilude]
0.5.8 - 2009-11-24
------------------
* Don't do the rendering if there is a redirection, use the update/render
pattern for that.
See http://dev.plone.org/plone/ticket/10022 for an example how
to adapt your code, in particular if you used FormWrapper with ViewletBase.
[vincentfretin]
0.5.7 - 2009-11-17
------------------
* Fix silly doctests so that they don't break in Python 2.6 / Zope 2.12
[optilude]
0.5.6 - 2009-09-25
------------------
* Added title_required msgid in macros.pt to be the same as plone.app.z3cform
because macros.pt from plone.app.z3cform uses plone.z3cform translations.
Added French translation and fixed German and Dutch translations
for label_required and title_required messages.
[vincentfretin]
0.5.5 - 2009-07-26
------------------
* Removed explicit <includeOverrides /> call from configure.zcml. This causes
race condition type errors in ZCML loading when overrides are included
later.
[optilude]
0.5.4 - 2009-04-17
------------------
* Added monkey patch to fix a bug in z3c.form's ChoiceTerms on z3c.form 1.9.0.
[optilude]
* Fix obvious bugs and dodgy naming in SingleCheckBoxWidget.
[optilude]
* Use chameleon-based page templates from five.pt if available.
[davisagli]
* Copied the basic textlines widget from z3c.form trunk for use until
it is released.
[davisagli]
0.5.3 - 2008-12-09
------------------
* Add translation marker for batch, update translation files.
[thefunny42]
* Handle changed signature for widget extract method in z3c.form > 1.9.0
[davisagli]
* Added wildcard support to the 'before' and 'after' parameters of the
fieldset 'move' utility function.
[davisagli]
* Fixes for Zope 2.12 compatibility.
[davisagli]
* Don't display an 'Apply changes' button if you don't define an
update_schema.
[thefunny42]
* Declare xmlnamespace into 'layout.pt' and 'subform.pt' templates
* Added support for an editsubform_factory for an EditForm so you can
override the default behavior for a sub form now.
* Changed css in crud-table.pt for a table to "listing" so that tables
now look like plone tables.
* Copy translation files to an english folder, so if your browser
negotiate to ``en,nl``, you will get english translations instead of
dutch ones (like expected).
[thefunny42]
* Send an event IAfterWidgetUpdateEvent after updating display widgets
manually in a CRUD form.
[thefunny42]
0.5.2 - 2008-08-28
------------------
* Add a namespace traversal adapter that allows traversal to widgets. This
is useful for AJAX calls, for example.
0.5.1 - 2008-08-21
------------------
* Add batching to ``plone.z3cform.crud`` CrudForm.
* Look up the layout template as an IPageTemplate adapter. This means that
it is possible for Plone to provide a "Ploneish" default template for forms
that don't opt into this, without those forms having a direct Plone
dependency.
* Default to the titleless form template, since the layout template will
provide a title anyway.
* In ``plone.z3cform.layout``, allow labels to be defined per form
instance, and not only per form class.
0.5.0 - 2008-07-30
------------------
* No longer depend on <3.5 of zope.component.
0.4 - 2008-07-25
----------------
* Depend on zope.component<3.5 to avoid ``TypeError("Missing
'provides' attribute")`` error.
* Allow ICrudForm.add to raise ValidationError, which allows for
displaying a user-friendly error message.
* Make the default layout template CMFDefault- compatible.
0.3 - 2008-07-24
----------------
* Moved Plone layout wrapper to ``plone.app.z3cform.layout``. If you
were using ``plone.z3cform.base.FormWrapper`` to get the Plone
layout before, you'll have to use
``plone.app.z3cform.layout.FormWrapper`` instead now. (Also, make
sure you include plone.app.z3cform's ZCML in this case.)
* Move out Plone-specific subpackages to ``plone.app.z3cform``. These
are:
- wysywig: Kupu/Plone integration
- queryselect: use z3c.formwidget.query with Archetypes
Clean up testing code and development ``buildout.cfg`` to not pull
in Plone anymore.
[nouri]
* Relicensed under the ZPL 2.1 and moved into the Zope repository.
[nouri]
* Add German translation.
[saily]
0.2 - 2008-06-20
----------------
* Fix usage of NumberDataConverter with zope.i18n >= 3.4 as the
previous test setup was partial and did not register all adapters
from z3c.form (some of them depends on zope >= 3.4)
[gotcha, jfroche]
* More tests
[gotcha, jfroche]
0.1 - 2008-05-21
----------------
* Provide and *register* default form and subform templates. These
allow forms to be used with the style provided in this package
without having to declare ``form = ViewPageTemplateFile('form.pt')``.
This does not hinder you from overriding with your own ``form``
attribute like usual. You can also still register a more
specialized IPageTemplate for your form.
* Add custom FileUploadDataConverter that converts a Zope 2 FileUpload
object to a Zope 3 one before handing it to the original
implementation. Also add support for different enctypes.
[skatja, nouri]
* Added Archetypes reference selection widget (queryselect)
[malthe]
* Moved generic Zope 2 compatibility code for z3c.form and a few
goodies from Singing & Dancing into this new package.
[nouri]
Raw data
{
"_id": null,
"home_page": "https://github.com/plone/plone.z3cform",
"name": "plone.z3cform",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "Plone CMF Python Zope CMS Webapplication",
"author": "Plone Foundation",
"author_email": "releasemanager@plone.org",
"download_url": "https://files.pythonhosted.org/packages/1e/83/0312ccd065aae31a77ef8cd79a9c89f7ae9e73ef9b72d0702d8b417c5cee/plone.z3cform-2.0.2.tar.gz",
"platform": null,
"description": "=============\nplone.z3cform\n=============\n\nplone.z3cform is a library that enables the use of `z3c.form`_ in Zope.\nIt depends only on Zope and z3c.form.\n\nFor Plone integration, there is also `plone.app.z3cform`_, which can be\ninstalled to make the default form templates more Ploneish. That package\npulls in this one as a dependency.\n\nIn addition to pure interoperability support, a few patterns which are useful\nin Zope 2 applications are implemented here.\n\n.. contents:: Contents\n\nInstallation\n============\n\nTo use this package, simply install it as a dependency of the package where\nyou are using forms, via the ``install_requires`` line in ``setup.py``. Then\nloads its configuration via ZCML::\n\n <include package=\"plone.z3cform\" />\n\nStandalone forms\n================\n\nIf you are using Zope 2.12 or later, z3c.form forms will *almost* work\nout of the box. However, two obstacles remain:\n\n* The standard file upload data converter does not work with Zope 2, so\n fields (like ``zope.schema.Bytes``) using the file widget will not work\n correctly.\n* z3c.form expects request values to be decoded to unicode strings by the\n publisher, which does not happen in Zope 2.\n\nTo address the first problem, this package provides an override for the\nstandard data converter adapter (registered on the ``zope.schema.Bytes`` class\ndirectly, so as to override the default, which is registered for the less\ngeneral ``IBytes`` interface). To address the second, it applies a monkey\npatch to the ``update()`` methods of ``BaseForm`` and ``GroupForm`` from\n``z3c.form`` which performs the necessary decoding in a way that is consistent\nwith the Zope 3-style publisher.\n\nNote: If you override ``update()`` in your own form you must either call the\nbase class version or call the function ``plone.z3cform.z2.processInputs()``\non the request *before* any values in the request are used. For example::\n\n from plone.z3cform.z2 import processInputs\n from z3c.form import form\n\n ...\n\n class MyForm(form.Form):\n\n ...\n\n def update(self):\n processInputs(self.request)\n ...\n\nOther than that, you can create a form using standard `z3c.form`_ conventions.\nFor example::\n\n from zope.interface import Interface\n from zope import schema\n from z3c.form import form, button\n\n class IMyFormSchema(Interface):\n field1 = schema.TextLine(title=u\"A field\")\n field2 = schema.Int(title=u\"Another field\")\n\n class MyForm(form.Form):\n fields = field.Fields(IMyformSchema)\n\n @button.buttonAndHandler(u'Submit')\n def handleApply(self, action):\n data, errors = self.extractData()\n # do something\n\nYou can register this as a view in ZCML using the standard ``<browser:page />``\ndirective::\n\n <browser:page\n for=\"*\"\n name=\"my-form\"\n class=\".forms.MyForm\"\n permission=\"zope2.View\"\n />\n\nA default template will be used to render the form. If you want to associate\na custom template, you should do so by setting the ``template`` class variable\ninstead of using the ``template`` attribute of the ZCML directive::\n\n from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile\n\n class MyForm(form.Form):\n fields = field.Fields(IMyformSchema)\n template = ViewPageTemplateFile('mytemplate.pt')\n\n @button.buttonAndHandler(u'Submit')\n def handleApply(self, action):\n data, errors = self.extractData()\n # do something\n\nSee below for more details about standard form macros.\n\nNote that to render any of the standard widgets, you will also need to make\nsure the request is marked with ``z3c.form.interfaces.IFormLayer``, as is\nthe norm with z3c.form. If you install `plone.app.z3cform`_ in Plone, that\nis already done for you, but in other scenarios, you will need to do this\nin whichever way Zope browser layers are normally applied.\n\nLayout form wrapper\n===================\n\nIn versions of Zope prior to 2.12, z3c.form instances cannot be registered\nas views directly, because they do not support Zope 2 security (via the\nacquisition mechanism). Whilst it may be possible to support this via custom\nmix-ins, the preferred approach is to use a wrapper view, which separates the\nrendering of the form from the page layout.\n\nThere are a few other reasons why you may want to use the wrapper view, even\nin later versions of Zope:\n\n* To support both an earlier version of Zope and Zope 2.12+\n* To re-use the same form in multiple views or viewlets\n* To use the ``IPageTemplate`` adapter lookup semantics from z3c.form to\n provide a different default or override template for the overall page\n layout, while retaining (or indeed customising independently) the default\n layout of the form.\n\nWhen using the wrapper view, you do *not* need to ensure your requests are\nmarked with ``IFormLayer``, as it is applied automatically during the\nrendering of the wrapper view.\n\nThe easiest way to create a wrapper view is to call the ``wrap_form()``\nfunction::\n\n from zope.interface import Interface\n from zope import schema\n from z3c.form import form, button\n\n from plone.z3cform import layout\n\n class IMyFormSchema(Interface):\n field1 = schema.TextLine(title=u\"A field\")\n field2 = schema.Int(title=u\"Another field\")\n\n class MyForm(form.Form):\n fields = field.Fields(IMyformSchema)\n\n @button.buttonAndHandler(u'Submit')\n def handleApply(self, action):\n data, errors = self.extractData()\n # do something\n\n MyFormView = layout.wrap_form(MyForm)\n\nYou can now register the (generated) ``MyFormView`` class as a browser view::\n\n <browser:page\n for=\"*\"\n name=\"my-form\"\n class=\".forms.MyFormView\"\n permission=\"zope2.View\"\n />\n\nIf you want to have more control, you can define the wrapper class manually.\nYou should derive from the default version to get the correct semantics. The\nfollowing is equivalent to the ``wrap_form()`` call above::\n\n class MyFormView(layout.FormWrapper):\n form = MyForm\n\nYou can of then add additional methods to the class, use a custom page\ntemplate, and so on.\n\nThe default ``FormWrapper`` class exposes a few methods and properties:\n\n* ``update()`` is called to prepare the request and then update the wrapped\n form.\n* ``render()`` is called to render the wrapper view. If a template has\n been set (normally via the ``template`` attribute of the\n ``<browser:page />`` directive), it will be rendered here. Otherwise,\n a default page template is found by adapting the view (``self``) and\n the request to ``zope.pagetemplate.interfaces.IPageTemplate``, in the\n same way that ``z3c.form`` does for its views. A default template is\n supplied with this package (and customised in `plone.app.z3cform`_ to\n achieve a standard Plone look and feel).\n* ``form`` is a class variable referring to the form class, as set above.\n* ``form_instance`` is an instance variable set to the current form instance\n once the view has been initialised.\n\nWhen a form is rendered in a wrapper view, the form instance is temporarily\nmarked with ``plone.z3cform.interfaces.IWrappedForm`` (unless the form is\na subform), to allow custom adapter registrations. Specifically, this is used\nto ensure that a form rendered \"standalone\" gets a full-page template applied,\nwhile a form rendered in a wrapper is rendered using a template that renders\nthe form elements only.\n\nDefault templates and macros\n============================\n\nSeveral standard templates are provided with this package. These are all\nregistered as adapters from ``(view, request)`` to ``IPageTemplate``, as is\nthe convention in z3c.form. It therefore follows that these defaults can be\ncustomised with an adapter override, e.g. for a specific browser layer. This\nis useful if you want to override the standard rendering of all forms. If you\njust want to provide a custom template for a particular form or wrapper view,\nyou can specify a template directly on the form or view, as shown above.\n\n* ``templates/layout.pt`` is the default template for the layout wrapper view.\n It uses the CMFDefault ``main_template`` and fills the ``header`` slot.\n* ``templates/wrappedform.pt`` is the default template for wrapped forms.\n It renders the ``titlelessform`` macro from the ``@@ploneform-macros`` view.\n* ``templates/subform.pt`` is the default template for sub-forms.\n It uses the macros in ``@@ploneform-macros`` view to render a heading,\n top/bottom content (verbatim) and the fields and actions of the subform (but\n does not) render the ``<form />`` tag itself.\n* ``templates/form.pt`` is the default template for a standalone form. It uses\n the macro ``context/@@standard_macros/page`` (supplied by Five and normally\n delegating to CMF's ``main_template``) to render a form where the form label\n is the page heading.\n\nAs hinted, this package also registers a view ``@@ploneform-macros``, which\ncontains a set of macros that be used to construct forms with a standard\nlayout, error message display, and so on. It contains the following macros:\n\n* ``form`` is a full page form, including the label (output as an ``<h3 />``),\n description, and all the elements of ``titlelessform``. It defines two\n slots: ``title`` contains the label, and ``description`` contains the\n description.\n* ``titlelessform`` includes the form ``status`` at the top, the ``<form />``\n element, and the contents of the ``fields`` and ``actions`` macros. It also\n defines four slots: ``formtop`` is just inside the opening ``<form>`` tag;\n ``formbottom``` is just inside the closing ``</form>`` tag;\n ``fields`` contains the ``fields`` macro; and ``actions`` contains the\n ``actions`` macro.\n* ``fields`` iterates over all widgets in the form and renders each, using the\n contents of the ``field`` macro. It also defines one slot, ``field`` which\n contains the ``field`` macro.\n* ``field`` renders a single field. It expects the variable ``widget`` to be\n defined in the TAL scope, referring to a z3c.form widget instance. It will\n output an error message if there is a field validation error, a label,\n a marker to say whether the field is required, the field description, and\n the widget itself (normally just an ``<input />`` element).\n* ``actions`` renders all actions (buttons) on the form. This normally results\n in a row of ``<input type=\"submit\" ... />`` elements.\n\nThus, to use the ``titlelessform`` macro, you could add something like the\nfollowing in a custom form template::\n\n <metal:use use-macro=\"context/@@ploneform-macros/titlelessform\" />\n\nNote that all of the templates mentioned above are customised by\n`plone.app.z3cform`_ to use standard Plone markup (but still retain the same\nmacros), so if you are using that package to configure this one, you should\nlook for the Plone-specific versions there.\n\nTemplate factories\n==================\n\nIf you want to provide an ``IPageTemplate`` adapter to customise the default\npage template used for wrapper views, forms or sub-forms, this package\nprovides helper classes to create an adapter factory for that purpose. You\nshould use these instead of ``z3c.form.form.FormTemplateFactory`` and\n(possibly) ``z3c.form.widget.WidgetTemplateFactory`` to get page templates\nwith Zope 2 semantics. These factories are also `Chameleon`_ aware, if you\nhave `five.pt`_ installed.\n\nThe most commonly used factory is\n``plone.z3cform.templates.ZopeTwoFormTemplateFactory``, which can be used to\nrender a wrapper view or a standalone form.\n\nTo render a wrapped form, you can use\n``plone.z3cform.templates.FormTemplateFactory``, which is closer to the\ndefault ``z3c.form`` version, but adds Chameleon-awareness.\n\nTo render a widget, the default ``WidgetTemplateFactory`` from z3c.form should\nsuffice, but if you need Zope 2 semantics for any reason, you can use\n``plone.z3cform.templates.ZopeTwoWidgetTemplateFactory``.\n\nAs an example, here are the default registrations from this package::\n\n import z3c.form.interfaces\n import plone.z3cform.interfaces\n\n from plone.z3cform.templates import ZopeTwoFormTemplateFactory\n from plone.z3cform.templates import FormTemplateFactory\n\n path = lambda p: os.path.join(os.path.dirname(plone.z3cform.__file__), 'templates', p)\n\n layout_factory = ZopeTwoFormTemplateFactory(path('layout.pt'),\n form=plone.z3cform.interfaces.IFormWrapper\n )\n\n wrapped_form_factory = FormTemplateFactory(path('wrappedform.pt'),\n form=plone.z3cform.interfaces.IWrappedForm,\n )\n\n # Default templates for the standalone form use case\n\n standalone_form_factory = ZopeTwoFormTemplateFactory(path('form.pt'),\n form=z3c.form.interfaces.IForm\n )\n\n subform_factory = FormTemplateFactory(path('subform.pt'),\n form=z3c.form.interfaces.ISubForm\n )\n\nThese are registered in ZCML like so::\n\n <!-- Form templates for wrapped layout use case -->\n <adapter factory=\".templates.layout_factory\" />\n <adapter factory=\".templates.wrapped_form_factory\" />\n\n <!-- Form templates for standalone form use case -->\n <adapter factory=\".templates.standalone_form_factory\" />\n <adapter factory=\".templates.subform_factory\" />\n\nThe widget traverser\n====================\n\nIt is sometimes useful to be able to register a view on a *widget* and be\nable to traverse to that view, for example during a background AJAX request.\nAs an example of widget doing this, see `plone.formwidget.autocomplete`_.\n\nThis package provides a ``++widget++`` namespace traversal adapter which can\nbe used for this purpose. It is looked up on either the form wrapper view,\nor the form itself (in the case of standalone) forms. Thus, if you have a\nform view called ``@@my-form``, with a field called ``myfield``, you could\ntraverse to the widget for that view using::\n\n http://example.com/@@my-form/++widget++myfield\n\nThe widget may be on the form itself, or in a group (fieldset). If it exists\nin multiple groups, the first one found will be used.\n\nThe example above will yield widget, but it is probably not publishable.\nYou would therefore commonly register a view on the widget itself and use\nthat. In this case, ``self.context`` in the view is the widget instance. Such\na view could be looked up with::\n\n http://example.com/@@my-form/++widget++myfield/@@some-view\n\nA caveat about security\n-----------------------\n\nIn Zope 2.12 and later, the security machinery is aware of ``__parent__``\npointers. Thus, traversal and authorisation on ``@@some-view`` in the example\nabove will work just fine for a standard widget. In earlier versions of Zope,\nyou will need to mix acquisition into your widget (which rules out using any\nof the standard ``z3c.form`` widgets). For example::\n\n from Acquisition import Explicit\n from z3c.form.widget import Widget\n\n class MyWidget(Widget, Explicit):\n ...\n\nUnfortunately, in Zope 2.12, this will cause some problems during traversal\nunless you also mix acquisition into the view you registered on the widget\n(``@@some-view`` above). Specifically, you will get an error as the publisher\ntries to wrap the view in the widget.\n\nTo stay compatible with both Zope 2.12+ and earlier versions, you have two\noptions:\n\n* Ensure that you mix acquisition into the view on the widget\n* Ensure that the widget inherits from ``Explicit``, but does *not* provide\n the ``IAcquirer`` interface. This tricks the publisiher into relying on\n ``__parent__`` pointers in Zope 2.12.\n\nTo do the latter, you can use ``implementsOnly()``, e.g.::\n\n from zope.interface import implementsOnly\n from Acquisition import Explicit\n from z3c.form.widget import Widget\n\n ...\n\n class MyWidget(Widget, Explicit):\n implementsOnly(IMyWidget) # or just IWdget from z3c.form\n ...\n\n.. _z3c.form: http://pypi.python.org/pypi/z3c.form\n.. _plone.app.z3cform: http://pypi.python.org/pypi/plone.app.z3cform\n.. _CMF: http://www.zope.org/Products/CMF\n.. _Chameleon: http://pypi.python.org/pypi/Chameleon\n.. _five.pt: http://pypi.python.org/pypi/five.pt\n.. _plone.formwidget.autocomplete: http://pypi.python.org/pypi/plone.formwidget.autocomplete\n\nFieldsets and form extenders\n============================\n\nThe ``plone.z3cform.fieldsets`` package provides support for z3c.form groups\n(fieldsets) and other modifications via \"extender\" adapters. The idea is that\na third party component can modify the fields in the form and the way that\nthey are grouped and ordered.\n\nThis support relies on a mixin class, which is itself a subclass of\nz3c.form's ``GroupForm``::\n\n >>> from plone.z3cform.fieldsets import group, extensible\n\nTo use this, you have to mix it into another form as the *first* base class::\n\n >>> from zope.annotation import IAttributeAnnotatable\n >>> from z3c.form import form, field, tests, group\n >>> from zope.interface import Interface\n >>> from zope.interface import implementer\n >>> from zope import schema\n\n >>> class ITest(Interface):\n ... title = schema.TextLine(title=u\"Title\")\n\n >>> @implementer(ITest, IAttributeAnnotatable)\n ... class Test(object):\n ... # avoid needing an acl_users for this test in Zope 2.10\n ... __allow_access_to_unprotected_subobjects__ = 1\n ...\n ... title = u\"\"\n ... def getPhysicalRoot(self): # needed for template to acquire REQUEST in Zope 2.10\n ... return self\n\n >>> class TestForm(extensible.ExtensibleForm, form.Form):\n ... fields = field.Fields(ITest)\n\nHere, note the order of the base classes. Also note that we use an ordinary\nset of fields directly on the form. This known as the default fieldset.\n\nThis form should work as-is, i.e. we can update it. First we need to fake a\nrequest::\n\n >>> from plone.z3cform.tests import TestRequest\n\n >>> request = TestRequest()\n >>> request.other = {}\n >>> context = Test()\n >>> context.REQUEST = request\n\n >>> form = TestForm(context, request)\n >>> form.update()\n >>> list(form.fields.keys())\n ['title']\n\nNow let's register an adapter that adds two new fields - one in the\ndefault fieldset as the first field, and one in a new group. To do this,\nwe only need to register a named multi-adapter. However, we can use a\nconvenience base class to make it easier to manipulate the fields of the\nform::\n\n >>> from plone.z3cform.fieldsets.interfaces import IFormExtender\n >>> from zope.component import adapter\n >>> from zope.component import provideAdapter\n\n >>> class IExtraBehavior(Interface):\n ... foo = schema.TextLine(title=u\"Foo\")\n ... bar = schema.TextLine(title=u\"Bar\")\n ... baz = schema.TextLine(title=u\"Baz\")\n ... fub = schema.TextLine(title=u\"Fub\")\n ... qux = schema.TextLine(title=u\"Qux\")\n\nOne plausible implementation is to use an annotation to store this data.\n\n::\n\n >>> from zope.annotation import factory\n >>> from zope.annotation.attribute import AttributeAnnotations\n >>> from persistent import Persistent\n >>> @implementer(IExtraBehavior)\n ... @adapter(Test)\n ... class ExtraBehavior(Persistent):\n ...\n ...\n ... foo = u\"\"\n ... bar = u\"\"\n ... baz = u\"\"\n ... fub = u\"\"\n ... qux = u\"\"\n\n >>> ExtraBehavior = factory(ExtraBehavior)\n >>> provideAdapter(ExtraBehavior)\n >>> provideAdapter(AttributeAnnotations)\n\nWe can now write the extender. The base class gives us some helper methods\nto add, remove and move fields. Here, we do a bit of unnecessary work just\nto exercise these methods.\n\n::\n\n >>> @adapter(Test, TestRequest, TestForm) # context, request, form\n ... class ExtraBehaviorExtender(extensible.FormExtender):\n ...\n ... def __init__(self, context, request, form):\n ... self.context = context\n ... self.request = request\n ... self.form = form\n ...\n ... def update(self):\n ... # Add all fields from an interface\n ... self.add(IExtraBehavior, prefix=\"extra\")\n ...\n ... # Remove the fub field\n ... self.remove('fub', prefix=\"extra\")\n ...\n ... all_fields = field.Fields(IExtraBehavior, prefix=\"extra\")\n ...\n ... # Insert fub again, this time at the top\n ... self.add(all_fields.select(\"fub\", prefix=\"extra\"), index=0)\n ...\n ... # Move 'baz' above 'fub'\n ... self.move('baz', before='fub', prefix='extra', relative_prefix='extra')\n ...\n ... # Move 'foo' after 'bar' - here we specify prefix manually\n ... self.move('foo', after='extra.bar', prefix='extra')\n ...\n ... # Remove 'bar' and re-insert into a new group\n ... self.remove('bar', prefix='extra')\n ... self.add(all_fields.select('bar', prefix='extra'), group='Second')\n ...\n ... # Move 'baz' after 'bar'. This means it also moves group.\n ... self.move('extra.baz', after='extra.bar')\n ...\n ... # Remove 'qux' and re-insert into 'Second' group,\n ... # then move it before 'baz'\n ... self.remove('qux', prefix='extra')\n ... self.add(all_fields.select('qux', prefix='extra'), group='Second')\n ... self.move('qux', before='baz', prefix='extra', relative_prefix='extra')\n\n >>> provideAdapter(factory=ExtraBehaviorExtender, name=u\"test.extender\")\n\nWith this in place, let's update the form once again::\n\n >>> form = TestForm(context, request)\n >>> form.update()\n\nAt this point, we should have a set of default fields that represent the\nones set in the adapter::\n\n >>> list(form.fields.keys())\n ['extra.fub', 'title', 'extra.foo']\n\nAnd we should have one group created by the group factory::\n\n >>> form.groups # doctest: +ELLIPSIS\n (<plone.z3cform.fieldsets.group.Group object at ...>,)\n\nNote that the created group is of a subtype of the standard z3c.form group,\nwhich has got support for a separate label and description as well as a\ncanonical name::\n\n >>> isinstance(form.groups[0], group.Group)\n True\n\nThis should have the group fields provided by the adapter as well::\n\n >>> list(form.groups[0].fields.keys())\n ['extra.bar', 'extra.qux', 'extra.baz']\n\nCRUD (Create, Read, Update and Delete) forms\n============================================\n\nThis module provides an abstract base class to create CRUD forms.\nBy default, such forms provide a tabular view of multiple objects, whose\nattributes can be edited in-place.\n\nPlease refer to the ``ICrudForm`` interface for more details.\n\n >>> from plone.z3cform.crud import crud\n\nSetup\n-----\n\n >>> from plone.z3cform.tests import setup_defaults\n >>> setup_defaults()\n\n\nA simple form\n-------------\n\nFirst, let's define an interface and a class to play with:\n\n >>> from zope import interface, schema\n >>> class IPerson(interface.Interface) :\n ... name = schema.TextLine()\n ... age = schema.Int()\n\n >>> @interface.implementer(IPerson)\n ... class Person(object):\n ... def __init__(self, name=None, age=None):\n ... self.name, self.age = name, age\n ... def __repr__(self):\n ... return \"<Person with name=%r, age=%r>\" % (self.name, self.age)\n\nFor this test, we take the the name of our persons as keys in our\nstorage:\n\n >>> storage = {'Peter': Person(u'Peter', 16),\n ... 'Martha': Person(u'Martha', 32)}\n\nOur simple form looks like this:\n\n >>> class MyForm(crud.CrudForm):\n ... update_schema = IPerson\n ...\n ... def get_items(self):\n ... return sorted(storage.items(), key=lambda x: x[1].name)\n ...\n ... def add(self, data):\n ... person = Person(**data)\n ... storage[str(person.name)] = person\n ... return person\n ...\n ... def remove(self, id_item):\n ... id, item = id_item\n ... del storage[id]\n\nThis is all that we need to render a combined edit add form containing\nall our items:\n\n >>> class FakeContext(object):\n ... def absolute_url(self):\n ... return 'http://nohost/context'\n >>> fake_context = FakeContext()\n\n >>> from plone.z3cform.tests import TestRequest\n >>> print(MyForm(fake_context, TestRequest())()) \\\n ... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE\n <div class=\"crud-form\">...Martha...Peter...</div>\n\nEditing items with our form\n---------------------------\n\nBefore we start with editing objects, let's log all events that the\nform fires for us:\n\n >>> from zope.lifecycleevent.interfaces import IObjectModifiedEvent\n >>> from plone.z3cform.tests import create_eventlog\n >>> log = create_eventlog(IObjectModifiedEvent)\n\n >>> request = TestRequest()\n >>> request.form['crud-edit.Martha.widgets.select-empty-marker'] = u'1'\n >>> request.form['crud-edit.Peter.widgets.select-empty-marker'] = u'1'\n >>> request.form['crud-edit.Martha.widgets.name'] = u'Martha'\n >>> request.form['crud-edit.Martha.widgets.age'] = u'55'\n >>> request.form['crud-edit.Peter.widgets.name'] = u'Franz'\n >>> request.form['crud-edit.Peter.widgets.age'] = u'16'\n >>> request.form['crud-edit.form.buttons.edit'] = u'Apply changes'\n >>> html = MyForm(fake_context, request)()\n >>> \"Successfully updated\" in html\n True\n\nTwo modified events should have been fired:\n\n >>> event1, event2 = log.pop(), log.pop()\n >>> storage['Peter'] in (event1.object, event2.object)\n True\n >>> storage['Martha'] in (event1.object, event2.object)\n True\n >>> log\n []\n\nIf we don't make any changes, we'll get a message that says so:\n\n >>> html = MyForm(fake_context, request)()\n >>> \"No changes made\" in html\n True\n >>> log\n []\n\nNow that we renamed Peter to Franz, it would be also nice to have\nFranz use 'Franz' as the id in the storage, wouldn't it?\n\n >>> storage['Peter']\n <Person with name='Franz', age=16>\n\nWe can override the CrudForm's ``before_update`` method to perform a\nrename whenever the name of a person is changed:\n\n >>> class MyRenamingForm(MyForm):\n ... def before_update(self, item, data):\n ... if data['name'] != item.name:\n ... del storage[item.name]\n ... storage[str(data['name'])] = item\n\nLet's rename Martha to Maria. This will give her another key in our\nstorage:\n\n >>> request.form['crud-edit.Martha.widgets.name'] = u'Maria'\n >>> html = MyRenamingForm(fake_context, request)()\n >>> \"Successfully updated\" in html\n True\n >>> log.pop().object == storage['Maria']\n True\n >>> log\n []\n >>> sorted(storage.keys())\n ['Maria', 'Peter']\n\nNext, we'll submit the form for edit, but we'll make no changes.\nInstead, we'll select one time. This shouldn't do anything, since we\nclicked the 'Apply changes' button:\n\n >>> request.form['crud-edit.Maria.widgets.name'] = u'Maria'\n >>> request.form['crud-edit.Maria.widgets.age'] = u'55'\n >>> request.form['crud-edit.Maria.widgets.select'] = [u'selected']\n >>> html = MyRenamingForm(fake_context, request)()\n >>> \"No changes\" in html\n True\n >>> log\n []\n\nAnd what if we do have changes *and* click the checkbox?\n\n >>> request.form['crud-edit.Maria.widgets.age'] = u'50'\n >>> html = MyRenamingForm(fake_context, request)()\n >>> \"Successfully updated\" in html\n True\n >>> log.pop().object == storage['Maria']\n True\n >>> log\n []\n\nIf we omit the name, we'll get an error:\n\n >>> request.form['crud-edit.Maria.widgets.name'] = u''\n >>> html = MyRenamingForm(fake_context, request)()\n >>> \"There were some errors\" in html\n True\n >>> \"Required input is missing\" in html\n True\n\nWe expect an error message in the title cell of Maria:\n\n >>> checkbox_pos = html.index('crud-edit.Maria.widgets.select-empty-marker')\n >>> \"Required input is missing\" in html[checkbox_pos:]\n True\n\nDelete an item with our form\n----------------------------\n\nWe can delete an item by selecting the item we want to delete and\nclicking the \"Delete\" button:\n\n >>> request = TestRequest()\n >>> request.form['crud-edit.Peter.widgets.select'] = ['selected']\n >>> request.form['crud-edit.form.buttons.delete'] = u'Delete'\n >>> html = MyForm(fake_context, request)()\n >>> \"Successfully deleted items\" in html\n True\n >>> 'Franz' in html\n False\n >>> storage\n {'Maria': <Person with name='Maria', age=50>}\n\nAdd an item with our form\n-------------------------\n\n >>> from zope.lifecycleevent.interfaces import IObjectCreatedEvent\n >>> from plone.z3cform.tests import create_eventlog\n >>> log = create_eventlog(IObjectCreatedEvent)\n\n >>> request = TestRequest()\n >>> request.form['crud-add.form.widgets.name'] = u'Daniel'\n >>> request.form['crud-add.form.widgets.age'] = u'28'\n >>> request.form['crud-add.form.buttons.add'] = u'Add'\n >>> html = MyForm(fake_context, request)()\n >>> \"Item added successfully\" in html\n True\n\nAdded items should show up right away:\n\n >>> \"Daniel\" in html\n True\n\n >>> storage['Daniel']\n <Person with name='Daniel', age=28>\n >>> log.pop().object == storage['Daniel']\n True\n >>> log\n []\n\nWhat if we try to add \"Daniel\" twice? Our current implementation of\nthe add form will simply overwrite the data:\n\n >>> save_daniel = storage['Daniel']\n >>> html = MyForm(fake_context, request)()\n >>> \"Item added successfully\" in html\n True\n >>> save_daniel is storage['Daniel']\n False\n >>> log.pop().object is storage['Daniel']\n True\n\nLet's implement a class that prevents this:\n\n >>> class MyCarefulForm(MyForm):\n ... def add(self, data):\n ... name = data['name']\n ... if name not in storage:\n ... return super(MyCarefulForm, self).add(data)\n ... else:\n ... raise schema.ValidationError(\n ... u\"There's already an item with the name '%s'\" % name)\n\n >>> save_daniel = storage['Daniel']\n >>> html = MyCarefulForm(fake_context, request)()\n >>> \"Item added successfully\" in html\n False\n >>> \"There's already an item with the name 'Daniel'\" in html\n True\n >>> save_daniel is storage['Daniel']\n True\n >>> len(log) == 0\n True\n\nRender some of the fields in view mode\n--------------------------------------\n\nWe can implement in our form a ``view_schema`` attribute, which will\nthen be used to view information in our form's table. Let's say we\nwanted the name of our persons to be viewable only in the table:\n\n >>> from z3c.form import field\n >>> class MyAdvancedForm(MyForm):\n ... update_schema = field.Fields(IPerson).select('age')\n ... view_schema = field.Fields(IPerson).select('name')\n ... add_schema = IPerson\n\n >>> print(MyAdvancedForm(fake_context, TestRequest())()) \\\n ... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE\n <div class=\"crud-form\">...Daniel...Maria...</div>\n\nWe can still edit the age of our Persons:\n\n >>> request = TestRequest()\n >>> request.form['crud-edit.Maria.widgets.age'] = u'40'\n >>> request.form['crud-edit.Daniel.widgets.age'] = u'35'\n >>> request.form['crud-edit.form.buttons.edit'] = u'Apply Changes'\n >>> html = MyAdvancedForm(fake_context, request)()\n >>> \"Successfully updated\" in html\n True\n\n >>> storage['Maria'].age\n 40\n >>> storage['Daniel'].age\n 35\n\nWe can still add a Person using both name and age:\n\n >>> request = TestRequest()\n >>> request.form['crud-add.form.widgets.name'] = u'Thomas'\n >>> request.form['crud-add.form.widgets.age'] = u'28'\n >>> request.form['crud-add.form.buttons.add'] = u'Add'\n >>> html = MyAdvancedForm(fake_context, request)()\n >>> \"Item added successfully\" in html\n True\n >>> len(storage)\n 3\n >>> storage['Thomas']\n <Person with name='Thomas', age=28>\n\nOur form can also contain links to our items:\n\n >>> class MyAdvancedLinkingForm(MyAdvancedForm):\n ... def link(self, item, field):\n ... if field == 'name':\n ... return 'http://en.wikipedia.org/wiki/%s' % item.name\n\n >>> print(MyAdvancedLinkingForm(fake_context, TestRequest())()) \\\n ... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE\n <div class=\"crud-form\">...\n ...<a href=\"http://en.wikipedia.org/wiki/Daniel\"...\n ...<a href=\"http://en.wikipedia.org/wiki/Maria\"...\n ...<a href=\"http://en.wikipedia.org/wiki/Thomas\"...\n </div>\n\nWhat if we wanted the name to be both used for linking to the item\n*and* for edit? We can just include the title field twice:\n\n >>> class MyAdvancedLinkingForm(MyAdvancedLinkingForm):\n ... update_schema = IPerson\n ... view_schema = field.Fields(IPerson).select('name')\n ... add_schema = IPerson\n\n >>> print(MyAdvancedLinkingForm(fake_context, TestRequest())()) \\\n ... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE\n <div class=\"crud-form\">...\n ...<a href=\"http://en.wikipedia.org/wiki/Thomas\"...Thomas...</a>...\n </div>\n\nWe can now change Thomas's name and see the change reflected in the\nWikipedia link immediately:\n\n >>> request = TestRequest()\n >>> for name in 'Daniel', 'Maria', 'Thomas':\n ... request.form['crud-edit.%s.widgets.name' % name] = storage[name].name\n ... request.form['crud-edit.%s.widgets.age' % name] = storage[name].age\n >>> request.form['crud-edit.Thomas.widgets.name'] = u'Dracula'\n >>> request.form['crud-edit.form.buttons.edit'] = u'Apply Changes'\n\n >>> print(MyAdvancedLinkingForm(fake_context, request)()) \\\n ... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE\n <div class=\"crud-form\">...\n ...<a href=\"http://en.wikipedia.org/wiki/Dracula\"...Dracula...</a>...\n </div>\n >>> storage['Thomas'].name = u'Thomas'\n\nDon't render one part\n---------------------\n\nWhat if we wanted our form to display only one part, that is, only the\nadd *or* the edit form. Our CrudForm can implement\n``editform_factory`` and ``addform_factory`` to override one or both\nforms. Setting one of these to ``crud.NullForm`` will make them\ndisappear:\n\n >>> class OnlyEditForm(MyForm):\n ... addform_factory = crud.NullForm\n >>> html = OnlyEditForm(fake_context, TestRequest())()\n >>> 'Edit' in html, 'Add' in html\n (True, False)\n\n >>> class OnlyAddForm(MyForm):\n ... editform_factory = crud.NullForm\n >>> html = OnlyAddForm(fake_context, TestRequest())()\n >>> 'Edit' in html, 'Add' in html\n (False, True)\n\nRender only in view, and define own actions\n-------------------------------------------\n\nSometimes you want to present a list of items, possibly in view mode\nonly, and have the user select one or more of the items to perform\nsome action with them. We'll present a minimal example that does this\nhere.\n\nWe can simply leave the ``update_schema`` class attribute out (it\ndefaults to ``None``). Furthermore, we'll need to override the\nediform_factory with our custom version that provides other buttons\nthan the 'edit' and 'delete' ones:\n\n >>> from pprint import pprint\n >>> from z3c.form import button\n\n >>> class MyEditForm(crud.EditForm):\n ... @button.buttonAndHandler(u'Capitalize', name='capitalize')\n ... def handle_capitalize(self, action):\n ... self.status = u\"Please select items to capitalize first.\"\n ... selected = self.selected_items()\n ... if selected:\n ... self.status = u\"Capitalized items\"\n ... for id, item in selected:\n ... item.name = item.name.upper()\n\n >>> class MyCustomForm(crud.CrudForm):\n ... view_schema = IPerson\n ... editform_factory = MyEditForm\n ... addform_factory = crud.NullForm # We don't want an add part.\n ...\n ... def get_items(self):\n ... return sorted(storage.items(), key=lambda x: x[1].name)\n\n >>> request = TestRequest()\n >>> html = MyCustomForm(fake_context, TestRequest())()\n >>> \"Delete\" in html, \"Apply changes\" in html, \"Capitalize\" in html\n (False, False, True)\n >>> pprint(storage)\n {'Daniel': <Person with name='Daniel', age=35>,\n 'Maria': <Person with name='Maria', age=40>,\n 'Thomas': <Person with name='Thomas', age=28>}\n\n >>> request.form['crud-edit.Thomas.widgets.select'] = ['selected']\n >>> request.form['crud-edit.form.buttons.capitalize'] = u'Capitalize'\n >>> html = MyCustomForm(fake_context, request)()\n >>> \"Capitalized items\" in html\n True\n >>> pprint(storage)\n {'Daniel': <Person with name='Daniel', age=35>,\n 'Maria': <Person with name='Maria', age=40>,\n 'Thomas': <Person with name='THOMAS', age=28>}\n\nWe *cannot* use any of the other buttons:\n\n >>> del request.form['crud-edit.form.buttons.capitalize']\n >>> request.form['crud-edit.form.buttons.delete'] = u'Delete'\n >>> html = MyCustomForm(fake_context, request)()\n >>> \"Successfully deleted items\" in html\n False\n >>> 'Thomas' in storage\n True\n\nCustomizing sub forms\n---------------------\n\nThe EditForm class allows you to specify an editsubform_factory-a class\ninherits from EditSubForm. This allows you to say, override the crud-row.pt\npage template and customize the look of the fields.\n\n >>> import zope.schema\n >>> class MyCustomEditSubForm(crud.EditSubForm):\n ...\n ... def _select_field(self):\n ... \"\"\"I want to customize the field that it comes with...\"\"\"\n ... select_field = field.Field(\n ... zope.schema.TextLine(__name__='select',\n ... required=False,\n ... title=u'select'))\n ... return select_field\n\n >>> class MyCustomEditForm(MyEditForm):\n ... editsubform_factory = MyCustomEditSubForm\n\n >>> class MyCustomFormWithCustomSubForm(MyCustomForm):\n ... editform_factory = MyCustomEditForm\n\n >>> request = TestRequest()\n >>> html = MyCustomFormWithCustomSubForm(fake_context, TestRequest())()\n\nStill uses same form as before\n >>> \"Delete\" in html, \"Apply changes\" in html, \"Capitalize\" in html\n (False, False, True)\n\nJust changes the widget used for selecting...\n >>> 'type=\"checkbox\"' in html\n False\n\nUsing batching\n--------------\n\nThe CrudForm base class supports batching. When setting the\n``batch_size`` attribute to a value greater than ``0``, we'll only get\nas many items displayed per page.\n\n >>> class MyBatchingForm(MyForm):\n ... batch_size = 2\n >>> request = TestRequest()\n >>> html = MyBatchingForm(fake_context, request)()\n >>> \"Daniel\" in html, \"Maria\" in html\n (True, True)\n >>> \"THOMAS\" in html\n False\n\nMake sure, the batch link to the next page is available\n\n >>> 'crud-edit.form.page=1' in html\n True\n\nShow next page and check content\n\n >>> request = TestRequest(QUERY_STRING='crud-edit.form.page=1')\n >>> request.form['crud-edit.form.page'] = '1'\n >>> html = MyBatchingForm(fake_context, request)()\n >>> \"Daniel\" in html, \"Maria\" in html\n (False, False)\n >>> \"THOMAS\" in html\n True\n\nThe form action also includes the batch page information so\nthe correct set of subforms can be processed::\n\n >>> print(html) \\\n ... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE\n <BLANKLINE>\n ...\n <form action=\"http://nohost/context?crud-edit.form.page=1\"\n method=\"post\"...\n\nLet's change Thomas' age on the second page:\n\n >>> request.form['crud-edit.Thomas.widgets.name'] = u'Thomas'\n >>> request.form['crud-edit.Thomas.widgets.age'] = '911'\n >>> request.form['crud-edit.form.buttons.edit'] = u'Apply changes'\n >>> html = MyBatchingForm(fake_context, request)()\n >>> \"Successfully updated\" in html\n True\n >>> \"911\" in html\n True\n\nChangelog\n=========\n\n.. You should *NOT* be adding new change log entries to this file.\n You should create a file in the news directory instead.\n For helpful instructions, please see:\n https://github.com/plone/plone.releaser/blob/master/ADD-A-NEWS-ITEM.rst\n\n.. towncrier release notes start\n\n2.0.2 (2023-10-07)\n------------------\n\nInternal:\n\n\n- Update configuration files.\n [plone devs] (cfffba8c)\n\n\n2.0.1 (2023-03-21)\n------------------\n\nInternal:\n\n\n- Update configuration files.\n [plone devs] (a533099d)\n\n\n2.0.0 (2022-11-23)\n------------------\n\nBug fixes:\n\n\n- Final release for Plone 6.0.0. [maurits] (#600)\n\n\n2.0.0b1 (2022-06-23)\n--------------------\n\nBug fixes:\n\n\n- Fix traversal to `z3c.form.widget.MultiWidget` widgets.\n [petschki] (#22)\n\n\n2.0.0a3 (2022-05-24)\n--------------------\n\nBug fixes:\n\n\n- cleanup crud-table markup\n [petschki] (#21)\n\n\n2.0.0a2 (2022-03-23)\n--------------------\n\nNew features:\n\n\n- compatibility with z3c.form >= 4.x\n [petschki] (#20)\n\n\n2.0.0a1 (2021-04-21)\n--------------------\n\nBreaking changes:\n\n\n- Update for Plone 6 with Bootstrap markup\n Refs PLIP https://github.com/plone/Products.CMFPlone/issues/3061\n [petschki, ale-rt, agitator] (#16)\n\n\n1.1.3 (2020-06-16)\n------------------\n\nBug fixes:\n\n\n- Copy the HTTPRequest._decode from Zope4 because it is going away in Zope5 (#13)\n\n\n1.1.2 (2020-04-21)\n------------------\n\nBug fixes:\n\n\n- Buttons in crud-table should be list items.\n [erral] (#9)\n\n\n1.1.1 (2019-10-12)\n------------------\n\nBug fixes:\n\n- Fix edit/delete in paginated crud-forms [fRiSi]\n\n\n1.1.0 (2019-04-09)\n------------------\n\nNew features:\n\n- Change license to GPLv2\n [petschki]\n\n- Enable ``:record[s]`` fields in ``z2.processInputs``\n [petschki]\n\n- Cosmetic tweaks.\n [gforcada]\n\n1.0.0 (2018-11-04)\n------------------\n\nNew features:\n\n- Support for Python 3\n [pbauer, davilima6, ale-rt, jensens]\n\nBug fixes:\n\n- Test cleanup.\n [jensens]\n\n- Rename folder templates to pagetemplates, because of ZCML browser directive warnings.\n [jensens]\n\n- Removal of tuple parameter unpacking in method definition (Fixes #14)\n [ale-rt]\n\n- Provide an up-to-date bootstrap.py\n [ale-rt]\n\n- Use the adapter and implementer decorators\n [ale-rt]\n\n\n\n0.9.1 (2017-09-03)\n------------------\n\nBug fixes:\n\n- Remove deprecated __of__ calls on BrowserViews\n [MrTango]\n\n\n0.9.0 (2016-05-25)\n------------------\n\nNew:\n\n- Enable groups aka fieldsets to be orderable.\n [jensens]\n\nFixes:\n\n- Fix batching navigation in CRUD form.\n [petschki]\n\n- Added two missing German translations.\n One of those fixes https://github.com/plone/Products.CMFPlone/issues/1580\n [jensens]\n\n- QA: pep8. [maurits, thet]\n\n\n0.8.1 (2015-01-22)\n------------------\n\n- Feature: take group class from parent-form if given. If not given it uses\n the default class.\n [jensens]\n\n- Added Ukrainian translation\n [kroman0]\n\n- Added Italian translation\n [giacomos]\n\n\n0.8.0 (2012-08-30)\n------------------\n\n* Remove backwards-compatibility code for Zope < 2.12\n [davisagli]\n\n* Use plone.testing for functional test layer support.\n [hannosch]\n\n* Use ViewPageTemplateFile from zope.browserpage.\n [hannosch]\n\n* Use form action URL as given by the view, instead of implementing it\n in the template as a call to the ``getURL`` method of the request.\n [malthe]\n\n* Use plone.batching for batches instead of z3c.batching\n [tom_gross]\n\n0.7.8 - 2011-09-24\n------------------\n\n* Do not display h1 element if there is no label on view.\n [thomasdesvenain]\n\n* Add Chinese translation.\n [jianaijun]\n\n0.7.7 - 2011-06-30\n------------------\n\n* Avoid rendering a wrapped form if a redirect has already occurred after\n updating it.\n [davisagli]\n\n* Remove <a name=\"\"/> elements from inside the CRUD table TBODY element\n they were otherwise unused (and illegal in that location of the HTML content\n model).\n [mj]\n\n0.7.6 - 2011-05-17\n------------------\n\n* Add ability to find widgets with non-integer names in lists. This shouldn't\n generally be something that happens, and ideally should be removed if\n DataGridField looses it's 'AA' and 'TT' rows.\n [lentinj]\n\n0.7.5 - 2011-05-03\n------------------\n\n* Fix traversal tests on Zope 2.10 to handle TraversalError instead of\n LocationError.\n [elro]\n\n* Fix traversal.py syntax to be python2.4 compatible.\n\n* Revert [120798] as it breaks on Zope2.10 / Plone 3.3. We can deal with Zope\n 2.14 in 0.8.x.\n [elro]\n\n0.7.4 - 2011-05-03\n------------------\n\n* Define 'hidden' within field macro.\n [elro]\n\n* Ignore \"form.widgets.\" if ++widget++ path begins with it.\n [lentinj]\n\n* Rework traverser to handle lists and subforms\n [lentinj]\n\n* Only search a group's widgets if they exist. collective.z3cform.wizard doesn't\n create widgets for pages/groups other than the current one\n [lentinj, elro]\n\n* Deal with forward compatibility with Zope 2.14.\n\n* Adds Brazilian Portuguese translation.\n [davilima6]\n\n0.7.3 - 2011-03-02\n------------------\n\n* Handle wrong fieldnames more cleanly in the ++widget++ traverser.\n [elro]\n\n0.7.2 - 2011-02-17\n------------------\n\n* Make sure the CRUD add form doesn't use a standalone template.\n [davisagli]\n\n0.7.1 - 2011-01-18\n---------------------\n\n* Add zope.app.testing to test dependencies so that it continues to work under\n Zope 2.13.\n [esteele]\n\n0.7.0 - 2010-08-04\n------------------\n\n* Add a marker interface which can be used by widgets to defer any security\n checks they may be doing when they are set up during traversal with the\n ++widgets++ namespace\n [dukebody]\n\n* Fix re-ordering of fields not in the default fieldset. Thanks to Thomas\n Buchberger for the patch.\n [optilude]\n\n* Added Norwegian translation.\n [regebro]\n\n0.6.0 - 2010-04-20\n------------------\n\n* In the CRUD table, fix odd/even labels, which were reversed.\n [limi]\n\n* Added slots to the ``titlelessform`` macro. See ``README.txt`` for details.\n [optilude, davisagli]\n\n* Remove the distinction between wrapped and unwrapped subforms. A subform is\n always wrapped by the form that contains it, and can use a Zope 3 page\n template.\n [davisagli]\n\n* Fixed tests in Plone 3.\n [davisagli]\n\n* Fixed tests in Plone 4\n [optilude]\n\n* Made it possible to distinguish wrapped and unwrapped forms via the\n IWrappedForm marker interface.\n [optilude]\n\n* Made it possible to use z3c.form forms without a FormWrapper in Plone 4.\n [optilude]\n\n0.5.10 - 2010-02-01\n-------------------\n\n* A z3c.form.form.AddForm do a redirect in its render method.\n So we have to render the form to see if we have a redirection.\n In the case of redirection, we don't render the layout at all.\n This version remove the contents method on FormWrapper,\n it's now an attribute set during the FormWrapper.update.\n This change fixes status message not shown because it was consumed by\n the never shown rendered form.\n [vincentfretin]\n\n0.5.9 - 2010-01-08\n------------------\n\n* Fix security problem with the ++widget++ namespace\n [optilude]\n\n0.5.8 - 2009-11-24\n------------------\n\n* Don't do the rendering if there is a redirection, use the update/render\n pattern for that.\n See http://dev.plone.org/plone/ticket/10022 for an example how\n to adapt your code, in particular if you used FormWrapper with ViewletBase.\n [vincentfretin]\n\n0.5.7 - 2009-11-17\n------------------\n\n* Fix silly doctests so that they don't break in Python 2.6 / Zope 2.12\n [optilude]\n\n0.5.6 - 2009-09-25\n------------------\n\n* Added title_required msgid in macros.pt to be the same as plone.app.z3cform\n because macros.pt from plone.app.z3cform uses plone.z3cform translations.\n Added French translation and fixed German and Dutch translations\n for label_required and title_required messages.\n [vincentfretin]\n\n0.5.5 - 2009-07-26\n------------------\n\n* Removed explicit <includeOverrides /> call from configure.zcml. This causes\n race condition type errors in ZCML loading when overrides are included\n later.\n [optilude]\n\n0.5.4 - 2009-04-17\n------------------\n\n* Added monkey patch to fix a bug in z3c.form's ChoiceTerms on z3c.form 1.9.0.\n [optilude]\n\n* Fix obvious bugs and dodgy naming in SingleCheckBoxWidget.\n [optilude]\n\n* Use chameleon-based page templates from five.pt if available.\n [davisagli]\n\n* Copied the basic textlines widget from z3c.form trunk for use until\n it is released.\n [davisagli]\n\n0.5.3 - 2008-12-09\n------------------\n\n* Add translation marker for batch, update translation files.\n [thefunny42]\n\n* Handle changed signature for widget extract method in z3c.form > 1.9.0\n [davisagli]\n\n* Added wildcard support to the 'before' and 'after' parameters of the\n fieldset 'move' utility function.\n [davisagli]\n\n* Fixes for Zope 2.12 compatibility.\n [davisagli]\n\n* Don't display an 'Apply changes' button if you don't define an\n update_schema.\n [thefunny42]\n\n* Declare xmlnamespace into 'layout.pt' and 'subform.pt' templates\n\n* Added support for an editsubform_factory for an EditForm so you can\n override the default behavior for a sub form now.\n\n* Changed css in crud-table.pt for a table to \"listing\" so that tables\n now look like plone tables.\n\n* Copy translation files to an english folder, so if your browser\n negotiate to ``en,nl``, you will get english translations instead of\n dutch ones (like expected).\n [thefunny42]\n\n* Send an event IAfterWidgetUpdateEvent after updating display widgets\n manually in a CRUD form.\n [thefunny42]\n\n0.5.2 - 2008-08-28\n------------------\n\n* Add a namespace traversal adapter that allows traversal to widgets. This\n is useful for AJAX calls, for example.\n\n0.5.1 - 2008-08-21\n------------------\n\n* Add batching to ``plone.z3cform.crud`` CrudForm.\n\n* Look up the layout template as an IPageTemplate adapter. This means that\n it is possible for Plone to provide a \"Ploneish\" default template for forms\n that don't opt into this, without those forms having a direct Plone\n dependency.\n\n* Default to the titleless form template, since the layout template will\n provide a title anyway.\n\n* In ``plone.z3cform.layout``, allow labels to be defined per form\n instance, and not only per form class.\n\n0.5.0 - 2008-07-30\n------------------\n\n* No longer depend on <3.5 of zope.component.\n\n0.4 - 2008-07-25\n----------------\n\n* Depend on zope.component<3.5 to avoid ``TypeError(\"Missing\n 'provides' attribute\")`` error.\n\n* Allow ICrudForm.add to raise ValidationError, which allows for\n displaying a user-friendly error message.\n\n* Make the default layout template CMFDefault- compatible.\n\n0.3 - 2008-07-24\n----------------\n\n* Moved Plone layout wrapper to ``plone.app.z3cform.layout``. If you\n were using ``plone.z3cform.base.FormWrapper`` to get the Plone\n layout before, you'll have to use\n ``plone.app.z3cform.layout.FormWrapper`` instead now. (Also, make\n sure you include plone.app.z3cform's ZCML in this case.)\n\n* Move out Plone-specific subpackages to ``plone.app.z3cform``. These\n are:\n\n - wysywig: Kupu/Plone integration\n\n - queryselect: use z3c.formwidget.query with Archetypes\n\n Clean up testing code and development ``buildout.cfg`` to not pull\n in Plone anymore.\n [nouri]\n\n* Relicensed under the ZPL 2.1 and moved into the Zope repository.\n [nouri]\n\n* Add German translation.\n [saily]\n\n0.2 - 2008-06-20\n----------------\n\n* Fix usage of NumberDataConverter with zope.i18n >= 3.4 as the\n previous test setup was partial and did not register all adapters\n from z3c.form (some of them depends on zope >= 3.4)\n [gotcha, jfroche]\n\n* More tests\n [gotcha, jfroche]\n\n0.1 - 2008-05-21\n----------------\n\n* Provide and *register* default form and subform templates. These\n allow forms to be used with the style provided in this package\n without having to declare ``form = ViewPageTemplateFile('form.pt')``.\n\n This does not hinder you from overriding with your own ``form``\n attribute like usual. You can also still register a more\n specialized IPageTemplate for your form.\n\n* Add custom FileUploadDataConverter that converts a Zope 2 FileUpload\n object to a Zope 3 one before handing it to the original\n implementation. Also add support for different enctypes.\n [skatja, nouri]\n\n* Added Archetypes reference selection widget (queryselect)\n [malthe]\n\n* Moved generic Zope 2 compatibility code for z3c.form and a few\n goodies from Singing & Dancing into this new package.\n [nouri]\n\n",
"bugtrack_url": null,
"license": "GPL version 2",
"summary": "plone.z3cform is a library that allows use of z3c.form with Zope and the CMF.",
"version": "2.0.2",
"project_urls": {
"Homepage": "https://github.com/plone/plone.z3cform"
},
"split_keywords": [
"plone",
"cmf",
"python",
"zope",
"cms",
"webapplication"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cdea4de1718a2d54b798d8b81686cf38877d7c788a56e553652d961569689b7f",
"md5": "b049a1d852963b8412e9f00fcb9d7420",
"sha256": "3ec2bd2b838de065935f4ed58f0e09f36c8f37652e6136e96f07dc8a00f9004f"
},
"downloads": -1,
"filename": "plone.z3cform-2.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b049a1d852963b8412e9f00fcb9d7420",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 89709,
"upload_time": "2023-10-06T22:48:52",
"upload_time_iso_8601": "2023-10-06T22:48:52.933407Z",
"url": "https://files.pythonhosted.org/packages/cd/ea/4de1718a2d54b798d8b81686cf38877d7c788a56e553652d961569689b7f/plone.z3cform-2.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1e830312ccd065aae31a77ef8cd79a9c89f7ae9e73ef9b72d0702d8b417c5cee",
"md5": "206a9983852f2fd773a4aa5c9f28cf55",
"sha256": "e0278bf77ea7d43300ea079b077a3f159820c5f0956a0295d71a1b4a836a3bce"
},
"downloads": -1,
"filename": "plone.z3cform-2.0.2.tar.gz",
"has_sig": false,
"md5_digest": "206a9983852f2fd773a4aa5c9f28cf55",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 89730,
"upload_time": "2023-10-06T22:48:55",
"upload_time_iso_8601": "2023-10-06T22:48:55.190569Z",
"url": "https://files.pythonhosted.org/packages/1e/83/0312ccd065aae31a77ef8cd79a9c89f7ae9e73ef9b72d0702d8b417c5cee/plone.z3cform-2.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-06 22:48:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "plone",
"github_project": "plone.z3cform",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "plone.z3cform"
}