Repository: django-cms/django-cms

Issue:
TemplateResponse in cms.views.detail



Discussion:

Resolving patch:
diff --git a/cms/views.py b/cms/views.py
--- a/cms/views.py
+++ b/cms/views.py
@@ -1,24 +1,25 @@
 # -*- coding: utf-8 -*-
 from __future__ import with_statement
+from django.template.response import TemplateResponse
 from cms.apphook_pool import apphook_pool
 from cms.appresolver import get_app_urls
 from cms.models import Title
 from cms.utils import get_template_from_request, get_language_from_request
-from cms.utils.i18n import get_fallback_languages, force_language, get_public_languages, get_redirect_on_fallback, get_language_list, is_language_prefix_patterns_used
+from cms.utils.i18n import get_fallback_languages, force_language, get_public_languages, get_redirect_on_fallback, \
+    get_language_list, is_language_prefix_patterns_used
 from cms.utils.page_resolver import get_page_from_request
 from cms.test_utils.util.context_managers import SettingsOverride
 from django.conf import settings
-from django.conf.urls.defaults import patterns
+from django.conf.urls import patterns
 from django.core.urlresolvers import resolve, Resolver404, reverse
 from django.http import Http404, HttpResponseRedirect
-from django.shortcuts import render_to_response
 from django.template.context import RequestContext
-from django.utils import translation
 from django.utils.http import urlquote
 
+
 def _handle_no_page(request, slug):
     if not slug and settings.DEBUG:
-        return render_to_response("cms/new.html", RequestContext(request))
+        return TemplateResponse(request, "cms/new.html", RequestContext(request))
     raise Http404('CMS: Page not found for "%s"' % slug)
 
 
@@ -51,7 +52,7 @@ def details(request, slug):
         attrs = '?preview=1'
         if 'draft' in request.GET:
             attrs += '&draft=1'
-    # Check that the language is in FRONTEND_LANGUAGES:
+        # Check that the language is in FRONTEND_LANGUAGES:
     if not current_language in user_languages:
         #are we on root?
         if not slug:
@@ -113,11 +114,11 @@ def details(request, slug):
                 return view(request, *args, **kwargs)
             except Resolver404:
                 pass
-        # Check if the page has a redirect url defined for this language.
+                # Check if the page has a redirect url defined for this language.
     redirect_url = page.get_redirect(language=current_language)
     if redirect_url:
         if (is_language_prefix_patterns_used() and redirect_url[0] == "/"
-            and not redirect_url.startswith('/%s/' % current_language)):
+        and not redirect_url.startswith('/%s/' % current_language)):
             # add language prefix to url
             redirect_url = "/%s/%s" % (current_language, redirect_url.lstrip("/"))
             # prevent redirect to self
@@ -145,4 +146,4 @@ def details(request, slug):
     if not context['has_view_permissions']:
         return _handle_no_page(request, slug)
 
-    return render_to_response(template_name, context_instance=context)
+    return TemplateResponse(request, template_name, context)


Test patch:
diff --git a/cms/tests/rendering.py b/cms/tests/rendering.py
--- a/cms/tests/rendering.py
+++ b/cms/tests/rendering.py
@@ -144,6 +144,7 @@ def test_details_view(self):
         with SettingsOverride(CMS_TEMPLATES=[(TEMPLATE_NAME, '')]):
             from cms.views import details
             response = details(self.get_request(self.test_page), '')
+            response.render()
             r = self.strip_rendered(response.content)
             self.assertEqual(r, u'|'+self.test_data['text_main']+u'|'+self.test_data['text_sub']+u'|')