Permalink
Browse files

Fix for issues #830 and #835 including tests

  • Loading branch information...
1 parent 5ccf928 commit a89d326cf66dad5d6f30dfeadd15b1bfaf23a20d @vvangelovski vvangelovski committed Jun 9, 2011
Showing with 52 additions and 3 deletions.
  1. +1 −0 AUTHORS
  2. +5 −1 cms/admin/change_list.py
  3. +3 −0 cms/templatetags/cms_admin.py
  4. +43 −1 cms/tests/admin.py
  5. +0 −1 cms/utils/admin.py
View
@@ -159,6 +159,7 @@ Contributors (in alphabetical order):
* Tino de Bruijn
* tiret
* Ulrich Petri
+* Vasil Vangelovski
* wangJunjie
* Wayne Moore
* wid
View
@@ -75,7 +75,8 @@ def set_items(self, request):
site = self._current_site
# Get all the pages, ordered by tree ID (it's convenient to build the
# tree using a stack now)
- pages = self.get_query_set(request).drafts().order_by('tree_id', 'parent', 'lft').select_related()
+ pages = self.get_query_set(request).drafts().order_by('tree_id', 'lft').select_related()
+
# Get lists of page IDs for which the current user has
# "permission to..." on the current site.
@@ -121,9 +122,12 @@ def set_items(self, request):
# This is normally a tag filter, but it's really nice in our case too:
# It caches children for every page in the list we pass it, so no
# further queries are needed.
+
mptt_tags.cache_tree_children(pages)
for page in pages:
+
+
children = page.get_children()
# note: We are using change_list permission here, because we must
@@ -23,12 +23,15 @@ class ShowAdminMenu(InclusionTag):
def get_context(self, context, page):
request = context['request']
+
if context.has_key("cl"):
filtered = context['cl'].is_filtered()
elif context.has_key('filtered'):
filtered = context['filtered']
+
+
# 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.
View
@@ -3,14 +3,16 @@
from cms.admin.dialog.forms import (ModeratorForm, PermissionForm,
PermissionAndModeratorForm)
from cms.admin.dialog.views import _form_class_selector
-from cms.admin.pageadmin import contribute_fieldsets, contribute_list_filter
+from cms.admin.pageadmin import contribute_fieldsets, contribute_list_filter, PageAdmin
+from cms.admin.change_list import CMSChangeList
from cms.api import create_page, create_title, add_plugin
from cms.apphook_pool import apphook_pool, ApphookPool
from cms.models.moderatormodels import PageModeratorState
from cms.models.pagemodel import Page
from cms.models.permissionmodels import GlobalPagePermission
from cms.models.placeholdermodel import Placeholder
from cms.test_utils import testcases as base
+from cms.test_utils.util.request_factory import RequestFactory
from cms.test_utils.testcases import (CMSTestCase, URL_CMS_PAGE_DELETE,
URL_CMS_PAGE, URL_CMS_TRANSLATION_DELETE)
from cms.test_utils.util.context_managers import SettingsOverride
@@ -28,6 +30,10 @@
class AdminTestCase(CMSTestCase):
+
+ def setUp(self):
+ self.request_factory = RequestFactory()
+
def _get_guys(self, admin_only=False):
admin = self.get_superuser()
if admin_only:
@@ -226,6 +232,42 @@ def test_get_permissions(self):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertTemplateNotUsed(response, 'admin/login.html')
+
+ def test_changelist_items(self):
+ admin = self._get_guys(True)
+ first_level_page = create_page('level1', 'nav_playground.html', 'en')
+ second_level_page_top = create_page('level21', "nav_playground.html", "en",
+ created_by=admin, published=True, parent= first_level_page)
+ second_level_page_bottom = create_page('level22', "nav_playground.html", "en",
+ created_by=admin, published=True, parent= self.reload(first_level_page))
+ third_level_page = create_page('level3', "nav_playground.html", "en",
+ created_by=admin, published=True, parent= second_level_page_top)
+ self.assertEquals(Page.objects.all().count(), 4)
+
+ url = reverse('admin:cms_%s_changelist' % Page._meta.module_name)
+ request = self.request_factory.get(url)
+
+ request.session = {}
+ request.user = admin
+
+ page_admin = site._registry[Page]
+
+ cl = CMSChangeList(request, page_admin.model, page_admin.list_display,
+ page_admin.list_display_links, page_admin.list_filter,
+ page_admin.date_hierarchy, page_admin.search_fields,
+ page_admin.list_select_related, page_admin.list_per_page,
+ page_admin.list_editable, page_admin)
+
+ cl.set_items(request)
+
+
+ root_page = cl.get_items()[0]
+
+ self.assertEqual(root_page, first_level_page)
+ self.assertEqual(root_page.get_children()[0], second_level_page_top)
+ self.assertEqual(root_page.get_children()[1], second_level_page_bottom)
+ self.assertEqual(root_page.get_children()[0].get_children()[0], third_level_page)
+
class AdminFieldsetTests(TestCase):
View
@@ -48,7 +48,6 @@ def get_admin_menu_item_context(request, page, filtered=False):
if not has_add_on_same_level_permission and page.parent_id:
has_add_on_same_level_permission = permissions.has_generic_permission(page.parent_id, request.user, "add", page.site)
#has_add_on_same_level_permission = has_add_page_on_same_level_permission(request, page)
-
context = {
'page': page,
'site': site,

0 comments on commit a89d326

Please sign in to comment.