Repository: django-cms/django-cms

Issue:
render_model template tag doesn't show correct change list
Looking at the docs here http://django-cms.readthedocs.org/en/latest/how_to/frontend_models.html#model-changelist, it says you can show the model change list by using the special "changelist" field name.

But no matter what model instance I use, and no matter what view_url I pass in, the change list that shows in the modal is always the cms pages list. I would expect the change list for the model I specified. 

Is this intended behavior? It would be really great if this were possible.



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
@@ -4,14 +4,18 @@
 from itertools import chain
 import re
 from classytags.values import StringValue
-from django.db.models import Model
-from cms.utils.urlutils import admin_reverse
+
+try:
+    from collections import OrderedDict
+except ImportError:
+    from django.utils.datastructures import SortedDict as OrderedDict
 
 from django import template
 from django.conf import settings
 from django.contrib.sites.models import Site
 from django.core.mail import mail_managers
 from django.core.urlresolvers import reverse
+from django.db.models import Model
 from django.template.defaultfilters import safe
 from django.template.loader import render_to_string
 from django.utils import six
@@ -20,8 +24,8 @@
 from django.utils.http import urlencode
 from django.utils.safestring import mark_safe
 from django.utils.translation import ugettext_lazy as _, get_language
-from classytags.arguments import Argument, MultiValueArgument, \
-    MultiKeywordArgument
+from classytags.arguments import (Argument, MultiValueArgument,
+                                  MultiKeywordArgument)
 from classytags.core import Options, Tag
 from classytags.helpers import InclusionTag, AsTag
 from classytags.parser import Parser
@@ -40,6 +44,7 @@
 from cms.utils.moderator import use_draft
 from cms.utils.page_resolver import get_page_queryset
 from cms.utils.placeholder import validate_placeholder_name, get_toolbar_plugin_struct, restore_sekizai_context
+from cms.utils.urlutils import admin_reverse
 
 
 register = template.Library()
@@ -883,8 +888,9 @@ def _get_empty_context(self, context, instance, edit_fields, language,
                 edit_fields = 'title,page_title,menu_title'
             view_url = 'admin:cms_page_edit_title_fields'
         if edit_fields == 'changelist':
-            view_url = 'admin:cms_page_changelist'
-        querystring = {'language': language}
+            view_url = 'admin:%s_%s_changelist' % (
+                instance._meta.app_label, instance._meta.module_name)
+        querystring = OrderedDict((('language', language),))
         if edit_fields:
             extra_context['edit_fields'] = edit_fields.strip().split(",")
         # If the toolbar is not enabled the following part is just skipped: it


Test patch:
diff --git a/cms/tests/toolbar.py b/cms/tests/toolbar.py
--- a/cms/tests/toolbar.py
+++ b/cms/tests/toolbar.py
@@ -1040,6 +1040,9 @@ def test_block_tag(self):
             response,
             '<div class="cms_plugin cms_plugin-%s-%s-changelist-%s cms_render_model cms_render_model_block">' % (
                 'placeholderapp', 'example1', ex1.pk))
+        self.assertContains(
+            response,
+            "'edit_plugin': '%s?language=%s&amp;edit_fields=changelist'" % (admin_reverse('placeholderapp_example1_changelist'), 'en'))
 
     def test_invalid_attribute(self):
         user = self.get_staff()
@@ -1424,7 +1427,9 @@ def test_edit_page(self):
         self.assertContains(
             response,
             '<div class="cms_plugin cms_plugin-cms-page-changelist-%s cms_render_model cms_render_model_block"><h3>Menu</h3></div>' % page.pk)
-
+        self.assertContains(
+            response,
+            "'edit_plugin': '%s?language=%s&amp;edit_fields=changelist'" % (admin_reverse('cms_page_changelist'), language))
 
 class CharPkFrontendPlaceholderAdminTest(ToolbarTestBase):