Skip to content

Commit

Permalink
Merge pull request #12 from yakky/future/integration_update
Browse files Browse the repository at this point in the history
Future/integration update
  • Loading branch information
yakky committed May 30, 2015
2 parents 8f14ad6 + 27fc259 commit 3918373
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
30 changes: 17 additions & 13 deletions cms/utils/plugins.py
Expand Up @@ -200,7 +200,7 @@ def requires_reload(action, plugins):
return False


def assign_plugins(request, placeholders, template, lang=None, no_fallback=False):
def assign_plugins(request, placeholders, template, lang=None, is_fallback=False):
"""
Fetch all plugins for the given ``placeholders`` and
cast them down to the concrete instances in one query
Expand All @@ -214,10 +214,11 @@ def assign_plugins(request, placeholders, template, lang=None, no_fallback=False
qs = get_cmsplugin_queryset(request).filter(placeholder__in=placeholders, language=request_lang).order_by(
'placeholder', 'tree_id', 'level', 'position')
plugins = list(qs)
fallbacks = defaultdict(list)
# If no plugin is present in the current placeholder we loop in the fallback languages
# and get the first available set of plugins

if not no_fallback:
if not is_fallback:
for placeholder in placeholders:
found = False
for plugin in plugins:
Expand All @@ -229,22 +230,25 @@ def assign_plugins(request, placeholders, template, lang=None, no_fallback=False
elif placeholder and get_placeholder_conf("language_fallback", placeholder.slot, template, False):
if hasattr(request, 'toolbar') and request.toolbar.edit_mode:
continue
fallbacks = get_fallback_languages(lang)
for fallback_language in fallbacks:
assign_plugins(request, [placeholder], template, fallback_language, no_fallback=True)
fallback_languages = get_fallback_languages(lang)
for fallback_language in fallback_languages:
assign_plugins(request, [placeholder], template, fallback_language, is_fallback=True)
fallback_plugins = placeholder._plugins_cache
if fallback_plugins:
plugins += fallback_plugins
fallbacks[placeholder.pk] += fallback_plugins
break
# If no plugin is present, create default plugins if enabled)
# 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, placeholders, template, lang)
plugin_list = downcast_plugins(plugins, placeholders)
plugins = create_default_plugins(request, non_fallback_phs, template, lang)
plugin_list = downcast_plugins(plugins, non_fallback_phs)
# split the plugins up by placeholder
groups = dict((key, list(plugins)) for key, plugins in groupby(plugin_list, operator.attrgetter('placeholder_id')))

for group in groups:
groups[group] = build_plugin_tree(groups[group])
plugin_groups = dict((key, list(plugins)) for key, plugins in groupby(plugin_list, operator.attrgetter('placeholder_id')))
for group in plugin_groups:
plugin_groups[group] = build_plugin_tree(plugin_groups[group])
groups = fallbacks.copy()
groups.update(plugin_groups)
for placeholder in placeholders:
setattr(placeholder, '_plugins_cache', list(groups.get(placeholder.pk, [])))

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -35,7 +35,7 @@
'Django>=1.4,<1.8',
'django-classy-tags>=0.5',
'south>=1.0.2',
'html5lib',
'html5lib>=0.90,<0.9999',
'django-mptt>=0.6,<0.6.2',
'django-sekizai>=0.7',
'djangocms-admin-style'
Expand Down
2 changes: 1 addition & 1 deletion test_requirements/requirements_base.txt
Expand Up @@ -5,7 +5,7 @@ unittest-xml-reporting==1.9.0
sphinx
Pillow==2.5.3
django-classy-tags>=0.5
html5lib>=0.90
html5lib>=0.90,<0.9999
django-mptt>=0.6,<0.7
django-sekizai>=0.7
argparse
Expand Down

0 comments on commit 3918373

Please sign in to comment.