Skip to content
This repository has been archived by the owner on Apr 9, 2019. It is now read-only.

Commit

Permalink
polish and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Oct 5, 2018
1 parent 1812be3 commit 5e94f5a
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 115 deletions.
16 changes: 8 additions & 8 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
Changelog
=========

0.9.2 (Unreleased)
1.0.0 (Unreleased)
------------------

New features:

- Support for Python 3
[pbauer, davilima6, ale-rt, jensens]

Bug fixes:

- Removal of tuple parameter unpacking in method definition (Fixes #14)
[ale-rt]

- Provide an up-to-date bootstrap.py
- Python 3 compatibility: use the adapter and implementer decorators
[ale-rt]

New features:

- Add support for Python 3
[pbauer]
- Use the adapter and implementer decorators
[ale-rt]

- Prepare for Python 2 / 3 compatibility
[pbauer, davilima6]


0.9.1 (2017-09-03)
Expand Down
29 changes: 14 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
from setuptools import setup, find_packages
import os

__version__ = '0.9.2.dev0'
__version__ = '1.0.0.dev0'


def description():
join = lambda *paths: os.path.join('src', 'plone', 'z3cform', *paths)
return (open('README.rst').read() + '\n' +
open(join('fieldsets', 'README.txt')).read() + '\n' +
open(join('crud', 'README.txt')).read() + '\n' +
open('CHANGES.rst').read() + '\n')
return (
open('README.rst').read()
+ '\n'
+ open(join('fieldsets', 'README.txt')).read()
+ '\n'
+ open(join('crud', 'README.txt')).read()
+ '\n'
+ open('CHANGES.rst').read()
+ '\n'
)


setup(
name='plone.z3cform',
version=__version__,
description="plone.z3cform is a library that allows use of z3c.form "
"with Zope and the CMF.",
"with Zope and the CMF.",
long_description=description(),
classifiers=[
"Framework :: Plone",
"Framework :: Plone :: 4.3",
"Framework :: Plone :: 5.0",
"Framework :: Plone :: 5.1",
"Framework :: Plone :: 5.2",
"Framework :: Zope2",
"Programming Language :: Python",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
Expand All @@ -49,10 +51,7 @@ def description():
'zope.i18n>=3.4',
'zope.browserpage',
'zope.component',
'Zope2',
'Zope',
],
extras_require={
'test': ['lxml',
'plone.testing']
}
extras_require={'test': ['lxml', 'plone.testing']},
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ The ``plone.z3cform.fieldsets`` package provides support for z3c.form groups
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``.
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:
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
Expand All @@ -38,7 +38,7 @@ 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.
request::

>>> from plone.z3cform.tests import TestRequest

Expand All @@ -48,19 +48,14 @@ request.
>>> context.REQUEST = request

>>> form = TestForm(context, request)
>>> try: # Zope 2.10 templates need a proper acquisition chain
... from Acquisition import ImplicitAcquisitionWrapper
... form = ImplicitAcquisitionWrapper(form, context)
... except:
... pass
>>> form.update()
>>> _ = form.render()

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
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.
form::

>>> from plone.z3cform.fieldsets.interfaces import IFormExtender
>>> from zope.component import adapter
Expand All @@ -75,6 +70,8 @@ form.

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
Expand All @@ -88,80 +85,82 @@ One plausible implementation is to use an annotation to store this data.
... 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.

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.
ones set in the adapter::

>>> form.fields.keys()
['extra.fub', 'title', 'extra.foo']
And we should have one group created by the group factory:

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.
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.
This should have the group fields provided by the adapter as well::

>>> form.groups[0].fields.keys()
['extra.bar', 'extra.qux', 'extra.baz']
Loading

0 comments on commit 5e94f5a

Please sign in to comment.