8000 384: Remove default_plugin creation logic by anirbanlahiri-fidelity · Pull Request #6460 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

384: Remove default_plugin creation logic #6460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
384: Remove default_plugin creation logic
  • Loading branch information
Anirban Lahiri committed Jul 25, 2018
commit c8c0ad94807f5d6c55aa67f7ae84682ba241e60c
21 changes: 0 additions & 21 deletions cms/tests/test_permmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,6 @@ def test_slave_can_add_page_under_slave_home(self):
# approve / publish as user_slave
# user master should be able to approve as well

@override_settings(
CMS_PLACEHOLDER_CONF={
'col_left': {
'default_plugins': [
{
'plugin_type': 'TextPlugin',
'values': {
'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.'
},
},
]
},
},
)
def test_default_plugins(self):
with self.login_user_context(self.user_slave):
self.assertEqual(CMSPlugin.objects.count(), 0)
response = self.client.get(self.slave_page.get_absolute_url(), {'edit': 1})
self.assertEqual(response.status_code, 200)
self.assertEqual(CMSPlugin.objects.count(), 1)

def test_page_added_by_slave_can_be_published_by_user_master(self):
# add page
page = create_page("page", "nav_playground.html", "en",
Expand Down
73 changes: 0 additions & 73 deletions cms/tests/test_placeholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,79 +650,6 @@ def test_plugins_discarded_with_language_fallback(self):
del(placeholder_sidebar_en._plugins_cache)
cache.clear()

def test_plugins_prepopulate(self):
""" Tests prepopulate placeholder configuration """

conf = {
'col_left': {
'default_plugins' : [
{
'plugin_type':'TextPlugin',
'values':{'body':'<p>en default body 1</p>'},
},
{
'plugin_type':'TextPlugin',
'values':{'body':'<p>en default body 2</p>'},
},
]
},
}
with self.settings(CMS_PLACEHOLDER_CONF=conf):
page = create_page('page_en', 'col_two.html', 'en')
placeholder = page.get_placeholders("en").get(slot='col_left')
context = SekizaiContext()
context['request'] = self.get_request(language="en", page=page)
# Our page should have "en default body 1" AND "en default body 2"
content = _render_placeholder(placeholder, context)
self.assertRegexpMatches(content, "^<p>en default body 1</p>\s*<p>en default body 2</p>$")

def test_plugins_children_prepopulate(self):
"""
Validate a default textplugin with a nested default link plugin
"""

conf = {
'col_left': {
'default_plugins': [
{
'plugin_type': 'TextPlugin',
'values': {
'body': '<p>body %(_tag_child_1)s and %(_tag_child_2)s</p>'
},
'children': [
{
'plugin_type': 'LinkPlugin',
'values': {
'name': 'django',
'external_link': 'https://www.djangoproject.com/'
},
},
{
'plugin_type': 'LinkPlugin',
'values': {
'name': 'django-cms',
'external_link': 'https://www.django-cms.org'
},
},
]
},
]
},
}

with self.settings(CMS_PLACEHOLDER_CONF=conf):
page = create_page('page_en', 'col_two.html', 'en')
placeholder = page.get_placeholders("en").get(slot='col_left')
context = SekizaiContext()
context['request'] = self.get_request(language="en", page=page)
_render_placeholder(placeholder, context)
plugins = placeholder.get_plugins_list()
self.assertEqual(len(plugins), 3)
self.assertEqual(plugins[0].plugin_type, 'TextPlugin')
self.assertEqual(plugins[1].plugin_type, 'LinkPlugin')
self.assertEqual(plugins[2].plugin_type, 'LinkPlugin')
self.assertTrue(plugins[1].parent == plugins[2].parent and plugins[1].parent == plugins[0])

def test_placeholder_pk_thousands_format(self):
page = create_page("page", "nav_playground.html", "en", published=True)
title = page.get_title_obj("en")
Expand Down
50 changes: 3 additions & 47 deletions cms/utils/plugins.py
8000
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from copy import deepcopy
from collections import defaultdict
from itertools import groupby, starmap
from operator import attrgetter, itemgetter
from itertools import groupby
from operator import attrgetter

from django.utils.encoding import force_text
from django.utils.lru_cache import lru_cache
Expand All @@ -14,7 +14,6 @@
from cms.utils import get_language_from_request
from cms.utils.i18n import get_fallback_languages
from cms.utils.moderator import get_cmsplugin_queryset
from cms.utils.permissions import has_plugin_permission
from cms.utils.placeholder import get_placeholder_conf


Expand Down Expand Up @@ -88,9 +87,7 @@ def assign_plugins(request, placeholders, template=None, lang=None, is_fallback=
break
# These placeholders have no fallback
non_fallback_phs = [ph for ph in placeholders if ph.pk not in fallbacks]
# If no plugin is present in non fallback placeholders, create default plugins if enabled)
if not plugins:
plugins = create_default_plugins(request, non_fallback_phs, template, lang)

plugins = downcast_plugins(plugins, non_fallback_phs, request=request)
# split the plugins up by placeholder
# Plugins should still be sorted by placeholder
Expand All @@ -107,47 +104,6 @@ def assign_plugins(request, placeholders, template=None, lang=None, is_fallback=
setattr(placeholder, '_plugins_cache', groups.get(placeholder.pk, []))


def create_default_plugins(request, placeholders, template, lang):
"""
Create all default plugins for the given ``placeholders`` if they have
a "default_plugins" configuration value in settings.
return all plugins, children, grandchildren (etc.) created
"""
from cms.api import add_plugin

def _create_default_plugins(placeholder, confs, parent=None):
"""
Auxillary function that builds all of a placeholder's default plugins
at the current level and drives the recursion down the tree.
Returns the plugins at the current level along with all descendants.
"""
plugins, descendants = [], []
addable_confs = (conf for conf in confs
if has_plugin_permission(request.user,
conf['plugin_type'], 'add'))
for conf in addable_confs:
plugin = add_plugin(placeholder, conf['plugin_type'], lang,
target=parent, **conf['values'])
if 'children' in conf:
args = placeholder, conf['children'], plugin
descendants += _create_default_plugins(*args)
plugin.notify_on_autoadd(request, conf)
plugins.append(plugin)
if parent:
parent.notify_on_autoadd_children(request, conf, plugins)
return plugins + descendants

unfiltered_confs = ((ph, get_placeholder_conf('default_plugins',
ph.slot, template))
for ph in placeholders)
# Empty confs must be filtered before filtering on add permission
mutable_confs = ((ph, default_plugin_confs)
for ph, default_plugin_confs
in filter(itemgetter(1), unfiltered_confs)
if ph.has_change_permission(request.user))
return sum(starmap(_create_default_plugins, mutable_confs), [])


def build_plugin_tree(plugins):
"""
Accepts an iterable of plugins and assigns tuples, sorted by position, of
Expand Down
0