Skip to content

Commit eef5cbb

Browse files
chaoskczpython
authored andcommitted
Removed default plugin creation for placeholders (#6468)
1 parent 71a68e1 commit eef5cbb

File tree

6 files changed

+5
-236
lines changed

6 files changed

+5
-236
lines changed

cms/tests/test_permmod.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -186,27 +186,6 @@ def test_slave_can_add_page_under_slave_home(self):
186186
# approve / publish as user_slave
187187
# user master should be able to approve as well
188188

189-
@override_settings(
190-
CMS_PLACEHOLDER_CONF={
191-
'col_left': {
192-
'default_plugins': [
193-
{
194-
'plugin_type': 'TextPlugin',
195-
'values': {
196-
'body': 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Culpa, repellendus, delectus, quo quasi ullam inventore quod quam aut voluptatum aliquam voluptatibus harum officiis officia nihil minus unde accusamus dolorem repudiandae.'
197-
},
198-
},
199-
]
200-
},
201-
},
202-
)
203-
def test_default_plugins(self):
204-
with self.login_user_context(self.user_slave):
205-
self.assertEqual(CMSPlugin.objects.count(), 0)
206-
response = self.client.get(self.slave_page.get_absolute_url(), {'edit': 1})
207-
self.assertEqual(response.status_code, 200)
208-
self.assertEqual(CMSPlugin.objects.count(), 1)
209-
210189
def test_page_added_by_slave_can_be_published_by_user_master(self):
211190
# add page
212191
page = create_page("page", "nav_playground.html", "en",

cms/tests/test_placeholder.py

Lines changed: 3 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -457,14 +457,7 @@ def test_get_placeholder_conf(self):
457457
'main': {
458458
'name': 'main content',
459459
'plugins': ['TextPlugin', 'LinkPlugin'],
460-
'default_plugins': [
461-
{
462-
'plugin_type': 'TextPlugin',
463-
'values': {
464-
'body': '<p>Some default text</p>'
465-
},
466-
},
467-
],
460+
'require_parent': False,
468461
},
469462
'layout/home.html main': {
470463
'name': u'main content with FilerImagePlugin and limit',
@@ -499,8 +492,8 @@ def test_get_placeholder_conf(self):
499492
returned = get_placeholder_conf('excluded_plugins', 'main', 'layout/other.html')
500493
self.assertEqual(returned, TEST_CONF['layout/other.html main']['excluded_plugins'])
501494
# test grandparent inherited value
502-
returned = get_placeholder_conf('default_plugins', 'main', 'layout/other.html')
503-
self.assertEqual(returned, TEST_CONF['main']['default_plugins'])
495+
returned = get_placeholder_conf('require_parent', 'main', 'layout/other.html')
496+
self.assertEqual(returned, TEST_CONF['main']['require_parent'])
504497
# test generic configuration
505498
returned = get_placeholder_conf('plugins', 'something')
506499
self.assertEqual(returned, TEST_CONF[None]['plugins'])
@@ -595,79 +588,6 @@ def test_placeholder_field_dynamic_slot_update(self):
595588
self.assertEqual(old_placeholder_1_plugin_count, current_placeholder_1_plugin_count)
596589
self.assertEqual(old_placeholder_2_plugin_count, current_placeholder_2_plugin_count)
597590

598-
def test_plugins_prepopulate(self):
599-
""" Tests prepopulate placeholder configuration """
600-
601-
conf = {
602-
'col_left': {
603-
'default_plugins' : [
604-
{
605-
'plugin_type':'TextPlugin',
606-
'values':{'body':'<p>en default body 1</p>'},
607-
},
608-
{
609-
'plugin_type':'TextPlugin',
610-
'values':{'body':'<p>en default body 2</p>'},
611-
},
612-
]
613-
},
614-
}
615-
with self.settings(CMS_PLACEHOLDER_CONF=conf):
616-
page = create_page('page_en', 'col_two.html', 'en')
617-
placeholder = page.get_placeholders("en").get(slot='col_left')
618-
context = SekizaiContext()
619-
context['request'] = self.get_request(language="en", page=page)
620-
# Our page should have "en default body 1" AND "en default body 2"
621-
content = _render_placeholder(placeholder, context)
622-
self.assertRegexpMatches(content, "^<p>en default body 1</p>\s*<p>en default body 2</p>$")
623-
624-
def test_plugins_children_prepopulate(self):
625-
"""
626-
Validate a default textplugin with a nested default link plugin
627-
"""
628-
629-
conf = {
630-
'col_left': {
631-
'default_plugins': [
632-
{
633-
'plugin_type': 'TextPlugin',
634-
'values': {
635-
'body': '<p>body %(_tag_child_1)s and %(_tag_child_2)s</p>'
636-
},
637-
'children': [
638-
{
639-
'plugin_type': 'LinkPlugin',
640-
'values': {
641-
'name': 'django',
642-
'external_link': 'https://www.djangoproject.com/'
643-
},
644-
},
645-
{
646-
'plugin_type': 'LinkPlugin',
647-
'values': {
648-
'name': 'django-cms',
649-
'external_link': 'https://www.django-cms.org'
650-
},
651-
},
652-
]
653-
},
654-
]
655-
},
656-
}
657-
658-
with self.settings(CMS_PLACEHOLDER_CONF=conf):
659-
page = create_page('page_en', 'col_two.html', 'en')
660-
placeholder = page.get_placeholders("en").get(slot='col_left')
661-
context = SekizaiContext()
662-
context['request'] = self.get_request(language="en", page=page)
663-
_render_placeholder(placeholder, context)
664-
plugins = placeholder.get_plugins_list()
665-
self.assertEqual(len(plugins), 3)
666-
self.assertEqual(plugins[0].plugin_type, 'TextPlugin')
667-
self.assertEqual(plugins[1].plugin_type, 'LinkPlugin')
668-
self.assertEqual(plugins[2].plugin_type, 'LinkPlugin')
669-
self.assertTrue(plugins[1].parent == plugins[2].parent and plugins[1].parent == plugins[0])
670-
671591
def test_placeholder_pk_thousands_format(self):
672592
page = create_page("page", "nav_playground.html", "en", published=True)
673593
title = page.get_title_obj("en")

cms/tests/test_rendering.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,6 @@ def test_inherit_placeholder_override(self):
668668
r = self.render(self.test_page5)
669669
self.assertEqual(r, u'|' + self.test_data5['text_main'] + '|' + self.test_data5['text_sub'])
670670

671-
@override_settings(CMS_PLACEHOLDER_CONF={None: {'language_fallback': False}})
672671
def test_inherit_placeholder_queries(self):
673672
with self.assertNumQueries(FuzzyInt(6,8)):
674673
r = self.render(self.test_page2)

cms/utils/plugins.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from copy import deepcopy
33
from collections import defaultdict, deque, OrderedDict
4-
from itertools import starmap
5-
from operator import itemgetter
64

75
from django.utils.encoding import force_text
86
from django.utils.lru_cache import lru_cache
@@ -12,7 +10,6 @@
1210
from cms.models.pluginmodel import CMSPlugin
1311
from cms.plugin_pool import plugin_pool
1412
from cms.utils import get_language_from_request
15-
from cms.utils.permissions import has_plugin_permission
1613
from cms.utils.placeholder import get_placeholder_conf
1714

1815

@@ -49,9 +46,6 @@ def assign_plugins(request, placeholders, template=None, lang=None):
4946
.objects
5047
.filter(placeholder__in=placeholders, language=lang)
5148
)
52-
if not plugins:
53-
# Create default plugins if enabled
54-
plugins = create_default_plugins(request, placeholders, template, lang)
5549
plugins = downcast_plugins(plugins, placeholders, request=request)
5650

5751
# split the plugins up by placeholder
@@ -73,47 +67,6 @@ def assign_plugins(request, placeholders, template=None, lang=None):
7367
setattr(placeholder, '_plugins_cache', layered_plugins)
7468

7569

76-
def create_default_plugins(request, placeholders, template, lang):
77-
"""
78-
Create all default plugins for the given ``placeholders`` if they have
79-
a "default_plugins" configuration value in settings.
80-
return all plugins, children, grandchildren (etc.) created
81-
"""
82-
from cms.api import add_plugin
83-
84-
def _create_default_plugins(placeholder, confs, parent=None):
85-
"""
86-
Auxillary function that builds all of a placeholder's default plugins
87-
at the current level and drives the recursion down the tree.
88-
Returns the plugins at the current level along with all descendants.
89-
"""
90-
plugins, descendants = [], []
91-
addable_confs = (conf for conf in confs
92-
if has_plugin_permission(request.user,
93-
conf['plugin_type'], 'add'))
94-
for conf in addable_confs:
95-
plugin = add_plugin(placeholder, conf['plugin_type'], lang,
96-
target=parent, **conf['values'])
97-
if 'children' in conf:
98-
args = placeholder, conf['children'], plugin
99-
descendants += _create_default_plugins(*args)
100-
plugin.notify_on_autoadd(request, conf)
101-
plugins.append(plugin)
102-
if parent:
103-
parent.notify_on_autoadd_children(request, conf, plugins)
104-
return plugins + descendants
105-
106-
unfiltered_confs = ((ph, get_placeholder_conf('default_plugins',
107-
ph.slot, template))
108-
for ph in placeholders)
109-
# Empty confs must be filtered before filtering on add permission
110-
mutable_confs = ((ph, default_plugin_confs)
111-
for ph, default_plugin_confs
112-
in filter(itemgetter(1), unfiltered_confs)
113-
if ph.has_change_permission(request.user))
114-
return sum(starmap(_create_default_plugins, mutable_confs), [])
115-
116-
11770
def get_plugins_as_layered_tree(plugins):
11871
"""
11972
Given an iterable of plugins ordered by position,

docs/reference/configuration.rst

Lines changed: 1 addition & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,6 @@ Example::
196196
'text_only_plugins': ['LinkPlugin'],
197197
'extra_context': {"width":640},
198198
'name': gettext("Content"),
199-
'language_fallback': True,
200-
'default_plugins': [
201-
{
202-
'plugin_type': 'TextPlugin',
203-
'values': {
204-
'body':'<p>Lorem ipsum dolor sit amet...</p>',
205-
},
206-
},
207-
],
208199
'child_classes': {
209200
'TextPlugin': ['PicturePlugin', 'LinkPlugin'],
210201
},
@@ -288,76 +279,6 @@ matches; if the same configuration is retrieved for the ``content`` placeholder
288279
this placeholder regardless of type (takes precedence over the
289280
type-specific limits).
290281

291-
``language_fallback``
292-
When ``True``, if the placeholder has no plugin for the current language
293-
it falls back to the fallback languages as specified in :setting:`CMS_LANGUAGES`.
294-
Defaults to ``True`` since version 3.1.
295-
296-
.. _placeholder_default_plugins:
297-
298-
``default_plugins``
299-
You can specify the list of default plugins which will be automatically
300-
added when the placeholder will be created (or rendered).
301-
Each element of the list is a dictionary with following keys :
302-
303-
``plugin_type``
304-
The plugin type to add to the placeholder
305-
Example : ``TextPlugin``
306-
307-
``values``
308-
Dictionary to use for the plugin creation.
309-
It depends on the ``plugin_type``. See the documentation of each
310-
plugin type to see which parameters are required and available.
311-
Example for a text plugin:
312-
``{'body':'<p>Lorem ipsum</p>'}``
313-
Example for a link plugin:
314-
``{'name':'Django-CMS','url':'https://www.django-cms.org'}``
315-
316-
``children``
317-
It is a list of dictionaries to configure default plugins
318-
to add as children for the current plugin (it must accepts children).
319-
Each dictionary accepts same args than dictionaries of
320-
``default_plugins`` : ``plugin_type``, ``values``, ``children``
321-
(yes, it is recursive).
322-
323-
Complete example of default_plugins usage::
324-
325-
CMS_PLACEHOLDER_CONF = {
326-
'content': {
327-
'name' : _('Content'),
328-
'plugins': ['TextPlugin', 'LinkPlugin'],
329-
'default_plugins':[
330-
{
331-
'plugin_type':'TextPlugin',
332-
'values':{
333-
'body':'<p>Great websites : %(_tag_child_1)s and %(_tag_child_2)s</p>'
334-
},
335-
'children':[
336-
{
337-
'plugin_type':'LinkPlugin',
338-
'values':{
339-
'name':'django',
340-
'url':'https://www.djangoproject.com/'
341-
},
342-
},
343-
{
344-
'plugin_type':'LinkPlugin',
345-
'values':{
346-
'name':'django-cms',
347-
'url':'https://www.django-cms.org'
348-
},
349-
# If using LinkPlugin from djangocms-link which
350-
# accepts children, you could add some grandchildren :
351-
# 'children' : [
352-
# ...
353-
# ]
354-
},
355-
]
356-
},
357-
]
358-
}
359-
}
360-
361282
``plugin_modules``
362283
A dictionary of plugins and custom module names to group plugin in the
363284
toolbar UI.
@@ -595,10 +516,7 @@ will redirect to the URL of the same page in the fallback language. If
595516
``False``, the content will be displayed in the fallback language, but there
596517
will be no redirect.
597518

598-
Note that this applies to the fallback behaviour of *pages*. Starting for 3.1 *placeholders*
599-
**will** default to the same behaviour. If you do not want a placeholder to follow a page's
600-
fallback behaviour, you must set its ``language_fallback`` to ``False``
601-
in :setting:`CMS_PLACEHOLDER_CONF`, above.
519+
Note that this applies to the fallback behaviour of *pages*.
602520

603521
type
604522
Boolean

docs/upgrade/3.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ Placeholders are pre-fillable with default plugins
304304

305305
In CMS_PLACEHOLDER_CONF, for each placeholder configuration, you can specify
306306
via 'default_plugins' a list of plugins to automatically add to the
307-
placeholder if empty. See :ref:`default_plugins in CMS_PLACEHOLDER_CONF <placeholder_default_plugins>`.
307+
placeholder if empty. See default_plugins in CMS_PLACEHOLDER_CONF.
308308

309309
Custom modules and plugin labels in the toolbar UI
310310
==================================================

0 commit comments

Comments
 (0)