Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to filter values in a RelationList/RelationChoice field in Plone 5? #200

Open
fulv opened this issue Nov 30, 2015 · 2 comments
Open

Comments

@fulv
Copy link
Member

fulv commented Nov 30, 2015

It seems to me that the References page (docs/advanced/references.rst) is not up to date for Plone 5. I have two reasons for this:

  1. I have not been able to get the ObjPathSourceBinder to work in any way. If I pass the RelationChoice field a vocabulary=plone.app.vocabularies.Catalog, all is fine. But I want to filter the vocabularies by any criteria, and the only way I know is to use a (Path | ObjPath | UUID)SourceBinder from plone.formwidget.contenttree, and no matter what I try, I always get an empty list of values to select from.
  2. The RelatedItems behavior in Plone 5 uses a RelatedItemsFieldWidget, which is not mentioned anywhere on that page. Instead, it talks about the AutocompleteFieldWidget, which I'm not sure is still good for Plone 5.

Here is the code for the IRelatedItems behavior, from plone.app.relationfield.behavior version 1.3.2, to illustrate my two points above:

class IRelatedItems(model.Schema):
    """Behavior interface to make a Dexterity type support related items.
    """

    relatedItems = RelationList(
        title=_(u'label_related_items', default=u'Related Items'),
        default=[],
        value_type=RelationChoice(
            title=u"Related",
            vocabulary="plone.app.vocabularies.Catalog"
        ),
        required=False
    )
    form.widget('relatedItems', RelatedItemsFieldWidget,
                vocabulary='plone.app.vocabularies.Catalog')

fieldset = Fieldset('categorization',
                    label=_(u'Categorization'), fields=['relatedItems'])
IRelatedItems.setTaggedValue(FIELDSETS_KEY, [fieldset])

alsoProvides(IRelatedItems, IFormFieldProvider)

What is the new way to do what used to be done with SourceBinders?

@davisagli
Copy link
Sponsor Member

Use plone.app.vocabularies.catalog.CatalogSource; here's an example from the collection portlet for Plone 5: https://github.com/plone/plone.portlet.collection/blob/master/plone/portlet/collection/collection.py#L42

That example is just a simple Choice though rather than a RelationChoice (i.e. it only stores a UID rather than a RelationValue indexed in the relation catalog) so I'm not sure if it will work the same.

@fulv
Copy link
Member Author

fulv commented Nov 30, 2015

CatalogSource works beautifully, thank you!

Now, does that mean that the *SourceBinders are no longer supported in Plone 5? A related question would be whether plone.formwidget.contenttree is even used anymore, given mockup.

I'm just trying to understand how this docs page should be updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants