Repository: django-cms/django-cms

Issue:
Make language_fallback enabled by default
I think we can set to enabled by default in `CMS_PLACEHOLDER_CONF` as the master behavior is controlled in `CMS_LANGUAGES` (see http://django-cms.readthedocs.org/en/support-3.0.x/reference/configuration.html#cms-placeholder-conf)



Discussion:
@evildmp @mkoistinen @ojii opinions?

Linked to #3847
If we want to keep this as is, make it clearer in the `CMS_LANGUAGES` documentation (http://django-cms.readthedocs.org/en/support-3.0.x/reference/configuration.html#fallbacks) that it needs a per-placeholder setting to work


Resolving patch:
diff --git a/cms/utils/placeholder.py b/cms/utils/placeholder.py
--- a/cms/utils/placeholder.py
+++ b/cms/utils/placeholder.py
@@ -23,7 +23,7 @@
 def get_placeholder_conf(setting, placeholder, template=None, default=None):
     """
     Returns the placeholder configuration for a given setting. The key would for
-    example be 'plugins'  or 'name'.
+    example be 'plugins' or 'name'.
 
     If a template is given, it will try
     CMS_PLACEHOLDER_CONF['template placeholder'] and
@@ -43,7 +43,7 @@ def get_placeholder_conf(setting, placeholder, template=None, default=None):
             if value is not None:
                 return value
             inherit = conf.get('inherit')
-            if inherit :
+            if inherit:
                 if ' ' in inherit:
                     inherit = inherit.split(' ')
                 else:
diff --git a/cms/utils/plugins.py b/cms/utils/plugins.py
--- a/cms/utils/plugins.py
+++ b/cms/utils/plugins.py
@@ -58,7 +58,7 @@ def assign_plugins(request, placeholders, template, lang=None, is_fallback=False
         disjoint_placeholders = (ph for ph in placeholders
                                  if all(ph.pk != p.placeholder_id for p in plugins))
         for placeholder in disjoint_placeholders:
-            if get_placeholder_conf("language_fallback", placeholder.slot, template, False):
+            if get_placeholder_conf("language_fallback", placeholder.slot, template, True):
                 for fallback_language in get_fallback_languages(lang):
                     assign_plugins(request, (placeholder,), template, fallback_language, is_fallback=True)
                     fallback_plugins = placeholder._plugins_cache


Test patch:
diff --git a/cms/tests/cache.py b/cms/tests/cache.py
--- a/cms/tests/cache.py
+++ b/cms/tests/cache.py
@@ -30,7 +30,7 @@ def test_cache_placeholder(self):
         request.current_page = Page.objects.get(pk=page1.pk)
         request.toolbar = CMSToolbar(request)
         rctx = RequestContext(request)
-        with self.assertNumQueries(3):
+        with self.assertNumQueries(5):
             template.render(rctx)
         connection.queries = []
         request = self.get_request('/en/')
diff --git a/cms/tests/placeholder.py b/cms/tests/placeholder.py
--- a/cms/tests/placeholder.py
+++ b/cms/tests/placeholder.py
@@ -378,27 +378,28 @@ def push(self):
         context_de = NoPushPopContext()
         context_de['request'] = self.get_request(language="de", page=page_en)
 
-        # First test the default (non-fallback) behavior)
+        # First test the default (fallback) behavior)
         ## English page should have the text plugin
         content_en = render_placeholder(placeholder_en, context_en)
         self.assertRegexpMatches(content_en, "^en body$")
 
-        ## Deutsch page should have no text
+        ## Deutsch page have text due to fallback
         content_de = render_placeholder(placeholder_de, context_de)
-        self.assertNotRegex(content_de, "^en body$")
-        self.assertEqual(len(content_de), 0)
+        self.assertRegexpMatches(content_de, "^en body$")
+        self.assertEqual(len(content_de), 7)
 
         conf = {
             'col_left': {
-                'language_fallback': True,
+                'language_fallback': False,
             },
         }
+        # configure non fallback
         with self.settings(CMS_PLACEHOLDER_CONF=conf):
             ## Deutsch page should have no text
             del(placeholder_de._plugins_cache)
             cache.clear()
             content_de = render_placeholder(placeholder_de, context_de)
-            self.assertRegexpMatches(content_de, "^en body$")
+            self.assertNotRegex(content_de, "^en body$")
             context_de2 = NoPushPopContext()
             request = self.get_request(language="de", page=page_en)
             request.user = self.get_superuser()
@@ -436,7 +437,7 @@ def push(self):
         context_de = NoPushPopContext()
         context_de['request'] = self.get_request(language="de", page=page_en)
 
-        # First test the default (non-fallback) behavior)
+        # First test the default (fallback) behavior)
         ## Deutsch page should have the text plugin
         content_de = render_placeholder(placeholder_en, context_de)
         self.assertRegexpMatches(content_de, "^de body$")
@@ -444,19 +445,20 @@ def push(self):
         cache.clear()
         ## English page should have no text
         content_en = render_placeholder(placeholder_en, context_en)
-        self.assertNotRegex(content_en, "^de body$")
-        self.assertEqual(len(content_en), 0)
+        self.assertRegexpMatches(content_en, "^de body$")
+        self.assertEqual(len(content_en), 7)
         del(placeholder_en._plugins_cache)
         cache.clear()
         conf = {
             'col_left': {
-                'language_fallback': True,
+                'language_fallback': False,
             },
         }
+        # configure non-fallback
         with self.settings(CMS_PLACEHOLDER_CONF=conf):
             ## English page should have deutsch text
             content_en = render_placeholder(placeholder_en, context_en)
-            self.assertRegexpMatches(content_en, "^de body$")
+            self.assertNotRegex(content_en, "^de body$")
 
             # remove the cached plugins instances
             del(placeholder_en._plugins_cache)
diff --git a/cms/tests/views.py b/cms/tests/views.py
--- a/cms/tests/views.py
+++ b/cms/tests/views.py
@@ -228,7 +228,7 @@ def test_context_current_page(self):
         # Number of queries when context processors is not enabled
         with self.settings(TEMPLATE_CONTEXT_PROCESSORS=new_context):
             # Baseline number of queries
-            with self.assertNumQueries(FuzzyInt(13, 17)) as context:
+            with self.assertNumQueries(FuzzyInt(13, 19)) as context:
                 response = self.client.get("/en/page-2/")
                 num_queries_page = len(context.captured_queries)
         cache.clear()