Repository: django-cms/django-cms

Issue:
show_placeholder always use the cache even in preview mode
`show_placeholder` always use the cached version of a plugin, even in preview, when you're supposed to want the most up-to-date content.
Should it check if `?preview` is in the `GET` and rendere the uncached one?
Code fix is trivial, but I'd like to discuss this first, before submitting PR



Discussion:

Resolving patch:
diff --git a/cms/templatetags/cms_tags.py b/cms/templatetags/cms_tags.py
--- a/cms/templatetags/cms_tags.py
+++ b/cms/templatetags/cms_tags.py
@@ -468,12 +468,16 @@ def get_context(self, *args, **kwargs):
         return _show_placeholder_for_page(**self.get_kwargs(*args, **kwargs))
 
     def get_kwargs(self, context, placeholder_name, reverse_id, lang, site):
+        cache_result = True
+        if 'preview' in context['request'].GET:
+            cache_result = False
         return {
             'context': context,
             'placeholder_name': placeholder_name,
             'page_lookup': reverse_id,
             'lang': lang,
-            'site': site
+            'site': site,
+            'cache_result': cache_result
         }
 
 


Test patch:
diff --git a/cms/tests/templatetags.py b/cms/tests/templatetags.py
--- a/cms/tests/templatetags.py
+++ b/cms/tests/templatetags.py
@@ -208,7 +208,7 @@ def test_untranslated_language_url(self):
 
 class NoFixtureDatabaseTemplateTagTests(TestCase):
     def test_cached_show_placeholder_sekizai(self):
-        from django.core.cache import cache;
+        from django.core.cache import cache
 
         cache.clear()
         from cms.test_utils import project
@@ -230,7 +230,7 @@ def test_cached_show_placeholder_sekizai(self):
             self.assertIn('JAVASCRIPT', output)
 
     def test_show_placeholder_for_page_marks_output_safe(self):
-        from django.core.cache import cache;
+        from django.core.cache import cache
 
         cache.clear()
         page = create_page('Test', 'col_two.html', 'en')
@@ -247,3 +247,24 @@ def test_show_placeholder_for_page_marks_output_safe(self):
         with self.assertNumQueries(0):
             output = template.render(context)
         self.assertIn('<b>Test</b>', output)
+
+    def test_cached_show_placeholder_preview(self):
+        from django.core.cache import cache
+
+        cache.clear()
+        page = create_page('Test', 'col_two.html', 'en')
+        placeholder = page.placeholders.all()[0]
+        add_plugin(placeholder, TextPlugin, 'en', body='<b>Test</b>')
+        request = RequestFactory().get('/')
+        template = Template(
+            "{% load cms_tags %}{% show_placeholder slot page 'en' 1 %}")
+        context = RequestContext(request, {'page': page, 'slot': placeholder.slot})
+        with self.assertNumQueries(4):
+            output = template.render(context)
+        self.assertIn('<b>Test</b>', output)
+        add_plugin(placeholder, TextPlugin, 'en', body='<b>Test2</b>')
+        request = RequestFactory().get('/?preview')
+        context = RequestContext(request, {'page': page, 'slot': placeholder.slot})
+        with self.assertNumQueries(4):
+            output = template.render(context)
+        self.assertIn('<b>Test2</b>', output)
\ No newline at end of file