Package: plone.autoform
plone.autoformContentsplone.autoformIntroductionBasic schema-based formsControlling form presentationChanging a field’s display modeOmitting fieldsRe-ordering fieldsOrganizing fields into fieldsetsChanging a field’s widgetProtect a field with a permissionDisplay FormsBehind the scenes: how autoform directives workSource CodeChangelog2.0.2 (2024-01-19)2.0.1 (2023-03-22)2.0.0 (2022-11-23)2.0.0a1 (2022-03-23)1.9.0 (2020-04-20)1.8.2 (2020-03-09)1.8.1 (2018-10-31)1.8.0 (2018-09-26)1.7.5 (2018-02-04)1.7.4 (2017-11-24)1.7.3 (2017-06-03)1.7.2 (2017-04-01)1.7.1 (2017-02-12)1.7.0 (2016-06-07)1.6.2 (2016-02-20)1.6.1 (2014-10-20)1.6 (2014-02-22)1.5 (2013-08-14)1.4 (2013-05-23)1.3 (2012-08-30)1.2 (2012-04-15)1.1 - 2012-02-201.0 - 2011-05-131.0b7 - 2011-04-291.0b6 - 2011-02-111.0b5 - 2011-01-111.0b4 - 2010-08-051.0b3 - 2010-04-201.0b2 - 2009-07-121.0b1 - 2009-04-17Introductionplone.autoformbuilds customz3c.formforms based on a model (schema)
of what fields to include and what widgets and options should be used for each
field. This model is defined as azope.schema-based schema, but additional
hints can be supplied to control aspects of form display not normally specified
in a Zope schema.Basic schema-based formsTo use the automatic form setup, mix in the following base class in your
forms:>>> from plone.autoform.form import AutoExtensibleFormand then provide theschema(a schema interface) and optionally theadditionalSchemata(a list of schema interfaces) attributes on your form:class MyForm(AutoExtensibleForm, form.EditForm):
    schema = IMySchema
    additionalSchemata = (ISchemaOne, ISchemaTwo,)
    # ...For dynamic forms, you could of course makeschemaandadditionalSchematainto properties. For example,plone.dexterityextends the
basic AutoExtensibleForm so thatschemais the content type schema andadditionalSchematais a list of field provider schemas associated with
behaviors.Controlling form presentationDirectives can be specified in the schema to control aspects of form presentation.Changing a field’s display modeA field’s widget can be displayed in several “modes”:input - allows the user to enter data into the fielddisplay - a read-only indication of the field’s valuehidden - a record of the field’s value that is included only in the HTML sourceThe mode can be controlled using themodedirective:from plone.supermodel import model
from plone.autoform import directives as form

class IMySchema(model.Schema):

    form.mode(secret='hidden')
    form.mode(IEditForm, secret='input')
    secret = schema.TextLine(
        title=u"Secret",
        default=u"Secret stuff (except on edit forms)"
        )In this case the mode for thesecretfield is set to ‘hidden’ for most forms,
but ‘input’ for forms that provide the IEditForm interface.The corresponding supermodel XML directive isform:mode:<field type="zope.schema.TextLine"
        name="secret"
        form:mode="z3c.form.interfaces.IForm:hidden z3c.form.interfaces.IEditForm:input">
    <title>Secret</title>
    <description>Secret stuff (except on edit forms)</description>
</field>The mode can be specified briefly if it should be the same for all forms:<field type="zope.schema.TextLine"
        name="secret"
        form:mode="hidden">
    <title>Secret</title>
    <description>Secret stuff</description>
</field>In other words,form:modemay be either a single mode, or a space-separated
list of form_interface:mode pairs.Omitting fieldsA field can be omitted entirely from all forms, or from some forms,
using theomittedandno_omitdirectives. In this example,
thedummyfield is omitted from all forms, and theedit_onlyfield is omitted from all forms except those that provide the
IEditForm interface:from z3c.form.interfaces import IEditForm
from plone.supermodel import model
from plone.autoform import directives as form

class IMySchema(model.Schema):

    form.omitted('dummy')
    dummy = schema.Text(
        title=u"Dummy"
        )

    form.omitted('edit_only')
    form.no_omit(IEditForm, 'edit_only')
    edit_only = schema.TextLine(
        title = u'Only included on edit forms',
        )In supermodel XML, this can be specified as:<field type="zope.schema.TextLine"
       name="dummy"
       form:omitted="true">
    <title>Dummy</title>
</field>

<field type="zope.schema.TextLine"
       name="edit-only"
       form:omitted="z3c.form.interfaces.IForm:true z3c.form.interfaces.IEditForm:false">
    <title>Only included on edit form</title>
