Skip to content

Commit

Permalink
Merge 9cef490 into 4b227ec
Browse files Browse the repository at this point in the history
  • Loading branch information
elioschmutz committed Feb 4, 2019
2 parents 4b227ec + 9cef490 commit 40affa7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -6,6 +6,10 @@ Changelog

Bugfixes:

- Do not fail on serializing types with fields having non-parametrized widgets.
Fixes issue `664 <https://github.com/plone/plone.restapi/issues/664>`_.
[elioschmutz]

- Tests: retry request on ConnectionError.
On Jenkins we often get one ConnectionError in a seemingly random test.
Retrying after a short pause helps.
Expand Down
24 changes: 21 additions & 3 deletions src/plone/restapi/tests/test_types.py
Expand Up @@ -18,6 +18,7 @@
from plone.restapi.types.utils import get_jsonschema_for_fti
from plone.restapi.types.utils import get_jsonschema_for_portal_type
from plone.restapi.types.utils import get_jsonschema_properties
from z3c.form.browser.text import TextWidget


class IDummySchema(model.Schema):
Expand Down Expand Up @@ -58,8 +59,13 @@ class ITaggedValuesSchema(model.Schema):
description=u"",
)

another_field = schema.TextLine(title=u"Tagged Values widget params")
form.widget('another_field', a_param='some_value')
parametrized_widget_field = schema.TextLine(
title=u"Parametrized widget field")
form.widget('parametrized_widget_field', a_param='some_value')

not_parametrized_widget_field = schema.TextLine(
title=u"No parametrized widget field")
form.widget(not_parametrized_widget_field=TextWidget)


class TestJsonSchemaUtils(TestCase):
Expand Down Expand Up @@ -182,7 +188,19 @@ def test_get_jsonschema_with_widget_params(self):
)
self.assertEqual(
'some_value',
jsonschema['properties']['another_field']['a_param']
jsonschema['properties']['parametrized_widget_field']['a_param']
)

def test_do_not_fail_with_non_parametrized_widget(self):
ttool = getToolByName(self.portal, 'portal_types')
jsonschema = get_jsonschema_for_fti(
ttool['TaggedDocument'],
self.portal,
self.request
)
self.assertEqual(
u'No parametrized widget field',
jsonschema['properties']['not_parametrized_widget_field']['title']
)


Expand Down
3 changes: 2 additions & 1 deletion src/plone/restapi/types/utils.py
Expand Up @@ -16,6 +16,7 @@
from collections import OrderedDict
from copy import copy
from plone.autoform.form import AutoExtensibleForm
from plone.autoform.interfaces import IParameterizedWidget
from plone.autoform.interfaces import WIDGETS_KEY
from plone.dexterity.utils import getAdditionalSchemata
from plone.restapi.serializer.converters import json_compatible
Expand Down Expand Up @@ -139,7 +140,7 @@ def get_tagged_values(schemas, key):
tagged_values = mergedTaggedValueDict(schema, key)
for field_name in schema:
widget = tagged_values.get(field_name)
if widget and widget.params:
if IParameterizedWidget.providedBy(widget) and widget.params:
params[field_name] = widget.params
return params

Expand Down

0 comments on commit 40affa7

Please sign in to comment.