Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install jyu.formwidget.object

How to install jyu.formwidget.object

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install jyu.formwidget.object
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.0b7 Available View build log
1.0b6 Available View build log
1.0b4 Available View build log
1.0b3 Available View build log
1.0b2 Available View build log
1.0b1 Available View build log
Windows (64-bit)
1.0b7 Available View build log
1.0b6 Available View build log
1.0b4 Available View build log
1.0b3 Available View build log
1.0b2 Available View build log
1.0b1 Available View build log
Mac OS X (10.5+)
1.0b7 Available View build log
1.0b6 Available View build log
1.0b4 Available View build log
1.0b3 Available View build log
1.0b2 Available View build log
1.0b1 Available View build log
Linux (32-bit)
1.0b7 Available View build log
1.0b6 Available View build log
1.0b4 Available View build log
1.0b3 Available View build log
1.0b2 Available View build log
1.0b1 Available View build log
Linux (64-bit)
1.0b7 Available View build log
1.0b6 Available View build log
1.0b4 Available View build log
1.0b3 Available View build log
1.0b2 Available View build log
1.0b1 Available View build log
 
Author
License
GPL
Lastest release
version 1.0b7 on Feb 23rd, 2011

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'

System Message: WARNING/2 (<string>, line 22)

Bullet list ends without a blank line; unexpected unindent.

values as SimpleItem-properties.

Note that this package relies on plone.app.z3cform 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:

System Message: WARNING/2 (<string>, line 32)

Literal block expected; none found.

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( title=_(u"period_start_label", default=u"Period began"), required=True )

end = schema.Date( title=_(u"period_end_label", default=u"Period ended"), required=True )

@invariant 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:

System Message: WARNING/2 (<string>, line 67)

Literal block expected; none found.

class IWorkPeriod(form.Schema): title = schema.TextLine( title=_(u"work_title_label", default=u"Title"), required=True ) description = schema.TextLine( title=_(u"work_description_label", default=u"Description"), required=False ) period = schema.Object( title=_(u"work_period", default=u"Period"), schema=IPeriod, required=True )

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:

System Message: WARNING/2 (<string>, line 89)

Literal block expected; none found.

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.provides(IObjectFactory) grok.name("my.package.schemas.IPeriod") 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).

Changelog

1.0b7 - 2011-02-23
  • Fixed datamanager to work as attribute field by default to

System Message: WARNING/2 (<string>, line 116)

Bullet list ends without a blank line; unexpected unindent.

fix problems with plone.app.textfield and plone.namedfile.

1.0b6 - 2011-01-28
  • Added note about problems of plone.app.textfield and plone.namedfile.
1.0b5 - 2011-01-24
  • Merged changes from plone.app.z3form (0.5.3) to validation.py.
1.0b4 - 2011-01-19
  • Fixed datamanager to initialize object attribute also when it

System Message: WARNING/2 (<string>, line 132)

Bullet list ends without a blank line; unexpected unindent.

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

System Message: WARNING/2 (<string>, line 143)

Bullet list ends without a blank line; unexpected unindent.

the one shipped with z3c.form.

1.0b1 - 2010-12-20
  • Initial release

Subscribe to package updates

Last updated Feb 23rd, 2011

Download Stats

Last month:5

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.