From 2c2570973403eecb6352f5c3d1b85944be13480b Mon Sep 17 00:00:00 2001 From: Florent Lebreton Date: Mon, 15 Dec 2014 11:57:35 +0100 Subject: [PATCH] Django 1.2 compatibility --- .travis.yml | 7 +++++++ safedelete/admin.py | 28 +++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 27c9087..16eee10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ python: - 3.4 env: + - DJANGO_VERSION=1.2 - DJANGO_VERSION=1.3 - DJANGO_VERSION=1.4 - DJANGO_VERSION=1.5 @@ -44,6 +45,12 @@ after_success: # We need to exclude old versions of Python for tests with Django >= 1.7. matrix: exclude: + - python: 3.2 + env: DJANGO_VERSION=1.2 + - python: 3.3 + env: DJANGO_VERSION=1.2 + - python: 3.4 + env: DJANGO_VERSION=1.2 - python: 3.2 env: DJANGO_VERSION=1.3 - python: 3.3 diff --git a/safedelete/admin.py b/safedelete/admin.py index b803297..f166de2 100644 --- a/safedelete/admin.py +++ b/safedelete/admin.py @@ -10,7 +10,14 @@ from django.contrib.admin.util import model_ngettext from django.contrib.contenttypes.models import ContentType from django.core.exceptions import PermissionDenied -from django.template.response import TemplateResponse + +try: + # Django >= 1.3 + from django.template.response import TemplateResponse +except ImportError: + from django.shortcuts import render_to_response + from django.template import RequestContext + try: # Django > 1.3 from django.utils.encoding import force_text @@ -137,10 +144,17 @@ def undelete_selected(self, request, queryset): 'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME, } - return TemplateResponse( - request, - self.undelete_selected_confirmation_template, - context, - current_app=self.admin_site.name, - ) + if django.VERSION[1] < 3: + return render_to_response( + self.undelete_selected_confirmation_template, + context, + context_instance=RequestContext(request)) + else: + return TemplateResponse( + request, + self.undelete_selected_confirmation_template, + context, + current_app=self.admin_site.name, + ) + undelete_selected.short_description = _("Undelete selected %(verbose_name_plural)s.")