[damned-lies] Replace render_to_response shortcut by render



commit 1fa95b6f73c6c5827d1644c2806aa7c22613f634
Author: Claude Paroz <claude 2xlibre net>
Date:   Tue May 17 09:12:17 2011 +0200

    Replace render_to_response shortcut by render

 common/views.py    |   22 +++++++++++-----------
 languages/views.py |   25 +++++++++++--------------
 people/views.py    |   11 +++--------
 stats/admin.py     |    5 ++---
 stats/views.py     |   23 +++++++++++------------
 teams/views.py     |   19 +++++++------------
 vertimus/views.py  |   22 ++++++++++------------
 7 files changed, 55 insertions(+), 72 deletions(-)
---
diff --git a/common/views.py b/common/views.py
index d083f69..f9de757 100644
--- a/common/views.py
+++ b/common/views.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (c) 2008 Claude Paroz <claude 2xlibre net>.
+# Copyright (c) 2008-2011 Claude Paroz <claude 2xlibre net>.
 #
 # This file is part of Damned Lies.
 #
@@ -18,14 +18,14 @@
 # along with Damned Lies; if not, write to the Free Software Foundation, Inc.,
 # 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-from django.shortcuts import render_to_response
-from django.http import HttpResponseRedirect
-from django.core.urlresolvers import reverse
-from django.template import RequestContext
-from django.utils.translation import ugettext as _
+from django.conf import settings
 from django.contrib.auth import login, authenticate, logout
 from django.contrib import messages
-from django.conf import settings
+from django.core.urlresolvers import reverse
+from django.http import HttpResponseRedirect
+from django.shortcuts import render
+from django.utils.translation import ugettext as _
+
 from people.models import Person
 from teams.models import Role
 from people.forms import RegistrationForm
@@ -48,7 +48,7 @@ def index(request):
         'user_language': curlang,
         'translator_credits': translator_credits
     }
-    return render_to_response('index.html', context, context_instance=RequestContext(request))
+    return render(request, 'index.html', context)
 
 def site_login(request):
     """ Site-specific login page. Not named 'login' to not confuse with auth.login """
@@ -90,7 +90,7 @@ def site_login(request):
         'referer': referer,
         'next': referer,
     }
-    return render_to_response('login.html', context, context_instance=RequestContext(request))
+    return render(request, 'login.html', context)
 
 def site_register(request):
     openid_path = ''
@@ -108,14 +108,14 @@ def site_register(request):
         'form': form,
         'openid_path': openid_path,
     }
-    return render_to_response('registration/register.html', context, context_instance=RequestContext(request))
+    return render(request, 'registration/register.html', context)
 
 def activate_account(request, key):
     """ Activate an account through the link a requestor has received by email """
     try:
         person = Person.objects.get(activation_key=key)
     except Person.DoesNotExist:
-        return render_to_response('error.html', {'error':"Sorry, the key you provided is not valid."})
+        return render(request, 'error.html', {'error': _("Sorry, the key you provided is not valid.")})
     person.activate()
     messages.success(request, _("Your account has been activated."))
     return site_login(request)
diff --git a/languages/views.py b/languages/views.py
index cf245e8..aba04be 100644
--- a/languages/views.py
+++ b/languages/views.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 #
 # Copyright (c) 2008 Stéphane Raimbault <stephane raimbault gmail com>
-# Copyright (c) 2008 Claude Paroz <claude 2xlibre net>
+# Copyright (c) 2008-2011 Claude Paroz <claude 2xlibre net>
 #
 # This file is part of Damned Lies.
 #
@@ -19,14 +19,15 @@
 # along with Damned Lies; if not, write to the Free Software Foundation, Inc.,
 # 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+from datetime import date, datetime
 import os
 import tarfile
-from datetime import date, datetime
-from django.shortcuts import render_to_response, get_object_or_404
-from django.utils.translation import ugettext as _
-from django.template import RequestContext
-from django.http import HttpResponse, HttpResponseRedirect
+
 from django.conf import settings
+from django.http import HttpResponse, HttpResponseRedirect
+from django.shortcuts import render, get_object_or_404
+from django.utils.translation import ugettext as _
+
 from common import utils
 from languages.models import Language
 from stats.models import Release, Statistics
@@ -38,8 +39,7 @@ def languages(request):
         'languages': utils.trans_sort_object_list(languages, 'name'),
         'bug_url': settings.ENTER_BUG_URL,
     }
