Skip to content

Commit

Permalink
Merge pull request #356 from plone/fix_behavior_marker
Browse files Browse the repository at this point in the history
Fix behavior subtemplate: use separate marker interface
  • Loading branch information
jensens committed Mar 2, 2019
2 parents 9fd35de + 5723cc2 commit 5a31ca7
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 19 deletions.
10 changes: 9 additions & 1 deletion CHANGES.rst
Expand Up @@ -4,7 +4,15 @@ Changelog
3.6.1 (unreleased)
------------------

- Nothing changed yet.
- Fix some confusion in setup.py classifiers and depenencies due to introduction of Plone 5.2 support.
Introduces plone.is_plone5.2 variable.
[jensens]

- Fix behavior template: use separate marker interface,
register marker in the behavior zcml and adapt content to the marker, not to IDexterityContent.
For further reference, see the plone.behavior README.rst Example 2.
Fixes #16.
[fredvd, jensens]


3.6.0 (2019-02-25)
Expand Down
22 changes: 19 additions & 3 deletions bobtemplates/plone/addon/setup.py.bob
Expand Up @@ -21,15 +21,25 @@ setup(
classifiers=[
"Environment :: Web Environment",
"Framework :: Plone",
"Framework :: Plone :: Addon",
{{% if not plone.is_plone5 %}}
"Framework :: Plone :: 4.3",
{{% endif %}}
{{% if plone.is_plone5 %}}
"Framework :: Plone :: 5.0",
{{% endif %}}
{{% if plone.is_plone51 %}}
"Framework :: Plone :: 5.1",
{{% endif %}}
{{% if plone.is_plone52 %}}
"Framework :: Plone :: 5.2",
{{% endif %}}
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
{{% if plone.is_plone52 %}}
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
{{% endif %}}
"Operating System :: OS Independent",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
],
Expand All @@ -44,11 +54,15 @@ setup(
include_package_data=True,
zip_safe=False,
install_requires=[
# -*- Extra requirements: -*-
'plone.api>=1.8.4',
'Products.GenericSetup>=1.8.2',
'setuptools',
# -*- Extra requirements: -*-
'z3c.jbot',
{{% if not (plone.is_plone51 or plone.is_plone52 %}}
'Products.GenericSetup>=1.8.2',
{{% endif %}}
{{% if not plone.is_plone52 %}}
'plone.api>=1.8.4',
{{% endif %}}
{{% if not plone.is_plone5 %}}
'plone.app.dexterity<=2.1.1',
'plone.app.referenceablebehavior',
Expand All @@ -60,10 +74,12 @@ setup(
extras_require={
'test': [
'plone.app.testing',
{{% if not plone.is_plone52 %}}
# Plone KGS does not use this version, because it would break
# Remove if your package shall be part of coredev.
# plone_coredev tests as of 2016-04-01.
'plone.testing>=5.0.0',
{{% endif %}}
{{% if plone.is_plone5 %}}
'plone.app.contenttypes',
{{% endif %}}
Expand Down
Expand Up @@ -19,15 +19,15 @@ class TestSetup(unittest.TestCase):
def setUp(self):
"""Custom shared utility setup for tests."""
self.portal = self.layer['portal']
{{% if plone.is_plone51 %}}
{{% if plone.is_plone51 or plone.is_plone52 %}}
self.installer = get_installer(self.portal, self.layer['request'])
{{% else %}}
self.installer = api.portal.get_tool('portal_quickinstaller')
{{% endif %}}

def test_product_installed(self):
"""Test if {{{ package.dottedname }}} is installed."""
{{% if plone.is_plone51 %}}
{{% if plone.is_plone51 or plone.is_plone52 %}}
self.assertTrue(self.installer.is_product_installed(
'{{{ package.dottedname }}}'))
{{% else %}}
Expand All @@ -51,14 +51,14 @@ class TestUninstall(unittest.TestCase):

def setUp(self):
self.portal = self.layer['portal']
{{% if plone.is_plone51 %}}
{{% if plone.is_plone51 or plone.is_plone52 %}}
self.installer = get_installer(self.portal, self.layer['request'])
{{% else %}}
self.installer = api.portal.get_tool('portal_quickinstaller')
{{% endif %}}
roles_before = api.user.get_roles(TEST_USER_ID)
setRoles(self.portal, TEST_USER_ID, ['Manager'])
{{% if plone.is_plone51 %}}
{{% if plone.is_plone51 or plone.is_plone52 %}}
self.installer.uninstall_product('{{{ package.dottedname }}}')
{{% else %}}
self.installer.uninstallProducts(['{{{ package.dottedname }}}'])
Expand All @@ -67,7 +67,7 @@ class TestUninstall(unittest.TestCase):

def test_product_uninstalled(self):
"""Test if {{{ package.dottedname }}} is cleanly uninstalled."""
{{% if plone.is_plone51 %}}
{{% if plone.is_plone51 or plone.is_plone52 %}}
self.assertFalse(self.installer.is_product_installed(
'{{{ package.dottedname }}}'))
{{% else %}}
Expand Down
13 changes: 5 additions & 8 deletions bobtemplates/plone/base.py
Expand Up @@ -240,16 +240,13 @@ def set_plone_version_variables(configurator, answer=None):
return
if 'plone.is_plone5' not in configurator.variables:
# Find out if it is supposed to be Plone 5.
if version.startswith('5'):
configurator.variables['plone.is_plone5'] = True
else:
configurator.variables['plone.is_plone5'] = False
configurator.variables['plone.is_plone5'] = version.startswith('5')
if 'plone.is_plone51' not in configurator.variables:
# Find out if it is supposed to be Plone 5.1 or higher
if version.startswith('5.1') or version.startswith('5.2'):
configurator.variables['plone.is_plone51'] = True
else:
configurator.variables['plone.is_plone51'] = False
configurator.variables['plone.is_plone51'] = version.startswith('5.1')
if 'plone.is_plone52' not in configurator.variables:
# Find out if it is supposed to be Plone 5.2 or higher
configurator.variables['plone.is_plone52'] = version.startswith('5.2')
if 'plone.minor_version' not in configurator.variables:
# extract minor version (4.3)
# (according to https://plone.org/support/version-support-policy)
Expand Down
2 changes: 1 addition & 1 deletion bobtemplates/plone/behavior.py
Expand Up @@ -70,7 +70,7 @@ def _update_behaviors_configure_zcml(configurator):
description="{description}"
provides=".{normalized_name}.I{klass_name}"
factory=".{normalized_name}.{klass_name}"
marker=".{normalized_name}.I{klass_name}"
marker=".{normalized_name}.I{klass_name}Marker"
/>
""".format(
Expand Down
Expand Up @@ -10,6 +10,9 @@ from zope.interface import implementer
from zope.interface import provider


class I{{{behavior_name_klass}}}Marker:
pass

@provider(IFormFieldProvider)
class I{{{behavior_name_klass}}}(model.Schema):
"""
Expand All @@ -23,7 +26,7 @@ class I{{{behavior_name_klass}}}(model.Schema):


@implementer(I{{{behavior_name_klass}}})
@adapter(IDexterityContent)
@adapter(I{{{behavior_name_klass}}}Marker)
class {{{behavior_name_klass}}}(object):
def __init__(self, context):
self.context = context
Expand Down
16 changes: 16 additions & 0 deletions package-tests/test_base.py
Expand Up @@ -105,6 +105,20 @@ def test_set_plone_version_variables(tmpdir):
base.set_plone_version_variables(configurator)
assert configurator.variables.get('plone.is_plone5')
assert not configurator.variables.get('plone.is_plone51')
assert not configurator.variables.get('plone.is_plone52')
assert configurator.variables.get('plone.minor_version') == '5'

configurator = Configurator(
template='bobtemplates.plone:addon',
target_directory=target_dir,
variables={
'plone.version': '5.2',
},
)
base.set_plone_version_variables(configurator)
assert configurator.variables.get('plone.is_plone5')
assert not configurator.variables.get('plone.is_plone51')
assert not configurator.variables.get('plone.is_plone52')
assert configurator.variables.get('plone.minor_version') == '5'

configurator = Configurator(
Expand All @@ -117,6 +131,7 @@ def test_set_plone_version_variables(tmpdir):
base.set_plone_version_variables(configurator)
assert configurator.variables.get('plone.is_plone5')
assert configurator.variables.get('plone.is_plone51')
assert not configurator.variables.get('plone.is_plone52')
assert configurator.variables.get('plone.minor_version') == '5.1'

configurator = Configurator(
Expand All @@ -129,6 +144,7 @@ def test_set_plone_version_variables(tmpdir):
base.set_plone_version_variables(configurator)
assert not configurator.variables.get('plone.is_plone5')
assert not configurator.variables.get('plone.is_plone51')
assert not configurator.variables.get('plone.is_plone52')
assert configurator.variables.get('plone.minor_version') == '4.3'


Expand Down

0 comments on commit 5a31ca7

Please sign in to comment.