Repository: django-cms/django-cms

Issue:
expanding the page tree give wrong preview link



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
@@ -119,13 +119,13 @@ def get_urls(self):
             pat(r'^([0-9]+)/copy-page/$', self.copy_page),
             pat(r'^([0-9]+)/copy-language/$', self.copy_language),
             pat(r'^([0-9]+)/dialog/copy/$', get_copy_dialog),  # copy dialog
-            pat(r'^([0-9]+)/descendants/$', self.descendants),  # menu html for page descendants
             pat(r'^([0-9]+)/change-navigation/$', self.change_innavigation),
             pat(r'^([0-9]+)/jsi18n/$', self.redirect_jsi18n),
             pat(r'^([0-9]+)/permissions/$', self.get_permissions),
             pat(r'^([0-9]+)/undo/$', self.undo),
             pat(r'^([0-9]+)/redo/$', self.redo),
             pat(r'^([0-9]+)/change_template/$', self.change_template),
+            pat(r'^([0-9]+)/([a-z\-]+)/descendants/$', self.descendants),  # menu html for page descendants
             pat(r'^([0-9]+)/([a-z\-]+)/edit-field/$', self.edit_title_fields),
             pat(r'^([0-9]+)/([a-z\-]+)/publish/$', self.publish_page),
             pat(r'^([0-9]+)/([a-z\-]+)/unpublish/$', self.unpublish),
@@ -1216,7 +1216,7 @@ def change_innavigation(self, request, page_id):
             return admin_utils.render_admin_menu_item(request, page)
         return HttpResponseForbidden(force_unicode(_("You do not have permission to change this page's in_navigation status")))
 
-    def descendants(self, request, page_id):
+    def descendants(self, request, page_id, language):
         """
         Get html for descendants of given page
         Used for lazy loading pages in cms.changelist.js
@@ -1226,7 +1226,7 @@ def descendants(self, request, page_id):
         """
         page = get_object_or_404(Page, pk=page_id)
         return admin_utils.render_admin_menu_item(request, page,
-                                                  template="admin/cms/page/tree/lazy_menu.html")
+                                                  template="admin/cms/page/tree/lazy_menu.html", language=language)
 
     def add_page_type(self, request):
         site = Site.objects.get_current()
diff --git a/cms/templatetags/cms_admin.py b/cms/templatetags/cms_admin.py
--- a/cms/templatetags/cms_admin.py
+++ b/cms/templatetags/cms_admin.py
@@ -40,14 +40,14 @@ def get_context(self, context, page):
             filtered = context['cl'].is_filtered()
         elif context.has_key('filtered'):
             filtered = context['filtered']
-
+        language = context['preview_language']
 
 
         # following function is newly used for getting the context per item (line)
         # if something more will be required, then get_admin_menu_item_context
         # function have to be updated. 
         # This is done because item can be reloaded after some action over ajax.
-        context.update(get_admin_menu_item_context(request, page, filtered))
+        context.update(get_admin_menu_item_context(request, page, filtered, language))
 
         # this here is just context specific for menu rendering - items itself does
         # not use any of following variables
diff --git a/cms/utils/admin.py b/cms/utils/admin.py
--- a/cms/utils/admin.py
+++ b/cms/utils/admin.py
@@ -37,7 +37,7 @@ def jsonify_request(response):
 }
 
 
-def get_admin_menu_item_context(request, page, filtered=False):
+def get_admin_menu_item_context(request, page, filtered=False, language=None):
     """
     Used for rendering the page tree, inserts into context everything what
     we need for single item
@@ -80,6 +80,7 @@ def get_admin_menu_item_context(request, page, filtered=False):
         'lang': lang,
         'filtered': filtered,
         'metadata': metadata,
+        'preview_language': language,
         'has_change_permission': page.has_change_permission(request),
         'has_publish_permission': page.has_publish_permission(request),
         'has_delete_permission': page.has_delete_permission(request),
@@ -91,7 +92,7 @@ def get_admin_menu_item_context(request, page, filtered=False):
     return context
 
 
-def render_admin_menu_item(request, page, template=None):
+def render_admin_menu_item(request, page, template=None, language=None):
     """
     Renders requested page item for the tree. This is used in case when item
     must be reloaded over ajax.
@@ -110,7 +111,7 @@ def render_admin_menu_item(request, page, template=None):
     })
 
     filtered = 'filtered' in request.REQUEST
-    context.update(get_admin_menu_item_context(request, page, filtered))
+    context.update(get_admin_menu_item_context(request, page, filtered, language))
     # add mimetype to help out IE
     if DJANGO_1_4:
         return render_to_response(template, context, mimetype="text/html; charset=utf-8")


Test patch:
diff --git a/cms/tests/admin.py b/cms/tests/admin.py
--- a/cms/tests/admin.py
+++ b/cms/tests/admin.py
@@ -489,7 +489,7 @@ def test_changelist_tree(self):
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.context["open_menu_trees"], [1, 2])
         # tests descendants method for the lazy load ajax call
-        url = "%s%d/descendants/" % (url, first_level_page.pk)
+        url = "%s%d/en/descendants/" % (url, first_level_page.pk)
         response = self.client.get(url)
         self.assertEqual(response.status_code, 200)
         # should include both direct descendant pages