-    return render_to_response('languages/language_list.html', context,
-                              context_instance=RequestContext(request))
+    return render(request, 'languages/language_list.html', context)
 
 def language_all(request, locale, dtype):
     language = get_object_or_404(Language, locale=locale)
@@ -54,8 +54,7 @@ def language_all(request, locale, dtype):
         'stats': stats,
         'scope': dtype.endswith('-part') and 'part' or 'full',
     }
-    return render_to_response('languages/language_all_modules.html', context,
-                              context_instance=RequestContext(request))
+    return render(request, 'languages/language_all_modules.html', context)
 
 def release_archives(request, locale):
     """ This view is used to display archive release stats through Ajax call
@@ -67,8 +66,7 @@ def release_archives(request, locale):
         'stats': language.get_release_stats(archives=True),
         'show_all_modules_line': False,
     }
-    return render_to_response('languages/language_release_summary.html', context,
-                              context_instance=RequestContext(request))
+    return render(request, 'languages/language_release_summary.html', context)
 
 def language_release(request, locale, release_name, dtype):
     if locale == 'C':
@@ -90,8 +88,7 @@ def language_release(request, locale, release_name, dtype):
         'dtype': dtype,
         'scope': dtype.endswith('-part') and 'part' or 'full',
     }
-    return render_to_response('languages/language_release.html', context,
-                              context_instance=RequestContext(request))
+    return render(request, 'languages/language_release.html', context)
 
 def language_release_tar(request, locale, release_name, dtype):
     release = get_object_or_404(Release, name=release_name)
diff --git a/people/views.py b/people/views.py
index ce019ee..fdfbd26 100644
--- a/people/views.py
+++ b/people/views.py
@@ -29,8 +29,7 @@ from django.contrib.sites.models import Site
 from django.core import urlresolvers
 from django.db import IntegrityError
 from django.http import HttpResponseRedirect
-from django.shortcuts import render_to_response, get_object_or_404
-from django.template import RequestContext
+from django.shortcuts import render, get_object_or_404
 from django.utils.translation import ugettext_lazy, ugettext as _
 from django.views.generic import ListView, DetailView, UpdateView
 
@@ -113,10 +112,7 @@ def person_team_join(request):
         'on_own_page': person.username == request.user.username,
         'form': form,
     }
-
-    context_instance = RequestContext(request)
-    return render_to_response('people/person_team_join_form.html', context,
-            context_instance=context_instance)
+    return render(request, 'people/person_team_join_form.html', context)
 
 @login_required
 def person_team_leave(request, team_slug):
@@ -152,5 +148,4 @@ def person_password_change(request):
         'on_own_page': person.username == request.user.username,
         'form': form,
     }
-    return render_to_response('people/person_password_change_form.html', context,
-            context_instance=RequestContext(request))
+    return render(request, 'people/person_password_change_form.html', context)
diff --git a/stats/admin.py b/stats/admin.py
index abf55d6..cb4cbf4 100644
--- a/stats/admin.py
+++ b/stats/admin.py
@@ -20,8 +20,7 @@
 
 from django.contrib import admin
 from django.contrib.admin import helpers
-from django.shortcuts import render_to_response
-from django.template import RequestContext
+from django.shortcuts import render
 from django.utils.encoding import force_unicode
 from django import forms
 from stats.models import Statistics, Information, Module, Branch, Domain, Category, Release
@@ -112,7 +111,7 @@ class ReleaseAdmin(admin.ModelAdmin):
             "model_label": self.model._meta.verbose_name_plural,
             "action_checkbox_name": helpers.ACTION_CHECKBOX_NAME,
         }
-        return render_to_response('admin/delete_release_confirmation.html', context, context_instance=RequestContext(request))
+        return render(request, 'admin/delete_release_confirmation.html', context)
     delete_release.short_description = "Delete release (and associated branches)"
 
 class InformationInline(admin.TabularInline):
diff --git a/stats/views.py b/stats/views.py
index 4558be5..7b48dab 100644
--- a/stats/views.py
+++ b/stats/views.py
@@ -21,12 +21,11 @@ from datetime import date
 import os
 
 from django.conf import settings
-from django.shortcuts import render_to_response, get_object_or_404
 from django.contrib.auth.decorators import login_required
 from django.contrib import messages
 from django.core import serializers
 from django.http import HttpResponse, Http404
-from django.template import RequestContext
+from django.shortcuts import render, get_object_or_404
 from django.utils.translation import ugettext as _
 
 from common.utils import MIME_TYPES
@@ -46,7 +45,7 @@ def modules(request, format='html'):
         'modules': utils.sort_object_list(all_modules, 'get_description'),
         'bug_url': settings.ENTER_BUG_URL,
     }
-    return render_to_response('module_list.html', context, context_instance=RequestContext(request))
+    return render(request, 'module_list.html', context)
 
 def module(request, module_name):
     mod = get_object_or_404(Module, name=module_name)
@@ -65,7 +64,7 @@ def module(request, module_name):
         'non_standard_repo_msg' : _(settings.VCS_HOME_WARNING),
         'can_edit_branches': mod.can_edit_branches(request.user),
     }
-    return render_to_response('module_detail.html', context, context_instance=RequestContext(request))
+    return render(request, 'module_detail.html', context)
 
 def module_branch(request, module_name, branch_name):
     """ This view is used to dynamically load a specific branch stats (jquery.load) """
@@ -75,7 +74,7 @@ def module_branch(request, module_name, branch_name):
         'module': mod,
         'branch': branch,
     }
-    return render_to_response('branch_detail.html', context, context_instance=RequestContext(request))
+    return render(request, 'branch_detail.html', context)
 
 @login_required
 def module_edit_branches(request, module_name):
@@ -143,7 +142,7 @@ def module_edit_branches(request, module_name):
         'module': mod,
         'form': form,
     }
-    return render_to_response('module_edit_branches.html', context, context_instance=RequestContext(request))
+    return render(request, 'module_edit_branches.html', context)
 
 def docimages(request, module_name, potbase, branch_name, langcode):
     mod = get_object_or_404(Module, name=module_name)
@@ -161,7 +160,7 @@ def docimages(request, module_name, potbase, branch_name, langcode):
         'module': mod,
         'stat': stat
     }
-    return render_to_response('module_images.html', context, context_instance=RequestContext(request))
+    return render(request, 'module_images.html', context)
 
 def dynamic_po(request, filename):
     """ Generates a dynamic po file from the POT file of a branch """
@@ -237,18 +236,18 @@ def releases(request, format='html'):
         'old_releases'   : old_releases,
         'bug_url'        : settings.ENTER_BUG_URL,
     }
-    return render_to_response('release_list.html', context, context_instance=RequestContext(request))
+    return render(request, 'release_list.html', context)
 
 def release(request, release_name, format='html'):
     release = get_object_or_404(Release, name=release_name)
     if format == 'xml':
-        return render_to_response('release_detail.xml', { 'release' : release },
-                                  mimetype=MIME_TYPES[format])
+        return render(request, 'release_detail.xml', { 'release' : release },
+                                  content_type=MIME_TYPES[format])
     context = {
         'pageSection': "releases",
         'release': release
     }
-    return render_to_response('release_detail.html', context, context_instance=RequestContext(request))
+    return render(request, 'release_detail.html', context)
 
 def compare_by_releases(request, dtype, rels_to_compare):
     releases = []
@@ -265,4 +264,4 @@ def compare_by_releases(request, dtype, rels_to_compare):
         'releases': releases,
         'stats': stats
     }
-    return render_to_response('release_compare.html', context, context_instance=RequestContext(request))
+    return render(request, 'release_compare.html', context)
diff --git a/teams/views.py b/teams/views.py
index dfd5ea9..b9b82be 100644
--- a/teams/views.py
+++ b/teams/views.py
@@ -22,8 +22,7 @@
 from django.conf import settings
 from django.core.urlresolvers import reverse
 from django.http import HttpResponseRedirect, HttpResponseForbidden
-from django.shortcuts import render_to_response, get_object_or_404
-from django.template import RequestContext
+from django.shortcuts import render, get_object_or_404
 from django.utils.translation import ugettext_lazy as _
 
 from common import utils
@@ -35,20 +34,16 @@ def teams(request, format='html'):
     teams = Team.objects.all_with_coordinator()
     format = request.GET.get('format') or format
     if format == 'xml':
-        return render_to_response(
-            'teams/team_list.xml',
-            { 'teams' : teams },
-            context_instance=RequestContext(request),
-            mimetype=utils.MIME_TYPES[format]
-            )
+        return render(request, 'teams/team_list.xml', { 'teams' : teams },
+            content_type=utils.MIME_TYPES[format]
+        )
     else:
         context = {
             'pageSection': 'teams',
             'teams': utils.trans_sort_object_list(teams, 'description'),
             'bug_url': settings.ENTER_BUG_URL,
         }
-        return render_to_response('teams/team_list.html', context,
-                                  context_instance=RequestContext(request))
+        return render(request, 'teams/team_list.html', context)
 
 def team(request, team_slug):
     try:
@@ -119,7 +114,7 @@ def team(request, team_slug):
 
     context['mem_groups'] = mem_groups
     context['can_edit_details'] = context['can_edit_team'] or utils.is_site_admin(request.user)
-    return render_to_response('teams/team_detail.html', context, context_instance=RequestContext(request))
+    return render(request, 'teams/team_detail.html', context)
 
 def team_edit(request, team_slug):
     team = get_object_or_404(Team, name=team_slug)
@@ -134,4 +129,4 @@ def team_edit(request, team_slug):
         'team': team,
         'form': form
     }
-    return render_to_response('teams/team_edit.html', context, context_instance=RequestContext(request))
+    return render(request, 'teams/team_edit.html', context)
diff --git a/vertimus/views.py b/vertimus/views.py
index ea35c2e..b21c2bc 100644
--- a/vertimus/views.py
+++ b/vertimus/views.py
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 #
 # Copyright (c) 2008 Stéphane Raimbault <stephane raimbault gmail com>
+# Copyright (c) 2011 Claude Paroz <claude 2xlibre net>
 #
 # This file is part of Damned Lies.
 #
@@ -19,11 +20,10 @@
 # 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 from django.conf import settings
-from django.utils.translation import ugettext as _
-from django.shortcuts import render_to_response, get_object_or_404
-from django.http import HttpResponseRedirect, Http404
-from django.template import RequestContext
 from django.core import urlresolvers
+from django.http import HttpResponseRedirect, Http404
+from django.shortcuts import render, get_object_or_404
+from django.utils.translation import ugettext as _
 
 from stats.models import Statistics, Module, Branch, Domain, Language
 from stats.utils import is_po_reduced
@@ -138,8 +138,7 @@ def vertimus(request, branch, domain, language, stats=None, level="0"):
         'level': level,
         'grandparent_level': grandparent_level,
     }
-    return render_to_response('vertimus/vertimus_detail.html', context,
-                              context_instance=RequestContext(request))
+    return render(request, 'vertimus/vertimus_detail.html', context)
 
 
 def vertimus_diff(request, action_id_1, action_id_2, level):
@@ -158,8 +157,8 @@ def vertimus_diff(request, action_id_1, action_id_2, level):
     try:
         content_1 = [l.decode('utf-8') for l in open(file_path_1, 'U').readlines()]
     except UnicodeDecodeError:
-        return render_to_response('error.html',
-                                  {'error': _("Error: The file %s contains invalid characters.") % file_path_1.split('/')[-1]})
+        return render(request, 'error.html',
+                      {'error': _("Error: The file %s contains invalid characters.") % file_path_1.split('/')[-1]})
     descr_1 = _("Uploaded file by %(name)s on %(date)s") % { 'name': action_1.person.name,
                                                              'date': action_1.created }
     if action_id_2 not in (None, "0"):
@@ -190,8 +189,8 @@ def vertimus_diff(request, action_id_1, action_id_2, level):
     try:
         content_2 = [l.decode('utf-8') for l in open(file_path_2, 'U').readlines()]
     except UnicodeDecodeError:
-        return render_to_response('error.html',
-                                  {'error': _("Error: The file %s contains invalid characters.") % file_path_2.split('/')[-1]})
+        return render(request, 'error.html',
+                      {'error': _("Error: The file %s contains invalid characters.") % file_path_2.split('/')[-1]})
     d = difflib.HtmlDiff(wrapcolumn=80)
     diff_content = d.make_table(content_2, content_1,
                                 descr_2, descr_1, context=True)
@@ -200,8 +199,7 @@ def vertimus_diff(request, action_id_1, action_id_2, level):
         'diff_content': diff_content,
         'state': state,
     }
-    return render_to_response('vertimus/vertimus_diff.html', context,
-                              context_instance=RequestContext(request))
+    return render(request, 'vertimus/vertimus_diff.html', context)
 
 def latest_uploaded_po(request, module_name, branch_name, domain_name, locale_name):
     """ Redirect to the latest uploaded po for a module/branch/language """



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]