Skip to main content

Introduces experimental schema.Object support for plone.autoform and

Project description

schema.Object made simple

This package introduces an experimental proof-of-concept support for object-fields (zope.schema.Object) on z3c.form and Plone for a use-case where one desires to save schema based hierarchical data on objects.

I can’t say, why anyone would like to do that (instead of mapping data to containers and items), but I hope this package provides examples, how to make object-fields work with plone.autoform and Plone’s KSS-validation.

This package

  • provides ISubformFactory for object-widget within IAutoExtensibleForm
  • implements simple Plone-style input and display widgets for object-field
  • introduces refactored KSS-validation integration with support for object-field
  • monkeypatches plone.z3cform’s widget traversal to support object-widgets
  • overrides default DataConverter for ObjectWidget’s with a less invasive one
  • provides a simple abstract factory class to store object-fields’ values as SimpleItem-properties.

Note that this package relies on and IPloneFormLayer it registers.

Example of Use

At first we define a simple schema we’d like to re-use as a part of other schemas:

from zope import schema
from zope.interface import invariant, Invalid

from plone.directives import form

from zope.i18nmessageid import MessageFactory as ZopeMessageFactory
_= ZopeMessageFactory("my.package")

class StartBeforeEnd(Invalid):
    __doc__ = _(u"The start or end date is invalid")

class IPeriod(form.Schema):
    start = schema.Date(
                default=u"Period began"),

    end = schema.Date(
                default=u"Period ended"),

    def validateStartEnd(data):
        if data.start is not None and data.end is not None:
            if data.start > data.end:
                raise StartBeforeEnd(\
                    _(u"The start date must be before the end date."))

Then we define the main schema, which re-uses the first schema:

class IWorkPeriod(form.Schema):
    title = schema.TextLine(
    description = schema.TextLine(
    period = schema.Object(

Finally, we register an object factor, which creates SimpleItem matching our schema for z3c.form to validate and store as a property of the actual object being created or edited:

from five import grok

from zope.interface import Interface

from z3c.form.interfaces import IObjectFactory

from jyu.formwidget.object.factory import AbstractBaseFactory

from my.package.schemas import IPeriod

class PeriodFactory(AbstractBaseFactory, grok.MultiAdapter):
    grok.adapts(Interface, Interface, Interface, Interface)

To be able to test this, you should, of course, also define and register a new content type based on the main schema (e.g. with Dexterity).


1.0b7 - 2011-02-23

  • Fixed datamanager to work as attribute field by default to fix problems with and plone.namedfile.

1.0b6 - 2011-01-28

  • Added note about problems of and plone.namedfile.

1.0b5 - 2011-01-24

  • Merged changes from (0.5.3) to

1.0b4 - 2011-01-19

  • Fixed datamanager to initialize object attribute also when it already exists with None.

1.0b3 - 2011-01-07

  • Fixed validator and data converter to handle sub object field.

1.0b2 - 2010-12-23

  • Refactored to use custom DataConverter and DataManager instead of the one shipped with z3c.form.

1.0b1 - 2010-12-20

  • Initial release

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for jyu.formwidget.object, version 1.0b7
Filename, size File type Python version Upload date Hashes
Filename, size (19.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page