Repository: django-cms/django-cms

Issue:
"Reverse for 'cms_page_clear_placeholder' with arguments '('',)' and keyword arguments '{}' not found." after visiting an Apphook-ed page as admin



Discussion:

Resolving patch:
diff --git a/cms/exceptions.py b/cms/exceptions.py
--- a/cms/exceptions.py
+++ b/cms/exceptions.py
@@ -70,3 +70,7 @@ class LanguageError(Exception): pass
 
 
 class PluginConsistencyError(Exception): pass
+
+
+class PlaceholderNotFound(Exception): pass
+
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
@@ -5,6 +5,7 @@
 from classytags.core import Options, Tag
 from classytags.helpers import InclusionTag, AsTag
 from classytags.parser import Parser
+from cms.exceptions import PlaceholderNotFound
 from cms.models import Page, Placeholder as PlaceholderModel
 from cms.plugin_pool import plugin_pool
 from cms.plugin_rendering import render_placeholder
@@ -154,11 +155,11 @@ def get_context(self, context, page_lookup, lang, site):
 
 
 def _get_placeholder(current_page, page, context, name):
-    from cms.utils.plugins import get_placeholders
-
     placeholder_cache = getattr(current_page, '_tmp_placeholders_cache', {})
     if page.pk in placeholder_cache:
-        return placeholder_cache[page.pk].get(name, None)
+        placeholder = placeholder_cache[page.pk].get(name, None)
+        if placeholder:
+            return placeholder
     placeholder_cache[page.pk] = {}
     placeholders = page.rescan_placeholders().values()
     assign_plugins(context['request'], placeholders, get_language())
@@ -166,7 +167,11 @@ def _get_placeholder(current_page, page, context, name):
         placeholder_cache[page.pk][placeholder.slot] = placeholder
         placeholder.page = page
     current_page._tmp_placeholders_cache = placeholder_cache
-    return placeholder_cache[page.pk].get(name, None)
+    placeholder = placeholder_cache[page.pk].get(name, None)
+    if page.application_urls and not placeholder:
+        raise PlaceholderNotFound(
+            '"%s" placeholder not found in an apphook application. Please use stacks instead.' % name)
+    return placeholder
 
 
 def get_placeholder_content(context, request, current_page, name, inherit):
@@ -326,8 +331,10 @@ def get_context(self, context, plugin):
                 child_plugin_classes.append((cls.__name__, force_unicode(cls.name)))
         return {'plugin_classes': child_plugin_classes}
 
+
 register.tag(PluginChildClasses)
 
+
 class PageAttribute(AsTag):
     """
     This template node is used to output an attribute from a page such
@@ -568,4 +575,5 @@ def get_context(self, context):
 
         return context
 
+
 register.tag(CMSEditablePageTitle)


Test patch:
diff --git a/cms/tests/placeholder.py b/cms/tests/placeholder.py
--- a/cms/tests/placeholder.py
+++ b/cms/tests/placeholder.py
@@ -560,7 +560,7 @@ def test_edit_plugin_and_cancel(self):
                 request = self.get_post_request(data)
                 response = admin.add_plugin(request)
                 self.assertEqual(response.status_code, 200)
-                plugin_id = int(str(response.content).split('/", "breadcrumb')[0].split("/")[-1])
+                plugin_id = int(str(response.content).split('edit-plugin/')[1].split("/")[0])
                 data = {
                     'body': 'Hello World',
                 }