1
1
# -*- coding: utf-8 -*-
2
2
from copy import deepcopy
3
3
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
6
6
7
7
from django .utils .encoding import force_text
8
8
from django .utils .lru_cache import lru_cache
14
14
from cms .utils import get_language_from_request
15
15
from cms .utils .i18n import get_fallback_languages
16
16
from cms .utils .moderator import get_cmsplugin_queryset
17
- from cms .utils .permissions import has_plugin_permission
18
17
from cms .utils .placeholder import get_placeholder_conf
19
18
20
19
@@ -88,9 +87,7 @@ def assign_plugins(request, placeholders, template=None, lang=None, is_fallback=
88
87
break
89
88
# These placeholders have no fallback
90
89
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
+
94
91
plugins = downcast_plugins (plugins , non_fallback_phs , request = request )
95
92
# split the plugins up by placeholder
96
93
# Plugins should still be sorted by placeholder
@@ -107,47 +104,6 @@ def assign_plugins(request, placeholders, template=None, lang=None, is_fallback=
107
104
setattr (placeholder , '_plugins_cache' , groups .get (placeholder .pk , []))
108
105
109
106
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
-
151
107
def build_plugin_tree (plugins ):
152
108
"""
153
109
Accepts an iterable of plugins and assigns tuples, sorted by position, of
0 commit comments