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

@types endpoint will fail with types with fields defining non-parametrized widgets #664

Closed
elioschmutz opened this issue Feb 4, 2019 · 0 comments
Assignees

Comments

@elioschmutz
Copy link
Member

Having a type with a schema defining the following field:

form.widget(field1=TextWidget)
field1 = schema.TextLine(title=u"Tagged Values widget params")

and requesting:

curl -H "Accept: application/json" --user "admin:admin" "http://localhost:8080/Plone/@types/MyType

will raise the following error:

  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module plone.rest.service, line 23, in __call__
  Module plone.restapi.services, line 19, in render
  Module plone.restapi.services.types.get, line 53, in reply
  Module plone.restapi.types.utils, line 206, in get_jsonschema_for_portal_type
  Module plone.restapi.types.utils, line 175, in get_jsonschema_for_fti
  Module plone.restapi.types.utils, line 141, in get_tagged_values
AttributeError: 'str' object has no attribute 'params'

Problem

To set a widget of a field, you'll use plone.autoforms widget-directive (https://github.com/plone/plone.autoform/blob/master/plone/autoform/directives.py#L76). If you take a closer look at this function, you'll see, that there are two different possibilities, how to set a widget.

The first on is to pass keyword-args

widget(field1='z3c.form.browser.text.TextWidget', field2=TextWidget)

The second is to pass positional-args:

widget('field1', TextWidget, label=u'My label')

Using positional-args will create a ParameterizedWidget-factory (https://github.com/plone/plone.autoform/blob/master/plone/autoform/directives.py#L137). Using the keyword-args will generate a string to identify the widget (https://github.com/plone/plone.autoform/blob/master/plone/autoform/directives.py#L129).

The get_tagged_values-function will fail (https://github.com/plone/plone.restapi/blob/master/src/plone/restapi/types/utils.py#L142) if you set a widget through keyword-args, because this function assumes a ParametrizedWidget factory.

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

1 participant