</field>form:omittedmay be either a single boolean value, or a space-separated
list of form_interface:boolean pairs.Re-ordering fieldsA field’s position in the form can be influenced using theorder_beforeandorder_afterdirectives. In this example, thenot_lastfield
is placed before thesummaryfield even though it is defined afterward:from plone.supermodel import model
from plone.autoform import directives as form

class IMySchema(model.Schema):

    summary = schema.Text(
        title=u"Summary",
        description=u"Summary of the body",
        readonly=True
        )

    form.order_before(not_last='summary')
    not_last = schema.TextLine(
        title=u"Not last",
        )The value passed to the directive may be either ‘*’ (indicating before or after
all fields) or the name of another field. Use'.fieldname'to refer to
field in the current schema or a base schema. Prefix with the schema name (e.g.'IDublinCore.title') to refer to a field in another schema. Use an
unprefixed name to refer to a field in the current or the default schema for
the form.In supermodel XML, the directives are calledform:beforeandform:after.
For example:<field type="zope.schema.TextLine"
       name="not_last"
       form:before="*">
    <title>Not last</title>
</field>Organizing fields into fieldsetsFields can be grouped into fieldsets, which will be rendered within an HTML<fieldset>tag. In this example thefooteranddummyfields
are placed within theextrafieldset:from plone.supermodel import model
from plone.autoform import directives as form

class IMySchema(model.Schema):

    model.fieldset('extra',
        label=u"Extra info",
        fields=['footer', 'dummy']
        )

    footer = schema.Text(
        title=u"Footer text",
        )

    dummy = schema.Text(
        title=u"Dummy"
        )In supermodel XML fieldsets are specified by grouping fields within a<fieldset>tag:<fieldset name="extra" label="Extra info">
    <field name="footer" type="zope.schema.TextLine">
        <title>Footer text</title>
    </field>
    <field name="dummy" type="zope.schema.TextLine">
        <title>Dummy</title>
    </field>
</fieldset>Changing a field’s widgetUsually, z3c.form picks a widget based on the type of your field.
You can change the widget using thewidgetdirective if you want
users to enter or view data in a different format. For example,
here we change the widget for thehumanfield to use yes/no
radio buttons instead of a checkbox:from plone.supermodel import model
from plone.autoform import directives as form
from z3c.form.browser.radio import RadioFieldWidget

class IMySchema(model.Schema):
    form.widget('human', RadioFieldWidget)
    human = schema.Bool(
        title = u'Are you human?',
        )You can also pass widget parameters to control attributes of the
widget. For example, here we keep the default widget, but
set a CSS class:from plone.supermodel import model
from plone.autoform import directives as form
from z3c.form.browser.radio import RadioWidget

class IMySchema(model.Schema):
    form.widget('human', klass='annoying')
    human = schema.Bool(
        title = u'Are you human?',
        )In supermodel XML the widget is specified using a<form:widget>tag, which
can have its own elements specifying parameters:<field name="human" type="zope.schema.TextLine">
    <title>Are you human?</title>
    <form:widget type="z3c.form.browser.radio.RadioWidget">
        <klass>annoying</klass>
    </form:widget>
</field>Note: In order to be included in the XML representation of a schema,
widget parameters must be handled by a WidgetExportImportHandler utility.
There is a default one which handles the attributes defined inz3c.form.browser.interfaces.IHTMLFormElement.Protect a field with a permissionBy default, fields are included in the form regardless of the user’s
permissions. Fields can be protected using theread_permissionandwrite_permissiondirectives. The read permission is checked when
the field is in display mode, and the write permission is checked when
the field is in input mode. The permission should be given with its
Zope 3-style name (i.e. cmf.ManagePortal rather than ‘Manage portal’).In this example, thesecretfield is protected by thecmf.ManagePortalpermission as both a read and write permission.
This means that in both display and input modes, the field will
only be included in the form for users who have that permission:from plone.supermodel import model
from plone.autoform import directives as form

class IMySchema(model.Schema):
    form.read_permission(secret='cmf.ManagePortal')
    form.write_permission(secret='cmf.ManagePortal')
    secret = schema.TextLine(
        title = u'Secret',
        )In supermodel XML the directives aresecurity:read-permissionandsecurity:write-permission:<field type="zope.schema.TextLine"
       name="secret"
       security:read-permission="cmf.ManagePortal"
       security:write-permission="cmf.ManagePortal">
    <title>Secret</title>
