1.4 compatibility + 1.3 backward compatibility #1161

Merged
merged 6 commits into from Jun 8, 2012
View
8 cms/admin/change_list.py
@@ -8,6 +8,7 @@
from django.contrib.admin.views.main import ChangeList, ALL_VAR, IS_POPUP_VAR, \
ORDER_TYPE_VAR, ORDER_VAR, SEARCH_VAR
from django.contrib.sites.models import Site
+import django
COPY_VAR = "copy"
@@ -54,9 +55,9 @@ class CMSChangeList(ChangeList):
real_queryset = False
def __init__(self, request, *args, **kwargs):
- super(CMSChangeList, self).__init__(request, *args, **kwargs)
from cms.utils.plugins import current_site
self._current_site = current_site(request)
+ super(CMSChangeList, self).__init__(request, *args, **kwargs)
try:
self.query_set = self.get_query_set(request)
except:
@@ -70,7 +71,10 @@ def __init__(self, request, *args, **kwargs):
def get_query_set(self, request=None):
if COPY_VAR in self.params:
del self.params[COPY_VAR]
- qs = super(CMSChangeList, self).get_query_set().drafts()
+ if django.VERSION >= (1, 4):
+ qs = super(CMSChangeList, self).get_query_set(request).drafts()
+ else:
+ qs = super(CMSChangeList, self).get_query_set().drafts()
if request:
site = self._current_site
permissions = Page.permissions.get_change_id_list(request.user, site)
View
17 cms/admin/pageadmin.py
@@ -461,7 +461,9 @@ def get_form(self, request, obj=None, **kwargs):
# remove permission inlines, if user isn't allowed to change them
def get_formsets(self, request, obj=None):
if obj:
- for inline in self.inline_instances:
+ inlines = self.get_inline_instances(request) if hasattr(self, 'get_inline_instances') \
+ else self.inline_instances
+ for inline in inlines:
if settings.CMS_PERMISSION and isinstance(inline, PagePermissionInlineAdmin) and not isinstance(inline, ViewRestrictionInlineAdmin):
if "recover" in request.path or "history" in request.path: #do not display permissions in recover mode
continue
@@ -639,12 +641,12 @@ def changelist_view(self, request, extra_context=None):
if not self.has_change_permission(request, None):
raise PermissionDenied
try:
- if hasattr(self, 'list_editable'):# django 1.1
+ if django.VERSION >= (1, 4):
cl = CMSChangeList(request, self.model, self.list_display, self.list_display_links, self.list_filter,
- self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_editable, self)
- else:# django 1.0.2
+ self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_max_show_all, self.list_editable, self)
+ else:
cl = CMSChangeList(request, self.model, self.list_display, self.list_display_links, self.list_filter,
- self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self)
+ self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_editable, self)
except IncorrectLookupParameters:
# Wacky lookup parameters were given, so redirect to the main
# changelist page, without parameters, and pass an 'invalid=1'
@@ -667,14 +669,13 @@ def changelist_view(self, request, extra_context=None):
languages = settings.CMS_SITE_LANGUAGES[site_id]
else:
languages = [x[0] for x in settings.CMS_LANGUAGES]
-
+
context = {
'title': cl.title,
'is_popup': cl.is_popup,
'cl': cl,
'opts':opts,
'has_add_permission': self.has_add_permission(request),
- 'root_path': self.admin_site.root_path,
'app_label': app_label,
'CMS_MEDIA_URL': settings.CMS_MEDIA_URL,
'softroot': settings.CMS_SOFTROOT,
@@ -936,7 +937,6 @@ def delete_translation(self, request, object_id, extra_context=None):
saved_plugins = CMSPlugin.objects.filter(placeholder__page__id=object_id, language=language)
if django.VERSION[1] > 2: # pragma: no cover
- # WARNING: Django 1.3 is not officially supported yet!
using = router.db_for_read(self.model)
kwargs = {
'admin_site': self.admin_site,
@@ -994,7 +994,6 @@ def delete_translation(self, request, object_id, extra_context=None):
"deleted_objects": deleted_objects,
"perms_lacking": perms_needed,
"opts": titleopts,
- "root_path": self.admin_site.root_path,
"app_label": app_label,
}
context.update(extra_context or {})
View
2 cms/templatetags/cms_admin.py
@@ -68,7 +68,7 @@ def get_context(self, context, cl, spec):
if choice['query_string'] != query_string:
unique_choices.append(choice)
query_string = choice['query_string']
- return {'title': spec.title(), 'choices' : unique_choices}
+ return {'title': spec.title, 'choices' : unique_choices}
register.tag(CleanAdminListFilter)
View
11 cms/tests/admin.py
@@ -351,12 +351,15 @@ def test_changelist_items(self):
request.user = admin
page_admin = site._registry[Page]
-
- cl = CMSChangeList(request, page_admin.model, page_admin.list_display,
+
+ cl_params = [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)
+ page_admin.list_select_related, page_admin.list_per_page]
+ if hasattr(page_admin, 'list_max_show_all'): # django 1.4
+ cl_params.append(page_admin.list_max_show_all)
+ cl_params.extend([page_admin.list_editable, page_admin])
+ cl = CMSChangeList(*tuple(cl_params))
cl.set_items(request)