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

Use AutoExtensibleForm in both Plone 5 and Plone 4 (when applicable) #12

Merged
merged 1 commit into from
Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ Changelog

New:

- *add item here*
- Attempt to use AutoExtensibleForm for as base for static portlet forms
when Plone 4 site also has recent plone.app.widgets; this should be
consistent in portlet with how TinyMCE is configured for Dexterity
content. This approach attempts to harmonize Plone 4 compatibillity
work done previously by @thet and @cdw9 -- supporting Plone 4, either
with/without plone.app.widgets, and with/without plone.app.contenttypes
(provided recent plone.app.widgets is used).
[seanupton]

Fixes:

Expand Down
31 changes: 27 additions & 4 deletions plone/portlet/static/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from plone.app.portlets.portlets import base
from plone.app.textfield import RichText
from plone.app.textfield.value import RichTextValue
from plone.autoform import directives
from plone.autoform.form import AutoExtensibleForm
from plone.i18n.normalizer.interfaces import IIDNormalizer
from plone.portlet.static import PloneMessageFactory as _
from plone.portlets.interfaces import IPortletDataProvider
Expand All @@ -16,15 +18,35 @@
import re

logger = logging.getLogger('plone.portlet.static')
WIDGETS_1X = False
PLONE5 = getFSVersionTuple()[0] >= 5

if PLONE5:
from plone.app.z3cform.widget import RichTextFieldWidget
base_AddForm = base.AddForm
base_EditForm = base.EditForm
else:
from plone.app.portlets.browser.z3cformhelper import AddForm as base_AddForm # noqa
from plone.app.portlets.browser.z3cformhelper import EditForm as base_EditForm # noqa
# PLONE 4 Support:
# Either Plone 4 plus compatible plone.app.widgets, or Plone 4.x without:
from plone.app.portlets.browser import z3cformhelper
from z3c.form import field
try:
from plone.app.widgets.dx import RichTextFieldWidget # req >= 1.9.1+

class base_AddForm(AutoExtensibleForm, z3cformhelper.AddForm):
pass

class base_EditForm(AutoExtensibleForm, z3cformhelper.EditForm):
pass

WIDGETS_1X = True
except ImportError:
WIDGETS_1X = False
base_AddForm = z3cformhelper.AddForm
base_EditForm = z3cformhelper.EditForm


USE_AUTOFORM = PLONE5 or WIDGETS_1X


class IStaticPortlet(IPortletDataProvider):
Expand All @@ -41,6 +63,7 @@ class IStaticPortlet(IPortletDataProvider):
constraint=re.compile("[^\s]").match,
required=False)

directives.widget(text=RichTextFieldWidget)
text = RichText(
title=_(u"Text"),
description=_(u"The text to render"),
Expand Down Expand Up @@ -173,7 +196,7 @@ class AddForm(base_AddForm):
zope.formlib which fields to display. The create() method actually
constructs the assignment that is being added.
"""
if PLONE5:
if USE_AUTOFORM:
schema = IStaticPortlet
else:
fields = field.Fields(IStaticPortlet)
Expand All @@ -194,7 +217,7 @@ class EditForm(base_EditForm):
This is registered with configure.zcml. The form_fields variable tells
zope.formlib which fields to display.
"""
if PLONE5:
if USE_AUTOFORM:
schema = IStaticPortlet
else:
fields = field.Fields(IStaticPortlet)
Expand Down