Skip to content

Commit

Permalink
Allow related items widget to be used in subforms plone/Products.CMFP…
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgross committed Jun 16, 2018
1 parent fbdf968 commit 812d37e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Bug fixes:
brings back the TinyMCE.
[sallner]

- Allow RelatedItems widget to be used in subforms
[tomgross]

3.0.4 (2018-02-04)
------------------
Expand Down
27 changes: 17 additions & 10 deletions plone/app/z3cform/widget.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_base
from Acquisition import ImplicitAcquisitionWrapper
from OFS.interfaces import ISimpleItem
from lxml import etree
from plone.app.textfield.value import RichTextValue
from plone.app.textfield.widget import RichTextWidget as patext_RichTextWidget
Expand Down Expand Up @@ -35,6 +37,7 @@
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.interfaces import IEditingSchema
from Products.CMFPlone.utils import safe_unicode
from six.moves import UserDict
from z3c.form.browser.checkbox import SingleCheckBoxWidget
from z3c.form.browser.select import SelectWidget as z3cform_SelectWidget
from z3c.form.browser.text import TextWidget as z3cform_TextWidget
Expand Down Expand Up @@ -65,12 +68,6 @@
import six


try:
from collections import UserDict
except ImportError:
from UserDict import UserDict


class BaseWidget(Widget):
"""Base widget for z3c.form."""

Expand Down Expand Up @@ -125,6 +122,9 @@ def render(self):
)
return pattern_widget.render()

def is_subform_widget(self):
return getattr(aq_base(self.form), 'parentForm', None) is not None


@implementer_only(IDateWidget)
class DateWidget(BaseWidget, HTMLInputWidget):
Expand Down Expand Up @@ -486,11 +486,18 @@ def _base_args(self):
view_context = get_widget_form(self)
# For EditForms and non-Forms (in tests), the vocabulary is looked
# up on the context, otherwise on the view
if (
IEditForm.providedBy(view_context) or
not IForm.providedBy(view_context)
):
if IEditForm.providedBy(view_context):
if self.is_subform_widget():
view_context = self.form.parentForm.context
elif not ISimpleItem.providedBy(context):
view_context = self.form.context
else:
view_context = context
elif not IForm.providedBy(view_context):
view_context = context
else:
pass
# view_context is defined above already

root_search_mode = (
args['pattern_options'].get('mode', None) and
Expand Down

1 comment on commit 812d37e

@jenkins-plone-org
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomgross Jenkins CI reporting about code analysis
See the full report here: https://jenkins.plone.org/job/package-plone.app.z3cform/110/violations

plone/app/z3cform/inline_validation.py:15:5: C901 'InlineValidationView.__call__' is too complex (15)
plone/app/z3cform/widget.py:5:1: I001 isort found an import in the wrong position
plone/app/z3cform/widget.py:667:19: T000 Todo note found.
plone/app/z3cform/widget.py:681:47: T000 Todo note found.
plone/app/z3cform/converters.py:106:11: T000 Todo note found.

Follow these instructions to reproduce it locally.

Please sign in to comment.