Skip to main content

Formlib widget for plone.app.relation

The purpose of this extension is to provide formlib widget to edit plone.app.relation relations. This have been tested with Plone 2.5 and Plone 3.

Interface definition

Simple interface for our contents, using the custom Zope 3 field for relation:

>>> from infrae.plone.relations.schema import PloneRelation
>>> from zope.interface import implements, Interface
>>> class ISimpleContent(Interface):
...    """Simple interface with relation."""
...    relation = PloneRelation(title=u"A relation",
...                             relation="relation1")

In the user interface, Zope IntID are used to keep track of object. You can also use Archetype UID (check the configure.zcml file), in this case all content must comes from the Referenceable class of Archetype (Products.Archetypes.Referenceable).

Widget definition

The plone relation widget is customisable, you can select different sub-widgets to select new items to add to relation. These sub-widgets can takes arguments. For instance here, you can put a restriction on content_type.

The widget is built using CustomWidgetFactory:

>>> from infrae.plone.relations.form import PloneRelationEditWidget
>>> from infrae.plone.relations.form import PloneRelationSearchAddWidget
>>> from zope.app.form import CustomWidgetFactory
>>> widget_factory = CustomWidgetFactory(PloneRelationEditWidget,
...                                      add_widget=PloneRelationSearchAddWidget,
...                                      add_widget_args=dict(content_type='MySimpleContent'))

Currently, there is three different widgets to add relations: one which does a catalog search with user input and let select result as object for relation, one which list objects (from the catalog always), one which use a Zope 3 vocabulary as input.

The infrae.plone.relations.form.utility provides simples methods to build these widgets.

Form definition

Now, we will do a simple edit form for a content using this interface:

>>> from Products.Five.formlib import formbase
>>> from zope.formlib import form
>>> class EditSimpleContentForm(formbase.EditForm):
...    label = 'Edit form'
...    description = 'Form to edit relation'
...    form_fields = form.Fields(ISimpleContent)
...    form_fields['relation'].custom_widget = widget_factory

It’s easy ?

Real test

We added this code in the example.py file, and the form would be bind to Document. We load it now:

>>> from Products.Five.zcml import load_string
>>> load_string("""<configure xmlns="http://namespaces.zope.org/browser">
... <page name="relation.html"
...       for="infrae.plone.relations.form.example.IPloneRelationExample"
...       class="infrae.plone.relations.form.example.PloneRelationEditForm"
...       permission="cmf.ModifyPortalContent" />
... </configure>""")

And now get an authenticated browser:

>>> browser = self.getAuthenticatedBrowser()

The front-page is a document, so we should get our form:

>>> browser.open('http://nohost/plone/front-page/relation.html')
>>> 'Plone relation edit form' in browser.contents
True

So we can search for Plone in this add widget, and should get one response, since by default there is only one document with the word Plone, the front page itself:

>>> browser.getControl(name='form.relation.search_value').value='Plone'
>>> browser.getControl(name='form.relation.search_button').click()

And we got some results:

>>> add_value = browser.getControl(name='form.relation.add_value:list')
>>> add_value.getControl('Welcome to Plone').selected = True
>>> browser.getControl(name='form.relation.add_button').click()
>>> browser.getControl('Apply').click()
>>> 'Updated on' in browser.contents
True

You can look up the README.EXT.txt and example.py file for more tests and examples.

Changes

1.0

  • Add more tests,

  • Remove translation marker: they triggers errors under Plone 3. Now this work with Plone 3 as well.

0.9

  • First release, we need more functional or unit test to release 1.0.

Credits

The first version of this widget have been released with the help of the Flemish government of Belgium, for the application <http://www.zonderisgezonder.be>.

You can help us as well to contribute to this product, by sending your remarks or patchs at the author email address (or ask for an SVN access).

Metadata

Release files for infrae.plone.relations.form 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for infrae.plone.relations.form 1.0
File Size Uploaded
infrae.plone.relations.form-1.0.tar.gz 17.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for infrae.plone.relations.form 1.0
File Interpreter ABI Platform
infrae.plone.relations.form-1.0-py2.4.egg Legacy Egg format - - Details

Total release size: 67.1 kB

Release files / infrae.plone.relations.form-1.0.tar.gz

Download URL infrae.plone.relations.form-1.0.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3172453801f7ba8ded86befd5f517456f3d38aa93817e4aed75dc61f4a1ebbfc
BLAKE2b-256 checksum
How to use checksums
e4037a38fd4b6b6dd48f6c1283cbfdd4c8dd67fe65b025b250ae5140d73b1dce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / infrae.plone.relations.form-1.0-py2.4.egg

Download URL infrae.plone.relations.form-1.0-py2.4.egg
Size 49.6 kB
Tags Egg
SHA-256 checksum
How to use checksums
3f91db4851f464d4666ed09bc3409e1dfaf49657f659c381a01dec03ba4fdc0d
BLAKE2b-256 checksum
How to use checksums
80f14cc850060e8515585599bb027bafc05df268b1684b5355440c8c7dcc6302
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0 This release

2 release files

0.9

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page