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

relationchoice not working ... #67

Closed
iham opened this issue Jan 17, 2018 · 6 comments
Closed

relationchoice not working ... #67

iham opened this issue Jan 17, 2018 · 6 comments

Comments

@iham
Copy link

iham commented Jan 17, 2018

from plone.app.vocabularies.catalog import CatalogSource
from z3c.relationfield.schema import RelationChoice
from zope import schema
from zope.interface import Interface

from collective.z3cform.datagridfield import DataGridFieldFactory
from collective.z3cform.datagridfield import DictRow
from plone.autoform import directives
from plone.supermodel import model

class IItemRow(Interface):
    note = schema.TextLine(
        title=u'Note',
        required=True,
        default=u'',
    )
    events = RelationChoice(
        title=u'Event',
        source=CatalogSource(portal_type=['Event']),
        required=True,
    )

class IEventsGroup(model.Schema):
    directives.widget(employees=DataGridFieldFactory)
    employees = schema.List(
        title=u'A list of events with notes.',
        required=False,
        value_type=DictRow(
            title=u'Event',
            schema=IEventRow,
        )
    )

IEventsGroup is a globally addable contenttype.

the widget gets displayed, but when clicking in the relationchoice widget i get a spinner and no result. calling the view "getSource" i get {"error": "Vocabulary lookup not allowed."}
this seems to occur as self.context.context has NO_VALUE

any help?

@thet
Copy link
Member

thet commented Jan 17, 2018

If you want to make use of the related items widget, I'd try not to use a CatalogSource but the following:

# -*- coding: utf-8 -*-
from collective.z3cform.datagridfield import DataGridFieldFactory
from collective.z3cform.datagridfield import DictRow
from plone.app.z3cform.widget import RelatedItemsFieldWidget
from plone.autoform import directives
from plone.supermodel import model
from z3c.relationfield.schema import RelationChoice
from zope import schema
from zope.interface import Interface


class IEventRow(Interface):
    note = schema.TextLine(
        title=u'Note',
        required=True,
        default=u'',
    )

    directives.widget(
        'events',
        RelatedItemsFieldWidget,
        pattern_options={
            'selectableTypes': ['Event'],
        }
    )
    events = RelationChoice(
        title=u'Event',
        vocabulary='plone.app.vocabularies.Catalog',
        required=True,
    )


class IEventsGroup(model.Schema):
    directives.widget(employees=DataGridFieldFactory)
    employees = schema.List(
        title=u'A list of events with notes.',
        required=False,
        value_type=DictRow(
            title=u'Event',
            schema=IEventRow,
        )
    )

@iham
Copy link
Author

iham commented Jan 17, 2018

i will give that a try! thx @thet

@iham
Copy link
Author

iham commented Jan 18, 2018

Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module plone.z3cform.layout, line 66, in __call__
  Module plone.z3cform.layout, line 50, in update
  Module plone.dexterity.browser.edit, line 58, in update
  Module plone.z3cform.fieldsets.extensible, line 59, in update
  Module plone.z3cform.patch, line 30, in GroupForm_update
  Module z3c.form.group, line 132, in update
  Module z3c.form.form, line 136, in updateWidgets
  Module z3c.form.field, line 277, in update
  Module z3c.form.browser.multi, line 63, in update
  Module z3c.form.browser.widget, line 171, in update
  Module z3c.form.widget, line 496, in update
  Module Products.CMFPlone.patches.z3c_form, line 46, in _wrapped
  Module z3c.form.widget, line 132, in update
  Module z3c.form.widget, line 491, in value
  Module collective.z3cform.datagridfield.datagridfield, line 153, in updateWidgets
  Module collective.z3cform.datagridfield.datagridfield, line 127, in getWidget
  Module z3c.form.browser.widget, line 171, in update
  Module z3c.form.object, line 217, in update
  Module z3c.form.object, line 208, in updateWidgets
  Module collective.z3cform.datagridfield.autoform, line 56, in update
  Module plone.z3cform.fieldsets.extensible, line 59, in update
  Module plone.z3cform.patch, line 30, in GroupForm_update
  Module z3c.form.group, line 132, in update
  Module collective.z3cform.datagridfield.datagridfield, line 315, in updateWidgets
  Module collective.z3cform.datagridfield.autoform, line 40, in updateWidgets
  Module z3c.form.form, line 136, in updateWidgets
  Module z3c.form.field, line 277, in update
  Module plone.app.z3cform.widget, line 400, in update
  Module z3c.form.browser.text, line 36, in update
  Module z3c.form.browser.widget, line 171, in update
  Module Products.CMFPlone.patches.z3c_form, line 46, in _wrapped
  Module z3c.form.widget, line 112, in update
  Module zope.schema._field, line 312, in bind
  Module Zope2.App.schema, line 33, in get
  Module plone.app.vocabularies.catalog, line 627, in __call__
AttributeError: 'NO_VALUE' object has no attribute 'getPhysicalPath'

@pbauer
Copy link
Member

pbauer commented Jun 5, 2019

@iham did you get this working? I ran into the same problem today using the current master that includes #71).

@iham
Copy link
Author

iham commented Jun 6, 2019

@pbauer sadly: no. even after hours of desperation and agony ;)

i guess this is broken by concept as complex fields using context don't work. there is no context, so no way to get a catalog, a portal_root or anything at all.

i'd say: YAFOWIL as @rnixx and @jensens are working on that and more and more fields/widgets/forms and types start looking good and useable. this will allow all sorts of complex fields (compounds) and sorting works like a charm (better than z3c.form) and no change in how to write behaviors, forms, ...

@laulaz
Copy link
Member

laulaz commented Mar 15, 2023

Fixed by #150 👍

@laulaz laulaz closed this as completed Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants