Skip to content

Commit

Permalink
Fixed Issue #1302
Browse files Browse the repository at this point in the history
  • Loading branch information
czpython committed Mar 19, 2013
1 parent b716020 commit e6402af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cms/models/pluginmodel.py
Expand Up @@ -343,7 +343,7 @@ def is_last_in_placeholder(self):
"""
WARNING: this is a rather expensive call compared to is_first_in_placeholder!
"""
return self.placeholder.cmsplugin_set.all().order_by('-position')[0].pk == self.pk
return self.placeholder.cmsplugin_set.filter(parent__isnull=True).order_by('-position')[0].pk == self.pk

def get_position_in_placeholder(self):
"""
Expand Down
13 changes: 13 additions & 0 deletions cms/tests/plugins.py
Expand Up @@ -698,6 +698,19 @@ def test_moving_plugin_to_different_placeholder(self):
build_plugin_tree(page.placeholders.get(slot='right-column').get_plugins_list())
plugin_pool.unregister_plugin(DumbFixturePlugin)

def test_is_last_in_placeholder(self):
"""
Tests that children plugins don't affect the is_last_in_placeholder plugin method.
"""
page_en = create_page("PluginOrderPage", "col_two.html", "en",
slug="page1", published=True, in_navigation=True)
ph_en = page_en.placeholders.get(slot="col_left")
text_plugin_1 = add_plugin(ph_en, "TextPlugin", "en", body="I'm the first")
text_plugin_2 = add_plugin(ph_en, "TextPlugin", "en", body="I'm the second")
inner_text_plugin_1 = add_plugin(ph_en, "TextPlugin", "en", body="I'm the first child of text_plugin_1")
text_plugin_1.cmsplugin_set.add(inner_text_plugin_1)
self.assertEquals(text_plugin_2.is_last_in_placeholder(), True)


class FileSystemPluginTests(PluginsTestBaseCase):
def setUp(self):
Expand Down

0 comments on commit e6402af

Please sign in to comment.