Repository: django-cms/django-cms

Issue:
plugin-list-holder doesn't properly display plugin after editing and canceling
Steps to reproduce:
1. Create a link plugin and give it the name 'foobar'
2. Notice the plugin's name in the plugin-list-holder (html class):   Link [ foobar ]
3. Open the edit dialog
4. Click cancel

Expected:
Plugin's name in the plugin-list-holder continues to be:   Link [ foobar ]

Actual:
Plugin's name in the plugin-list-holder continues to be:   Link [ 6 ]

(where 6 appears to be the plugin's PK)



Discussion:

Resolving patch:
diff --git a/cms/admin/pageadmin.py b/cms/admin/pageadmin.py
--- a/cms/admin/pageadmin.py
+++ b/cms/admin/pageadmin.py
@@ -1295,7 +1295,6 @@ def edit_plugin(self, request, plugin_id):
                 'CMS_MEDIA_URL': get_cms_setting('MEDIA_URL'),
                 'plugin': cms_plugin,
                 'is_popup': True,
-                'name': unicode(cms_plugin),
                 "type": cms_plugin.get_plugin_name(),
                 'plugin_id': plugin_id,
                 'icon': force_escape(escapejs(cms_plugin.get_instance_icon_src())),
@@ -1303,11 +1302,14 @@ def edit_plugin(self, request, plugin_id):
                 'cancel': True,
             }
             instance = cms_plugin.get_plugin_instance()[0]
-            if not instance:
+            if instance:
+                context['name'] = unicode(instance)
+            else:
                 # cancelled before any content was added to plugin
                 cms_plugin.delete()
                 context.update({
-                    "deleted":True,
+                    "deleted": True,
+                    'name': unicode(cms_plugin),
                 })
             return render_to_response('admin/cms/page/plugin_forms_ok.html', context, RequestContext(request))
 
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
@@ -405,9 +405,9 @@ def _show_placeholder_for_page(context, placeholder_name, page_lookup, lang=None
         cached_value = cache.get(cache_key)
         if isinstance(cached_value, dict): # new style
             _restore_sekizai(context, cached_value['sekizai'])
-            return {'content': cached_value['content']}
+            return {'content': mark_safe(cached_value['content'])}
         elif isinstance(cached_value, basestring): # old style
-            return {'content': cached_value}
+            return {'content': mark_safe(cached_value)}
 
     page = _get_page_by_untyped_arg(page_lookup, request, site_id)
     if not page:


Test patch:
diff --git a/cms/tests/templatetags.py b/cms/tests/templatetags.py
--- a/cms/tests/templatetags.py
+++ b/cms/tests/templatetags.py
@@ -190,6 +190,7 @@ def test_untranslated_language_url(self):
 
 class NoFixtureDatabaseTemplateTagTests(TestCase):
     def test_cached_show_placeholder_sekizai(self):
+        from django.core.cache import cache;cache.clear()
         from cms.test_utils import project
         template_dir = os.path.join(os.path.dirname(project.__file__), 'templates', 'alt_plugin_templates', 'show_placeholder')
         page = create_page('Test', 'col_two.html', 'en')
@@ -204,3 +205,19 @@ def test_cached_show_placeholder_sekizai(self):
             context = RequestContext(request, {'page': page, 'slot': placeholder.slot})
             output = template.render(context)
             self.assertIn('JAVASCRIPT', output)
+
+    def test_show_placeholder_for_page_marks_output_safe(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 sekizai_tags %}{% show_placeholder slot page 'en' 1 %}{% render_block 'js' %}")
+        context = RequestContext(request, {'page': page, 'slot': placeholder.slot})
+        with self.assertNumQueries(5):
+            output = template.render(context)
+        self.assertIn('<b>Test</b>', output)
+        context = RequestContext(request, {'page': page, 'slot': placeholder.slot})
+        with self.assertNumQueries(0):
+            output = template.render(context)
+        self.assertIn('<b>Test</b>', output)