Skip to content

Commit

Permalink
Merge pull request #5378 from piotrjakimiak/fix-5371
Browse files Browse the repository at this point in the history
Fix #5371. Properly check parent_classes in get_child_classes
  • Loading branch information
czpython committed Jun 6, 2016
2 parents 5eeaa73 + 0657855 commit 53fd43e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cms/plugin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def get_child_plugin_candidates(cls, slot, page):
# Useful in cases like djangocms-text-ckeditor
# where only text only plugins are allowed.
from cms.plugin_pool import plugin_pool
return plugin_pool.get_all_plugins(slot, page)
return plugin_pool.get_all_plugins()

def get_child_classes(self, slot, page):
"""
Expand Down
33 changes: 33 additions & 0 deletions cms/tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,39 @@ def test_plugin_parent_classes_from_settings(self):
self.assertEqual(['TestPlugin'],
plugin.get_parent_classes(placeholder.slot, page))

def test_plugin_parent_classes_from_object(self):
page = api.create_page("page", "nav_playground.html", "en", published=True)
placeholder = page.placeholders.get(slot='body')
ParentPlugin = type('ParentPlugin', (CMSPluginBase,),
dict(render_plugin=False))
ChildPlugin = type('ChildPlugin', (CMSPluginBase,),
dict(parent_classes=['ParentPlugin'], render_plugin=False))

with register_plugins(ParentPlugin, ChildPlugin):
plugin = api.add_plugin(placeholder, ParentPlugin, settings.LANGUAGES[0][0])
plugin = plugin.get_plugin_class_instance()
## assert baseline
child_classes = plugin.get_child_classes(placeholder.slot, page)
self.assertIn('ChildPlugin', child_classes)
self.assertIn('ParentPlugin', child_classes)

def test_plugin_require_parent_from_object(self):
page = api.create_page("page", "nav_playground.html", "en", published=True)
placeholder = page.placeholders.get(slot='body')
ParentPlugin = type('ParentPlugin', (CMSPluginBase,),
dict(render_plugin=False))
ChildPlugin = type('ChildPlugin', (CMSPluginBase,),
dict(require_parent=True, render_plugin=False))

with register_plugins(ParentPlugin, ChildPlugin):
plugin = api.add_plugin(placeholder, ParentPlugin, settings.LANGUAGES[0][0])
plugin = plugin.get_plugin_class_instance()
## assert baseline
child_classes = plugin.get_child_classes(placeholder.slot, page)
self.assertIn('ChildPlugin', child_classes)
self.assertIn('ParentPlugin', child_classes)


def test_plugin_translatable_content_getter_setter(self):
"""
Test that you can add a text plugin
Expand Down

0 comments on commit 53fd43e

Please sign in to comment.