Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.4 compatibility + 1.3 backward compatibility #1161

Merged
merged 6 commits into from
Jun 8, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cms/admin/change_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
17 changes: 8 additions & 9 deletions cms/admin/pageadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {})
Expand Down
2 changes: 1 addition & 1 deletion cms/templatetags/cms_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
11 changes: 7 additions & 4 deletions cms/tests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down