8000 384: Remove default_plugin creation logic · django-cms/django-cms@c8c0ad9 · GitHub
[go: up one dir, main page]

Skip to content

Commit c8c0ad9

Browse files
author
Anirban Lahiri
committed
384: Remove default_plugin creation logic
1 parent 0e11071 commit c8c0ad9

File tree

3 files changed

+3
-141
lines changed

3 files changed

+3
-141
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: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -650,79 +650,6 @@ def test_plugins_discarded_with_language_fallback(self):
650650
del(placeholder_sidebar_en._plugins_cache)
651651
cache.clear()
652652

653-
def test_plugins_prepopulate(self):
654-
""" Tests prepopulate placeholder configuration """
655-
656-
conf = {
657-
'col_left': {
658-
'default_plugins' : [
659-
{
660-
'plugin_type':'TextPlugin',
661-
'values':{'body':'<p>en default body 1</p>'},
662-
},
663-
{
664-
'plugin_type':'TextPlugin',
665-
'values':{'body':'<p>en default body 2</p>'},
666-
},
667-
]
668-
},
669-
}
670-
with self.settings(CMS_PLACEHOLDER_CONF=conf):
671-
page = create_page('page_en', 'col_two.html', 'en')
672-
placeholder = page.get_placeholders("en").get(slot='col_left')
673-
context = SekizaiContext()
674-
context['request'] = self.get_request(language="en", page=page)
675-
# Our page should have "en default body 1" AND "en default body 2"
676-
content = _render_placeholder(placeholder, context)
677-
self.assertRegexpMatches(content, "^<p>en default body 1</p>\s*<p>en default body 2</p>$")
678-
679-
def test_plugins_children_prepopulate(self):
680-
"""
681-
Validate a default textplugin with a nested default link plugin
682-
"""
683-
684-
conf = {
685-
'col_left': {
686-
'default_plugins': [
687-
{
688-
'plugin_type': 'TextPlugin',
689-
'values': {
690-
'body': '<p>body %(_tag_child_1)s and %(_tag_child_2)s</p>'
691-
},
692-
'children': [
693-
{
694-
'plugin_type': 'LinkPlugin',
695-
'values': {
696-
'name': 'django',
697-
'external_link': 'https://www.djangoproject.com/'
698-
},
699-
},
700-
{
701-
'plugin_type': 'LinkPlugin',
702-
'values': {
703-
'name': 'django-cms',
704-
'external_link': 'https://www.django-cms.org'
705-
},
706-
},
707-
]
708-
},
709-
]
710-
},
711-
}
712-
713-
with self.settings(CMS_PLACEHOLDER_CONF=conf):
714-
page = create_page('page_en', 'col_two.html', 'en')
715-
placeholder = page.get_placeholders("en").get(slot='col_left')
716-
context = SekizaiContext()
717-
context['request'] = self.get_request(language="en", page=page)
718-
_render_placeholder(placeholder, context)
719-
plugins = placeholder.get_plugins_list()
720-
self.assertEqual(len(plugins), 3)
721-
self.assertEqual(plugins[0].plugin_type, 'TextPlugin')
722-
self.assertEqual(plugins[1].plugin_type, 'LinkPlugin')
723-
self.assertEqual(plugins[2].plugin_type, 'LinkPlugin')
724-
self.assertTrue(plugins[1].parent == plugins[2].parent and plugins[1].parent == plugins[0])
725-
726653
def test_placeholder_pk_thousands_format(self):
727654
page = create_page("page", "nav_playground.html", "en", published=True)
728655
title = page.get_title_obj("en")

cms/utils/plugins.py

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

77
from django.utils.encoding import force_text
88
from django.utils.lru_cache import lru_cache
@@ -14,7 +14,6 @@
1414
from cms.utils import get_language_from_request
1515
from cms.utils.i18n import get_fallback_languages
1616
from cms.utils.moderator import get_cmsplugin_queryset
17-
from cms.utils.permissions import has_plugin_permission
1817
from cms.utils.placeholder import get_placeholder_conf
1918

2019

@@ -88,9 +87,7 @@ def assign_plugins(request, placeholders, template=None, lang=None, is_fallback=
8887
break
8988
# These placeholders have no fallback
9089
non_fallback_phs = [ph for ph in placeholders if ph.pk not in fallbacks]
91-
# If no plugin is present in non fallback placeholders, create default plugins if enabled)
92-
if not plugins:
93-
plugins = create_default_plugins(request, non_fallback_phs, template, lang)
90+
9491
plugins = downcast_plugins(plugins, non_fallback_phs, request=request)
9592
# split the plugins up by placeholder
9693
# Plugins should still be sorted by placeholder
@@ -107,47 +104,6 @@ def assign_plugins(request, placeholders, template=None, lang=None, is_fallback=
107104
setattr(placeholder, '_plugins_cache', groups.get(placeholder.pk, []))
108105

109106

110-
def create_default_plugins(request, placeholders, template, lang):
111-
"""
112-
Create all default plugins for the given ``placeholders`` if they have
113-
a "default_plugins" configuration value in settings.
114-
return all plugins, children, grandchildren (etc.) created
115-
"""
116-
from cms.api import add_plugin
117-
118-
def _create_default_plugins(placeholder, confs, parent=None):
119-
"""
120-
Auxillary function that builds all of a placeholder's default plugins
121-
at the current level and drives the recursion down the tree.
122-
Returns the plugins at the current level along with all descendants.
123-
"""
124-
plugins, descendants = [], []
125-
addable_confs = (conf for conf in confs
126-
if has_plugin_permission(request.user,
127-
conf['plugin_type'], 'add'))
128-
for conf in addable_confs:
129-
plugin = add_plugin(placeholder, conf['plugin_type'], lang,
130-
target=parent, **conf['values'])
131-
if 'children' in conf:
132-
args = placeholder, conf['children'], plugin
133-
descendants += _create_default_plugins(*args)
134-
plugin.notify_on_autoadd(request, conf)
135-
plugins.append(plugin)
136-
if parent:
137-
parent.notify_on_autoadd_children(request, conf, plugins)
138-
return plugins + descendants
139-
140-
unfiltered_confs = ((ph, get_placeholder_conf('default_plugins',
141-
ph.slot, template))
142-
for ph in placeholders)
143-
# Empty confs must be filtered before filtering on add permission
144-
mutable_confs = ((ph, default_plugin_confs)
145-
for ph, default_plugin_confs
146-
in filter(itemgetter(1), unfiltered_confs)
147-
if ph.has_change_permission(request.user))
148-
return sum(starmap(_create_default_plugins, mutable_confs), [])
149-
150-
151107
def build_plugin_tree(plugins):
152108
"""
153109
Accepts an iterable of plugins and assigns tuples, sorted by position, of

0 commit comments

Comments
 (0)
0