From 62caf55fe64ecfd6c94a7731510a92617970b7ce Mon Sep 17 00:00:00 2001 From: j Date: Sat, 20 Feb 2016 00:25:48 +0530 Subject: [PATCH] stop using RequestContext --- pandora/app/views.py | 12 ++++-------- pandora/archive/views.py | 6 ++---- pandora/item/views.py | 10 ++++------ pandora/text/views.py | 16 +++++++--------- pandora/user/views.py | 26 +++++++++++++------------- 5 files changed, 30 insertions(+), 40 deletions(-) diff --git a/pandora/app/views.py b/pandora/app/views.py index 8b84ab4d7..3fd0cd805 100644 --- a/pandora/app/views.py +++ b/pandora/app/views.py @@ -3,8 +3,7 @@ import copy from datetime import datetime -from django.shortcuts import render_to_response, redirect -from django.template import RequestContext +from django.shortcuts import render, redirect from django.conf import settings from django.http import HttpResponse @@ -22,8 +21,7 @@ from changelog.models import add_changelog from ox.django.api import actions def intro(request): - context = RequestContext(request, {'settings': settings}) - return render_to_response('intro.html', context) + return render(request, 'intro.html', {'settings': settings}) def index(request): title = settings.SITENAME @@ -38,19 +36,17 @@ def index(request): title += ' - ' + p['title'] text, created = models.Page.objects.get_or_create(name=page) text = text.text - context = RequestContext(request, { + return render(request, 'index.html', { 'base_url': request.build_absolute_uri('/'), 'settings': settings, 'text': text, 'title': title, }) - return render_to_response('index.html', context) def embed(request, id): - context = RequestContext(request, { + return render(request, 'embed.html', { 'settings': settings }) - return render_to_response('embed.html', context) def redirect_url(request, url): if request.META['QUERY_STRING']: diff --git a/pandora/archive/views.py b/pandora/archive/views.py index 8780ce907..3d031dab2 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -5,8 +5,7 @@ import os.path from datetime import datetime from django import forms -from django.shortcuts import get_object_or_404, redirect, render_to_response -from django.template import RequestContext +from django.shortcuts import get_object_or_404, redirect, render from django.conf import settings from django.db.models import Count, Q @@ -224,12 +223,11 @@ actions.register(addMedia, cache=False) @login_required_json def firefogg_upload(request): if not 'profile' in request.GET or not 'id' in request.GET: - context = RequestContext(request, { + return render(request, 'api.html', { 'api': [], 'settings': settings, 'sitename': settings.SITENAME }) - return render_to_response('api.html', context) profile = request.GET['profile'] oshash = request.GET['id'] config = settings.CONFIG['video'] diff --git a/pandora/item/views.py b/pandora/item/views.py index f728286cd..4d9ed4777 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -10,9 +10,8 @@ import time import Image from django.db.models import Count, Sum -from django.template import RequestContext from django.http import HttpResponse, HttpResponseForbidden, Http404 -from django.shortcuts import get_object_or_404, redirect, render_to_response +from django.shortcuts import get_object_or_404, redirect, render from django.core.files.temp import NamedTemporaryFile from wsgiref.util import FileWrapper from django.conf import settings @@ -1240,10 +1239,10 @@ def item(request, id): level = request.user.profile.level qs = models.Item.objects.filter(public_id=id, level__lte=level) if qs.count() == 0: - context = RequestContext(request, { + ctx = { 'base_url': request.build_absolute_uri('/'), 'settings': settings - }) + } else: item = qs[0] template = 'item.html' @@ -1340,6 +1339,5 @@ def item(request, id): if value: ctx['keywords'] = ox.strip_tags(value) - context = RequestContext(request, ctx) - return render_to_response(template, context) + return render(request, template, ctx) diff --git a/pandora/text/views.py b/pandora/text/views.py index 81b70ca63..5a1026a12 100644 --- a/pandora/text/views.py +++ b/pandora/text/views.py @@ -13,8 +13,7 @@ from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, from django import forms from django.db.models import Sum, Max from django.conf import settings -from django.shortcuts import render_to_response -from django.template import RequestContext +from django.shortcuts import render from item import utils from archive.chunk import process_chunk @@ -381,13 +380,12 @@ def icon(request, id, size=16): def pdf_viewer(request, id): text = get_text_or_404_json(id) if text.type == 'pdf' and text.file and not text.uploading: - context = RequestContext(request, { + return render(request, 'pdf/viewer.html', { 'editable': json.dumps(text.editable(request.user)), 'embeds': json.dumps(text.embeds), 'settings': settings, 'url': text.get_absolute_pdf_url() }) - return render_to_response('pdf/viewer.html', context) response = json_response(status=404, text='file not found') return render_to_json_response(response) @@ -434,7 +432,7 @@ def text(request, id=''): if id != '' and not text.accessible(request.user): raise template = 'text.html' - context = RequestContext(request, { + context = { 'base_url': request.build_absolute_uri('/'), 'description': ox.strip_tags(text.description), 'icon': request.build_absolute_uri('/text/%s/icon256.jpg' % text.get_id()), @@ -442,12 +440,12 @@ def text(request, id=''): 'text': text, 'title': ox.strip_tags(text.name), 'url': request.build_absolute_uri(text.get_absolute_url()), - }) + } except: template = 'index.html' - context = RequestContext(request, { + context = { 'base_url': request.build_absolute_uri('/'), 'settings': settings, 'title': settings.SITENAME - }) - return render_to_response(template, context) + } + return render(request, template, context) diff --git a/pandora/user/views.py b/pandora/user/views.py index 767f6e975..d7d91b62a 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -6,7 +6,7 @@ import re import json from django.contrib.auth import authenticate, login, logout -from django.template import RequestContext, loader +from django.template import loader from django.conf import settings from django.core.mail import send_mail, BadHeaderError, EmailMessage from django.shortcuts import redirect @@ -306,13 +306,13 @@ def requestToken(request, data): user_profile.save() template = loader.get_template('password_reset_email.txt') - context = RequestContext(request, { + context = { 'code': code, 'sitename': settings.SITENAME, 'footer': settings.CONFIG['site']['email']['footer'], 'url': request.build_absolute_uri('/'), - }) - message = template.render(context) + } + message = template.render(context, request) subject = '%s - Reset Password' % settings.SITENAME user.email_user(subject, message) response = json_response({ @@ -593,14 +593,14 @@ def mail(request, data): if 'receipt' in data \ and data['receipt']: template = loader.get_template('mailout_receipt.txt') - context = RequestContext(request, { + context = { 'footer': settings.CONFIG['site']['email']['footer'], 'to': ', '.join(['"%s" <%s>' % (u.username, u.email) for u in users]), 'subject': subject, 'message': data['message'], 'url': request.build_absolute_uri('/'), - }) - message = template.render(context) + } + message = template.render(context, request) subject = u'Fwd: %s' % subject email_to = '"%s" <%s>' % (request.user.username, request.user.email) receipt = EmailMessage(subject, @@ -637,7 +637,7 @@ def contact(request, data): email_to = [settings.CONFIG['site']['email']['contact'], ] subject = data.get('subject', '').strip() template = loader.get_template('contact_email.txt') - context = RequestContext(request, { + context = { 'name': name, 'email': email, 'subject': subject, @@ -645,9 +645,9 @@ def contact(request, data): 'sitename': settings.SITENAME, 'footer': settings.CONFIG['site']['email']['footer'], 'url': request.build_absolute_uri('/'), - }) + } subject = ox.decode_html(subject) - message = ox.decode_html(template.render(context)) + message = ox.decode_html(template.render(context, request)) response = json_response(text='message sent') try: send_mail(u'%s Contact - %s' % (settings.SITENAME, subject), message, email_from, email_to) @@ -657,7 +657,7 @@ def contact(request, data): and 'receipt' in data \ and data['receipt']: template = loader.get_template('contact_receipt.txt') - context = RequestContext(request, { + context = { 'name': name, 'from': email, 'sitename': settings.SITENAME, @@ -666,8 +666,8 @@ def contact(request, data): 'subject': subject, 'message': data['message'].strip(), 'url': request.build_absolute_uri('/'), - }) - message = template.render(context) + } + message = template.render(context, request) try: send_mail('Fwd: %s' % subject, message, email_from, [email]) except: