summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-07-24 09:35:55 -0500
committerDan McGee <dan@archlinux.org>2012-07-24 19:57:20 -0500
commit76c37ce3acc7a4af0271c7535d4a33042f7749b5 (patch)
tree4156207a4631dd28d4803d6305dc51bb8388e6db
parentc0bf9e20660cfae7ea8994472555bba23398b598 (diff)
Replace deprecated direct_to_template() with render() shortcut
Now that Django actually provides a concise way to use a RequestContext object without instantiating it, we can use that rather than the old function-based generic view that worked well to do the same. Additionally, these function-based generic views will be gone in Django 1.5, so might as well make the move now. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--devel/views.py15
-rw-r--r--mirrors/views.py19
-rw-r--r--packages/views/__init__.py11
-rw-r--r--packages/views/display.py13
-rw-r--r--packages/views/flag.py12
-rw-r--r--packages/views/signoff.py5
-rw-r--r--public/views.py14
-rw-r--r--releng/views.py15
-rw-r--r--retro/views.py4
-rw-r--r--todolists/views.py13
-rw-r--r--visualize/views.py4
11 files changed, 57 insertions, 68 deletions
diff --git a/devel/views.py b/devel/views.py
index 143b12bf..f877bc84 100644
--- a/devel/views.py
+++ b/devel/views.py
@@ -17,11 +17,10 @@ from django.core.mail import send_mail
from django.db import transaction
from django.db.models import F, Count, Max
from django.http import Http404
-from django.shortcuts import get_object_or_404
+from django.shortcuts import get_object_or_404, render
from django.template import loader, Context
from django.template.defaultfilters import filesizeformat
from django.views.decorators.cache import never_cache
-from django.views.generic.simple import direct_to_template
from django.utils.encoding import force_unicode
from django.utils.http import http_date
from django.utils.timezone import now
@@ -88,7 +87,7 @@ def index(request):
'signoffs': signoffs
}
- return direct_to_template(request, 'devel/index.html', page_dict)
+ return render(request, 'devel/index.html', page_dict)
@login_required
def clock(request):
@@ -128,7 +127,7 @@ def clock(request):
'utc_now': current_time,
}
- response = direct_to_template(request, 'devel/clock.html', page_dict)
+ response = render(request, 'devel/clock.html', page_dict)
if not response.has_header('Expires'):
expire_time = current_time.replace(second=0, microsecond=0)
expire_time += timedelta(minutes=1)
@@ -178,7 +177,7 @@ def change_profile(request):
else:
form = ProfileForm(initial={'email': request.user.email})
profile_form = UserProfileForm(instance=request.user.get_profile())
- return direct_to_template(request, 'devel/profile.html',
+ return render(request, 'devel/profile.html',
{'form': form, 'profile_form': profile_form})
@login_required
@@ -301,7 +300,7 @@ def report(request, report_name, username=None):
'column_names': names,
'column_attrs': attrs,
}
- return direct_to_template(request, 'devel/packages.html', context)
+ return render(request, 'devel/packages.html', context)
class NewUserForm(forms.ModelForm):
@@ -399,7 +398,7 @@ def new_user_form(request):
'title': 'Create User',
'submit_text': 'Create User'
}
- return direct_to_template(request, 'general_form.html', context)
+ return render(request, 'general_form.html', context)
@user_passes_test(lambda u: u.is_superuser)
def admin_log(request, username=None):
@@ -410,6 +409,6 @@ def admin_log(request, username=None):
'title': "Admin Action Log",
'log_user': user,
}
- return direct_to_template(request, 'devel/admin_log.html', context)
+ return render(request, 'devel/admin_log.html', context)
# vim: set ts=4 sw=4 et:
diff --git a/mirrors/views.py b/mirrors/views.py
index 8f092be7..400c084d 100644
--- a/mirrors/views.py
+++ b/mirrors/views.py
@@ -8,9 +8,8 @@ from django.forms.widgets import CheckboxSelectMultiple
from django.core.serializers.json import DjangoJSONEncoder
from django.db.models import Q
from django.http import Http404, HttpResponse
-from django.shortcuts import get_object_or_404
+from django.shortcuts import get_object_or_404, render
from django.views.decorators.csrf import csrf_exempt
-from django.views.generic.simple import direct_to_template
from django_countries.countries import COUNTRIES
from .models import Mirror, MirrorUrl, MirrorProtocol, TIER_CHOICES
@@ -76,7 +75,7 @@ def generate_mirrorlist(request):
else:
form = MirrorlistForm()
- return direct_to_template(request, 'mirrors/mirrorlist_generate.html',
+ return render(request, 'mirrors/mirrorlist_generate.html',
{'mirrorlist_form': form})
@@ -142,10 +141,10 @@ def find_mirrors(request, countries=None, protocols=None, use_status=False,
urls = status_filter(urls)
template = 'mirrors/mirrorlist_status.txt'
- return direct_to_template(request, template, {
- 'mirror_urls': urls,
- },
- mimetype='text/plain')
+ context = {
+ 'mirror_urls': urls,
+ }
+ return render(request, template, context, content_type='text/plain')
def find_mirrors_simple(request, protocol):
@@ -161,7 +160,7 @@ def mirrors(request):
mirror_list = Mirror.objects.select_related().order_by('tier', 'country')
if not request.user.is_authenticated():
mirror_list = mirror_list.filter(public=True, active=True)
- return direct_to_template(request, 'mirrors/mirrors.html',
+ return render(request, 'mirrors/mirrors.html',
{'mirror_list': mirror_list})
@@ -180,7 +179,7 @@ def mirror_details(request, name):
all_urls = set(checked_urls).union(all_urls)
all_urls = sorted(all_urls, key=attrgetter('url'))
- return direct_to_template(request, 'mirrors/mirror_details.html',
+ return render(request, 'mirrors/mirror_details.html',
{'mirror': mirror, 'urls': all_urls})
@@ -217,7 +216,7 @@ def status(request, tier=None):
'error_logs': error_logs,
'tier': tier,
})
- return direct_to_template(request, 'mirrors/status.html', context)
+ return render(request, 'mirrors/status.html', context)
class MirrorStatusJSONEncoder(DjangoJSONEncoder):
diff --git a/packages/views/__init__.py b/packages/views/__init__.py
index fa67daa8..19ea9103 100644
--- a/packages/views/__init__.py
+++ b/packages/views/__init__.py
@@ -6,10 +6,9 @@ from django.contrib.auth.decorators import permission_required
from django.contrib.auth.models import User
from django.core.cache import cache
from django.http import HttpResponse
-from django.shortcuts import redirect
+from django.shortcuts import redirect, render
from django.views.decorators.cache import cache_control
from django.views.decorators.http import require_GET, require_POST
-from django.views.generic.simple import direct_to_template
from main.models import Package, Arch
from ..models import PackageRelation
@@ -32,9 +31,9 @@ def opensearch(request):
else:
domain = "http://%s" % request.META['HTTP_HOST']
- return direct_to_template(request, 'packages/opensearch.xml',
+ return render(request, 'packages/opensearch.xml',
{'domain': domain},
- mimetype='application/opensearchdescription+xml')
+ content_type='application/opensearchdescription+xml')
@require_GET
@@ -115,7 +114,7 @@ def arch_differences(request):
'differences': differences,
'multilib_differences': multilib_diffs
}
- return direct_to_template(request, 'packages/differences.html', context)
+ return render(request, 'packages/differences.html', context)
@permission_required('main.change_package')
def stale_relations(request):
@@ -132,7 +131,7 @@ def stale_relations(request):
'missing_pkgbase': missing_pkgbase,
'wrong_permissions': wrong_permissions,
}
- return direct_to_template(request, 'packages/stale_relations.html', context)
+ return render(request, 'packages/stale_relations.html', context)
@permission_required('packages.delete_packagerelation')
@require_POST
diff --git a/packages/views/display.py b/packages/views/display.py
index 31f18c79..585e0e4e 100644
--- a/packages/views/display.py
+++ b/packages/views/display.py
@@ -6,7 +6,6 @@ from urllib import urlencode
from django.http import HttpResponse, Http404
from django.shortcuts import get_object_or_404, redirect, render
from django.utils.timezone import now
-from django.views.generic.simple import direct_to_template
from main.models import Package, PackageFile, Arch, Repo
from mirrors.utils import get_mirror_url_for_download
@@ -33,8 +32,7 @@ def split_package_details(request, name, repo, arch):
'arch': arch,
'packages': pkgs,
}
- return direct_to_template(request, 'packages/packages_list.html',
- context)
+ return render(request, 'packages/packages_list.html', context)
CUTOFF = datetime.timedelta(days=60)
@@ -67,8 +65,7 @@ def details(request, name='', repo='', arch=''):
pkg = Package.objects.select_related(
'arch', 'repo', 'packager').get(pkgname=name,
repo__name__iexact=repo, arch__name=arch)
- return direct_to_template(request, 'packages/details.html',
- {'pkg': pkg, })
+ return render(request, 'packages/details.html', {'pkg': pkg})
except Package.DoesNotExist:
arch_obj = get_object_or_404(Arch, name=arch)
# for arch='any' packages, we can issue a redirect to them if we
@@ -111,7 +108,7 @@ def groups(request, arch=None):
'groups': grps,
'arch': arch,
}
- return direct_to_template(request, 'packages/groups.html', context)
+ return render(request, 'packages/groups.html', context)
def group_details(request, arch, name):
@@ -128,7 +125,7 @@ def group_details(request, arch, name):
'arch': arch,
'packages': pkgs,
}
- return direct_to_template(request, 'packages/packages_list.html', context)
+ return render(request, 'packages/packages_list.html', context)
def files(request, name, repo, arch):
@@ -153,7 +150,7 @@ def files(request, name, repo, arch):
'dir_count': dir_count,
}
template = 'packages/files.html'
- return direct_to_template(request, template, context)
+ return render(request, template, context)
def details_json(request, name, repo, arch):
diff --git a/packages/views/flag.py b/packages/views/flag.py
index f3db93b3..b9542a62 100644
--- a/packages/views/flag.py
+++ b/packages/views/flag.py
@@ -3,10 +3,9 @@ from django.conf import settings
from django.contrib.auth.decorators import permission_required
from django.core.mail import send_mail
from django.db import transaction
-from django.shortcuts import get_object_or_404, redirect
+from django.shortcuts import get_object_or_404, redirect, render
from django.template import loader, Context
from django.utils.timezone import now
-from django.views.generic.simple import direct_to_template
from django.views.decorators.cache import cache_page, never_cache
from ..models import FlagRequest
@@ -34,7 +33,7 @@ class FlagForm(forms.Form):
@cache_page(3600)
def flaghelp(request):
- return direct_to_template(request, 'packages/flaghelp.html')
+ return render(request, 'packages/flaghelp.html')
@never_cache
@@ -43,8 +42,7 @@ def flag(request, name, repo, arch):
pkgname=name, repo__name__iexact=repo, arch__name=arch)
if pkg.flag_date is not None:
# already flagged. do nothing.
- return direct_to_template(request, 'packages/flagged.html',
- {'pkg': pkg})
+ return render(request, 'packages/flagged.html', {'pkg': pkg})
# find all packages from (hopefully) the same PKGBUILD
pkgs = Package.objects.normal().filter(
pkgbase=pkg.pkgbase, flag_date__isnull=True,
@@ -129,7 +127,7 @@ def flag(request, name, repo, arch):
'packages': pkgs,
'form': form
}
- return direct_to_template(request, 'packages/flag.html', context)
+ return render(request, 'packages/flag.html', context)
def flag_confirmed(request, name, repo, arch):
pkg = get_object_or_404(Package,
@@ -142,7 +140,7 @@ def flag_confirmed(request, name, repo, arch):
context = {'package': pkg, 'packages': pkgs}
- return direct_to_template(request, 'packages/flag_confirmed.html', context)
+ return render(request, 'packages/flag_confirmed.html', context)
@permission_required('main.change_package')
def unflag(request, name, repo, arch):
diff --git a/packages/views/signoff.py b/packages/views/signoff.py
index 7aa39106..56eb060c 100644
--- a/packages/views/signoff.py
+++ b/packages/views/signoff.py
@@ -10,7 +10,6 @@ from django.http import HttpResponse, Http404
from django.shortcuts import get_list_or_404, redirect, render
from django.utils.timezone import now
from django.views.decorators.cache import never_cache
-from django.views.generic.simple import direct_to_template
from main.models import Package, Arch, Repo
from ..models import SignoffSpecification, Signoff
@@ -28,7 +27,7 @@ def signoffs(request):
'arches': Arch.objects.all(),
'repo_names': sorted(set(g.target_repo for g in signoff_groups)),
}
- return direct_to_template(request, 'packages/signoffs.html', context)
+ return render(request, 'packages/signoffs.html', context)
@permission_required('main.change_package')
@never_cache
@@ -144,7 +143,7 @@ def signoff_options(request, name, repo, arch):
'package': package,
'form': form,
}
- return direct_to_template(request, 'packages/signoff_options.html', context)
+ return render(request, 'packages/signoff_options.html', context)
class SignoffJSONEncoder(DjangoJSONEncoder):
'''Base JSONEncoder extended to handle all serialization of all classes
diff --git a/public/views.py b/public/views.py
index 3ea8f841..3f68545c 100644
--- a/public/views.py
+++ b/public/views.py
@@ -5,8 +5,8 @@ from django.conf import settings
from django.contrib.auth.models import User
from django.db.models import Count, Q
from django.http import Http404
+from django.shortcuts import render
from django.views.decorators.cache import cache_control
-from django.views.generic.simple import direct_to_template
from devel.models import MasterKey, PGPSignature
from main.models import Arch, Repo, Donor
@@ -21,7 +21,7 @@ def index(request):
'news_updates': News.objects.order_by('-postdate', '-id')[:15],
'pkg_updates': pkgs,
}
- return direct_to_template(request, 'public/index.html', context)
+ return render(request, 'public/index.html', context)
USER_LISTS = {
'devs': {
@@ -55,14 +55,14 @@ def userlist(request, user_type='devs'):
users = users.distinct()
context = USER_LISTS[user_type].copy()
context['users'] = users
- return direct_to_template(request, 'public/userlist.html', context)
+ return render(request, 'public/userlist.html', context)
@cache_control(max_age=300)
def donate(request):
context = {
'donors': Donor.objects.filter(visible=True).order_by('name'),
}
- return direct_to_template(request, 'public/donate.html', context)
+ return render(request, 'public/donate.html', context)
@cache_control(max_age=300)
def download(request):
@@ -76,7 +76,7 @@ def download(request):
'releng_pxeboot_url': settings.PXEBOOT_URL,
'mirror_urls': mirror_urls,
}
- return direct_to_template(request, 'public/download.html', context)
+ return render(request, 'public/download.html', context)
@cache_control(max_age=300)
def feeds(request):
@@ -84,7 +84,7 @@ def feeds(request):
'arches': Arch.objects.all(),
'repos': Repo.objects.all(),
}
- return direct_to_template(request, 'public/feeds.html', context)
+ return render(request, 'public/feeds.html', context)
@cache_control(max_age=300)
def keys(request):
@@ -113,6 +113,6 @@ def keys(request):
'active_users': users,
'signatures': signatures,
}
- return direct_to_template(request, 'public/keys.html', context)
+ return render(request, 'public/keys.html', context)
# vim: set ts=4 sw=4 et:
diff --git a/releng/views.py b/releng/views.py
index fc81d410..a1bc3b81 100644
--- a/releng/views.py
+++ b/releng/views.py
@@ -2,8 +2,7 @@ from django import forms
from django.conf import settings
from django.db.models import Count, Max
from django.http import Http404
-from django.shortcuts import get_object_or_404, redirect
-from django.views.generic.simple import direct_to_template
+from django.shortcuts import get_object_or_404, redirect, render
from .models import (Architecture, BootType, Bootloader, ClockChoice,
Filesystem, HardwareType, InstallType, Iso, IsoType, Module, Source,
@@ -73,7 +72,7 @@ def submit_test_result(request):
form = TestForm()
context = {'form': form}
- return direct_to_template(request, 'releng/add.html', context)
+ return render(request, 'releng/add.html', context)
def calculate_option_overview(field_name):
field = Test._meta.get_field(field_name)
@@ -145,7 +144,7 @@ def test_results_overview(request):
'options': all_options,
'iso_url': settings.ISO_LIST_URL,
}
- return direct_to_template(request, 'releng/results.html', context)
+ return render(request, 'releng/results.html', context)
def test_results_iso(request, iso_id):
iso = get_object_or_404(Iso, pk=iso_id)
@@ -154,7 +153,7 @@ def test_results_iso(request, iso_id):
'iso_name': iso.name,
'test_list': test_list
}
- return direct_to_template(request, 'releng/result_list.html', context)
+ return render(request, 'releng/result_list.html', context)
def test_results_for(request, option, value):
if option not in Test._meta.get_all_field_names():
@@ -170,10 +169,10 @@ def test_results_for(request, option, value):
'value_id': value,
'test_list': test_list
}
- return direct_to_template(request, 'releng/result_list.html', context)
+ return render(request, 'releng/result_list.html', context)
def submit_test_thanks(request):
- return direct_to_template(request, "releng/thanks.html", None)
+ return render(request, "releng/thanks.html", None)
def iso_overview(request):
isos = Iso.objects.all().order_by('-pk')
@@ -192,6 +191,6 @@ def iso_overview(request):
context = {
'isos': isos
}
- return direct_to_template(request, 'releng/iso_overview.html', context)
+ return render(request, 'releng/iso_overview.html', context)
# vim: set ts=4 sw=4 et:
diff --git a/retro/views.py b/retro/views.py
index 3bc59e9f..31226deb 100644
--- a/retro/views.py
+++ b/retro/views.py
@@ -1,6 +1,6 @@
from django.http import Http404
+from django.shortcuts import render
from django.views.decorators.cache import cache_page
-from django.views.generic.simple import direct_to_template
RETRO_YEAR_MAP = {
@@ -26,6 +26,6 @@ def retro_homepage(request, year):
context = {
'year': year,
}
- return direct_to_template(request, 'retro/%s' % template, context)
+ return render(request, 'retro/%s' % template, context)
# vim: set ts=4 sw=4 et:
diff --git a/todolists/views.py b/todolists/views.py
index 580ec00f..c7ba2560 100644
--- a/todolists/views.py
+++ b/todolists/views.py
@@ -3,12 +3,11 @@ import json
from django import forms
from django.http import HttpResponse
from django.core.mail import send_mail
-from django.shortcuts import get_list_or_404, get_object_or_404, redirect
+from django.shortcuts import get_list_or_404, get_object_or_404, redirect, render
from django.contrib.auth.decorators import login_required, permission_required
from django.db import transaction
from django.views.decorators.cache import never_cache
from django.views.generic import DeleteView
-from django.views.generic.simple import direct_to_template
from django.template import Context, loader
from main.models import Todolist, TodolistPkg, Package, Repo
@@ -54,7 +53,7 @@ def view(request, list_id):
# we don't hold onto the result, but the objects are the same here,
# so accessing maintainers in the template is now cheap
attach_maintainers(tp.pkg for tp in todolist.packages)
- return direct_to_template(request, 'todolists/view.html', {
+ return render(request, 'todolists/view.html', {
'list': todolist,
'svn_roots': svn_roots,
})
@@ -72,7 +71,7 @@ def list_pkgbases(request, list_id, svn_root):
@login_required
def todolist_list(request):
lists = get_annotated_todolists()
- return direct_to_template(request, 'todolists/list.html', {'lists': lists})
+ return render(request, 'todolists/list.html', {'lists': lists})
@permission_required('main.add_todolist')
@never_cache
@@ -92,7 +91,7 @@ def add(request):
'form': form,
'submit_text': 'Create List'
}
- return direct_to_template(request, 'general_form.html', page_dict)
+ return render(request, 'general_form.html', page_dict)
# TODO: this calls for transaction management and async emailing
@permission_required('main.change_todolist')
@@ -115,7 +114,7 @@ def edit(request, list_id):
'form': form,
'submit_text': 'Save List'
}
- return direct_to_template(request, 'general_form.html', page_dict)
+ return render(request, 'general_form.html', page_dict)
class DeleteTodolist(DeleteView):
model = Todolist
@@ -185,7 +184,7 @@ def public_list(request):
# total hackjob, but it makes this a lot less query-intensive.
all_pkgs = [tp for tl in todo_lists for tp in tl.packages]
attach_maintainers([tp.pkg for tp in all_pkgs])
- return direct_to_template(request, "todolists/public_list.html",
+ return render(request, "todolists/public_list.html",
{"todo_lists": todo_lists})
# vim: set ts=4 sw=4 et:
diff --git a/visualize/views.py b/visualize/views.py
index 95f8c314..44e60472 100644
--- a/visualize/views.py
+++ b/visualize/views.py
@@ -4,14 +4,14 @@ import json
from django.contrib.auth.models import User
from django.db.models import Count, Sum, Q
from django.http import HttpResponse
+from django.shortcuts import render
from django.views.decorators.cache import cache_page
-from django.views.generic.simple import direct_to_template
from main.models import Package, Arch, Repo
from devel.models import MasterKey, PGPSignature
def index(request):
- return direct_to_template(request, 'visualize/index.html', {})
+ return render(request, 'visualize/index.html')
def arch_repo_data():
qs = Package.objects.select_related().values(