Migrate RequestContext users to render() calls.

This was necessary because render_to_response no longer takes a
context_instance.  We were always using this to pass in a RequestContext,
which the render shortcut can already do, so switch to that.
This commit is contained in:
Brett Smith 2017-11-03 11:58:24 -04:00
parent b2a006f49c
commit 66dbfac066
8 changed files with 21 additions and 36 deletions

View file

@ -1,9 +1,12 @@
import hashlib
from django.conf import settings
from django.shortcuts import render_to_response
from django.template import RequestContext
# This is backwards compatibilty support for a custom function we wrote
# ourselves that is no longer necessary in modern Django.
from django.shortcuts import render as render_template_with_context
class ParameterValidator(object):
def __init__(self, given_hash_or_params, params_hash_key=None):
if params_hash_key is None:
@ -41,8 +44,3 @@ class ParameterValidator(object):
def fail(self):
self.valid = False
def render_template_with_context(request, template_path, context_dict):
return render_to_response(template_path, context_dict,
context_instance=RequestContext(request))

View file

@ -4,8 +4,7 @@ from django.views.generic import ListView
from django.views.generic.dates import YearArchiveView, MonthArchiveView, DayArchiveView, DateDetailView
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from conservancy.apps.staff.models import Person
from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
from django.shortcuts import get_object_or_404, render
from datetime import datetime
def OR_filter(field_name, objs):
@ -65,7 +64,7 @@ def custom_index(request, queryset, *args, **kwargs):
extra_context['blog_entries'] = blog_entries
return render_to_response('blog/entry_list.html', extra_context, context_instance=RequestContext(request))
return render(request, 'blog/entry_list.html', extra_context)
def techblog_redirect(request):
"""Redirect from the old 'techblog' to the new blog
@ -103,8 +102,7 @@ def query(request):
entry__isnull=False).distinct(),
key=last_name)
tags = EntryTag.objects.all().order_by('label')
return render_to_response('blog/query.html',
{'authors': authors, 'tags': tags}, context_instance=RequestContext(request))
return render(request, 'blog/query.html', {'authors': authors, 'tags': tags})
def relative_redirect(request, path):
from django import http

View file

@ -1,5 +1,4 @@
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.shortcuts import render
from django import forms
from conservancy.apps.contacts.models import ContactEntry
from django.forms import ModelForm
@ -18,10 +17,8 @@ def subscribe(request):
form = ContactEntryForm(request.POST)
if form.is_valid():
form.save()
return render_to_response('contacts/subscribe_success.html',
{'form': form.cleaned_data}, context_instance=RequestContext(request))
return render(request, 'contacts/subscribe_success.html', {'form': form.cleaned_data})
else:
form = ContactEntryForm()
return render_to_response('contacts/subscribe.html',
{'form': form}, context_instance=RequestContext(request))
return render(request, 'contacts/subscribe.html', {'form': form})

View file

@ -1,6 +1,5 @@
# from django.views.generic.list_detail import object_list
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.shortcuts import render
from django.http import Http404, HttpResponse
from django.template import loader
from django.core.exceptions import ObjectDoesNotExist
@ -21,7 +20,7 @@ def event_detail(request, year, slug, queryset, **kwargs):
event = queryset.get(date__year=year, slug__exact=slug)
except ObjectDoesNotExist:
raise Http404, "Event does not exist"
return render_to_response('events/event_detail.html', {'event': event}, context_instance=RequestContext(request))
return render(request, 'events/event_detail.html', {'event': event})
def custom_index(request, queryset, *args, **kwargs):
"""Scrollable index of future and past events, with date index.

View file

@ -1,7 +1,6 @@
# from django.views.generic.list_detail import object_list
from django.views.generic import ListView
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.shortcuts import render
from django.views.generic.dates import YearArchiveView, MonthArchiveView, DayArchiveView, DateDetailView
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from conservancy.apps.news.models import ExternalArticle
@ -42,7 +41,7 @@ def listing(request, *args, **kwargs):
# If page is out of range (e.g. 9999), deliver last page of results.
news = paginator.page(paginator.num_pages)
return render_to_response('news/pressrelease_list.html', {"news": news, "date_list" : date_list}, context_instance=RequestContext(request))
return render(request, 'news/pressrelease_list.html', {"news": news, "date_list" : date_list})
class NewsYearArchiveView(YearArchiveView):
# queryset = Article.objects.all()

View file

@ -1,7 +1,5 @@
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.shortcuts import render
from django import forms
from django.template import RequestContext
from conervancy.apps.summit_registration.models import SummitRegistration
def register(request):
@ -21,10 +19,8 @@ def register(request):
form = SummitForm(request.POST)
if form.is_valid():
form.save()
return render_to_response('summit_registration/register_success.html',
{'form': form.cleaned_data}, context_instance=RequestContext(request))
return render(reqeust, 'summit_registration/register_success.html', {'form': form.cleaned_data})
else:
form = SummitForm()
return render_to_response('summit_registration/register.html',
{'form': form}, context_instance=RequestContext(request))
return render(request, 'summit_registration/register.html', {'form': form})

View file

@ -2,8 +2,7 @@ from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Rss201rev2Feed
from conservancy.apps.news.models import PressRelease
from conservancy.apps.blog.models import Entry as BlogEntry
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.shortcuts import render
from django.conf import settings
from datetime import datetime
@ -255,4 +254,4 @@ def view(request):
"""
feeds = (PressReleaseFeed, BlogFeed, OmnibusFeed)
return render_to_response("feeds.html", {'feeds': feeds}, context_instance=RequestContext(request))
return render(request, "feeds.html", {'feeds': feeds})

View file

@ -1,5 +1,4 @@
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.shortcuts import render
from conservancy.apps.supporters.models import Supporter as Supporter
from datetime import datetime, timedelta
@ -19,4 +18,4 @@ def view(request):
'supporters_count' : supporters_count,
'anonymous_count' : anonymous_count
}
return render_to_response("sponsors.html", c, context_instance=RequestContext(request))
return render(request, "sponsors.html", c)