</field>Display FormsSometimes rather than rendering a form for data entry, you want to display
stored values based on the same schema. This can be done using a “display form.”
The display form renders each field’s widget in “display mode,” which means
that it shows the field value in read-only form rather than as a form input.To use the display form, create a view that extendsWidgetsViewlike this:>>> from plone.autoform.view import WidgetsView
>>> class MyView(WidgetsView):
...     schema = IMySchema
...     additionalSchemata = (ISchemaOne, ISchemaTwo,)
...
...     # ...To render the form, do not override__call__(). Instead, either implement
therender()method, set anindexattribute to a page template or
other callable, or use thetemplateattribute of the<browser:page />ZCML directive when registering the view.In the template, you can use the following variables:view/wis a dictionary of all widgets, including those from non-default
fieldsets (by contrast, thewidgetsvariable contains only those
widgets in the default fieldset). The keys are the field names, and the
values are widget instances. To render a widget (in display mode), you can
dotal:replace="structureview/w/myfield/render" />.view/fieldsetsis a dictionary of all fieldsets (not including the
default fieldset, i.e. those widgets not placed into a fieldset). They keys
are the fieldset names, and the values are the fieldset form instances,
which in turn have variables likewidgetsgiven a list of all widgets.Behind the scenes: how autoform directives workZope schema fields do not allow storing arbitrary key-value data associated
with a particular field. However, arbitrary data can be stored in a
dictionary on the schema (interface) known as the “tagged values.”
This is whereplone.autoformkeeps track of its extra hints,
whether they are configured via Python directives, an XML model, or some
other way.The tagged values are stored under various keys, which are defined
in theplone.autoform.interfacesmodule. They can be set several ways:Manually, by usingsetTaggedValue()on an interface.By loading the schema from aplone.supermodelXML file and using theform:prefixBy using the directives fromplone.autoform.directiveswhile defining
a schema in Python.Source CodeContributors please read the documentProcess for Plone core’s developmentSources are at thePlone code repository hosted at Github.Changelog2.0.2 (2024-01-19)Internal:Update configuration files.
[plone devs] (55bda5c9)2.0.1 (2023-03-22)Internal:Update configuration files.
[plone devs] (243ca9ec)2.0.0 (2022-11-23)Bug fixes:Final release for Plone 6.0.0.  [maurits] (#600)2.0.0a1 (2022-03-23)Breaking changes:Plone 6 only. (#41)New features:Fixes for latest z3c.form
[petschki] (#40)Reimplementation of backported ObjectSubForm and ISubformFactory
[petschki] (#41)1.9.0 (2020-04-20)New features:Support for zope.interface 5.
Seehttps://github.com/zopefoundation/zope.interface/pull/183#issuecomment-599547556[jensens] (#39)1.8.2 (2020-03-09)Bug fixes:Decrease the loglevel of “Field move to non-existing: …” (#21)1.8.1 (2018-10-31)Bug fixes:Remove the dummy security manager on test tear down
[ale-rt]1.8.0 (2018-09-26)New features:Add support for python 3
[pbauer]1.7.5 (2018-02-04)Bug fixes:Prepare for Python 2 / 3 compatibility
[pbauer]Minor fixes on testing that could avoid having test isolation problems.
[gforcada]1.7.4 (2017-11-24)New features:Allow configuration of fieldsets viaplone.supermodelfieldset directives via a schema without fields.
This can be used to create a Plone behavior for stable ordering of fieldsets.
[thet]Add handler registration for text input widgets to support e.g. ‘placeholder’
parameter in parameterized widgets
[datakurre]1.7.3 (2017-06-03)Bug fixes:Reduce field move failure logging from error to warning.
Log more information like full rule.
[jensens]Fix traceback in updateFieldsFromSchemata for forms with no schema.
[davisagli]Clean up code.
[gforcada]Remove unittest2 dependency
[kakshay21]1.7.2 (2017-04-01)New features:Make of tracebacks ofplone.autoform.widgets.ParameterizedWidgetcalls more verbose in order to ease debugging.
[jensens]1.7.1 (2017-02-12)Bug fixes:Make sure WidgetsView doesn’t use acquisition in Zope 4. [davisagli]1.7.0 (2016-06-07)Incompatibilities:Because of the ordering fix the field order in forms may be different.
Before this fix the order was a gamble dependent on schema order.
Schema form hintsorder_afterandorder_beforemay need minor adjustments.plone.autoform.utils.processFieldMoveswas deprecated,
but still works as before.
The new functionality is now part ofplone.autoform.base.AutoFields.
[jensens]New:Fieldset labels/descriptions we’re taken from first occurrence.
It was not possible to override them in a subsequent directive.
Also it was not possible to set them in a subsequent directive, if it was not set before.
Now subsequent directives w/o a label/description are just adding the field to the fieldset.
If a different label and/or description is given, it replaces the existing prior loaded one.
[jensens]The order of the fieldsets can be defined now explicitly with theplone.supermodel.directives.fieldsetdirective.plone.autoformnow does the sorting while fieldset processing.
[jensens]Fixes:Implementation on how field ordering happens was unreproducible if same schemas are coming in in different orders.
New implementation build a well defined rule tree and processes then the field moves,
almost independent from the schema order.
[jensens]Update setup.py url
[esteele]1.6.2 (2016-02-20)Fixes:Fix test for changedzope.interfacecomparison method, which
incorrectly reports two different Interfaces from the same module
but with empty name as being equal.  [thet]1.6.1 (2014-10-20)pep8 cleanup, utf8-header,sorted imports, readability, …
[jensens]Fix issue where multiple (plone.supermodel) fieldset directive calls for the
same fieldset name resulted to duplicate fieldsets (e.g. when updating
fieldset with new fields in a subschema)
[datakurre]1.6 (2014-02-22)Replace deprecated test assert statements.
[timo]Support anonymous schema (dynamic interfaces with and empty
__name__ attribute) in autoGroups, opting to use prefix as
group name for such cases.  This allows subclasses of
AutoExtensibleForm to implement getPrefix() method as
a sufficient condition to support an unnamed schema.
[seanupton]1.5 (2013-08-14)Added an option on form to allow display of empty fieldsets.
[thomasdesvenain]fix tests
[vangheem]1.4 (2013-05-23)Enhance the widget directive to allow for specifying widget parameters
within the schema.
[davisagli]Support passing widget classes in the widget directive in addition to
IFieldWidgets.
[davisagli]Support serializing widget parameters to XML. This requires implementing
a IWidgetExportImportHandler utility for the widget type.
[davisagli]1.3 (2012-08-30)Avoid dependency on z3c.form.testing.
[hannosch]1.2 (2012-04-15)Moved form schema directives here from plone.directives.form, and
reimplemented them as plone.supermodel directives to avoid depending on
grok.  Included directives: omitted, no_omit, mode, widget, order_before,
order_after, read_permission, write_permission
[davisagli]1.1 - 2012-02-20Added the AutoObjectSubForm class to support form hints for
object widget subforms.
[jcbrand]1.0 - 2011-05-13Raise a NotImplementedError instead of NotImplemented as that is not
an exception but meant for comparisons and is not callable.
[maurits]1.0b7 - 2011-04-29Check to make sure that interfaces and field widgets resolved by the
supermodel handler are of the correct type.
[elro]Add form:validator support for supermodel.
[elro]Fix issue where permission checks were not applied correctly to schemas being
added with prefixes.
[davisagli]Add MANIFEST.in.
[WouterVH]1.0b6 - 2011-02-11Fix WidgetsView so that _update and update do not clash.
[elro]Fix view.txt doctest to test actual behaviour, not artifacts from test setup.
[elro]1.0b5 - 2011-01-11Use five.ManageSite permission to check field permissions. We’ll avoid
sniffing for Five/CMFCore permissions.zcml difference between Zope 2.12 and
2.13. [esteele]1.0b4 - 2010-08-05Fixed widget traversal for WidgetsViewhttp://groups.google.com/group/dexterity-development/browse_frm/thread/280016ece3ed1462[29.08.2010, jbaumann]Make field permission checks use the field mode rather than the form mode.
Fixeshttp://code.google.com/p/dexterity/issues/detail?id=110[optilude]Removed some dead code.
Fixeshttp://code.google.com/p/dexterity/issues/detail?id=132[optilude, shywolf9982]1.0b3 - 2010-04-20Properly handle the ‘omitted’ tagged value when it is set to ‘false’ for a
field.
[davisagli]Make it possible to set the ‘omitted’ and ‘mode’ settings only for particular
form interfaces.
[davisagli]Do not omit read-only fields when rendering a form in DISPLAY mode.http://code.google.com/p/dexterity/issues/detail?id=118[mj]1.0b2 - 2009-07-12Changed API methods and arguments to mixedCase to be more consistent with
the rest of Zope. This is a non-backwards-compatible change. Our profuse
apologies, but it’s now or never. :-/If you find that you get import errors or unknown keyword arguments in your
code, please change names from foo_bar too fooBar, e.g. process_fields()
becomes processFields().Note in particular that the additional_schemata property is now called
additionalSchemata. If you have implemented this property yourself, you will
need to rename it!
[optilude]1.0b1 - 2009-04-17Initial release