Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix 983 #984

Merged
merged 2 commits into from

2 participants

@ojii
Collaborator

Fixed #983

@chrisglass chrisglass merged commit a85e488 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 2, 2011
  1. @ojii

    Added test for #983

    ojii authored
  2. @ojii

    Fixed #983

    ojii authored
This page is out of date. Refresh to see the latest.
Showing with 47 additions and 8 deletions.
  1. +5 −1 cms/plugin_pool.py
  2. +42 −7 cms/tests/placeholder.py
View
6 cms/plugin_pool.py
@@ -77,10 +77,14 @@ def get_all_plugins(self, placeholder=None, page=None, setting_key="plugins", in
plugins = self.plugins.values()[:]
plugins.sort(key=lambda obj: unicode(obj.name))
final_plugins = []
+ if page:
+ template = page.get_template()
+ else:
+ template = None
allowed_plugins = get_placeholder_conf(
setting_key,
placeholder,
- getattr(page, 'template', None)
+ template,
)
for plugin in plugins:
include_plugin = False
View
49 cms/tests/placeholder.py
@@ -1,21 +1,22 @@
# -*- coding: utf-8 -*-
from __future__ import with_statement
-from cms.api import add_plugin
+from cms.api import add_plugin, create_page
+from cms.conf.global_settings import CMS_TEMPLATE_INHERITANCE_MAGIC
from cms.exceptions import DuplicatePlaceholderWarning
from cms.models.placeholdermodel import Placeholder
-from cms.plugins.text.models import Text
+from cms.plugin_pool import plugin_pool
from cms.plugin_rendering import render_placeholder
+from cms.plugins.link.cms_plugins import LinkPlugin
from cms.plugins.text.cms_plugins import TextPlugin
+from cms.plugins.text.models import Text
from cms.test_utils.fixtures.fakemlng import FakemlngFixtures
-from cms.test_utils.testcases import CMSTestCase
+from cms.test_utils.testcases import CMSTestCase, TestCase
from cms.test_utils.util.context_managers import (SettingsOverride,
UserLoginContext)
from cms.test_utils.util.mock import AttributeObject
-from cms.utils.placeholder import PlaceholderNoAction, MLNGPlaceholderActions
+from cms.utils.placeholder import (PlaceholderNoAction, MLNGPlaceholderActions,
+ get_placeholder_conf)
from cms.utils.plugins import get_placeholders
-from cms.api import create_page, add_plugin
-from cms.models import Placeholder
-from cms.plugins.text.cms_plugins import TextPlugin
from django.conf import settings
from django.contrib import admin
from django.contrib.auth.models import User, Permission
@@ -494,3 +495,37 @@ def test_plugin_edit_requires_permissions(self):
# It looks like it breaks here because of a missing csrf token in the request
# I have no idea how to fix this
self.assertEqual(response.status_code, HttpResponse.status_code)
+
+
+class PlaceholderConfTests(TestCase):
+ def test_get_all_plugins_single_page(self):
+ page = create_page('page', 'col_two.html', 'en')
+ placeholder = page.placeholders.get(slot='col_left')
+ conf = {
+ 'col_two': {
+ 'plugins': ['TextPlugin', 'LinkPlugin'],
+ },
+ 'col_two.html col_left': {
+ 'plugins': ['LinkPlugin'],
+ },
+ }
+ with SettingsOverride(CMS_PLACEHOLDER_CONF=conf):
+ plugins = plugin_pool.get_all_plugins(placeholder, page)
+ self.assertEqual(len(plugins), 1, plugins)
+ self.assertEqual(plugins[0], LinkPlugin)
+ def test_get_all_plugins_inherit(self):
+ parent = create_page('parent', 'col_two.html', 'en')
+ page = create_page('page', CMS_TEMPLATE_INHERITANCE_MAGIC, 'en', parent=parent)
+ placeholder = page.placeholders.get(slot='col_left')
+ conf = {
+ 'col_two': {
+ 'plugins': ['TextPlugin', 'LinkPlugin'],
+ },
+ 'col_two.html col_left': {
+ 'plugins': ['LinkPlugin'],
+ },
+ }
+ with SettingsOverride(CMS_PLACEHOLDER_CONF=conf):
+ plugins = plugin_pool.get_all_plugins(placeholder, page)
+ self.assertEqual(len(plugins), 1, plugins)
+ self.assertEqual(plugins[0], LinkPlugin)
Something went wrong with that request. Please try again.