summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-09-03 20:44:27 +0200
committerDan McGee <dan@archlinux.org>2010-09-03 20:45:13 +0200
commit872af225a98b9c328988e1cdbdea2ca73b8d185c (patch)
tree2d0e486f2321f5113f3e0b9e6c7625c2d76d64de
parent7c7f57f6ac43af5350f04c6eaeb927063ad4daee (diff)
downloadarchweb-872af225a98b9c328988e1cdbdea2ca73b8d185c.tar.gz
archweb-872af225a98b9c328988e1cdbdea2ca73b8d185c.tar.xz
Use direct_to_template in all remaining possible places
Rather than the need to include RequestContext() calls directly, we can just use direct_to_template to do all the work for us. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--devel/views.py16
-rw-r--r--mirrors/views.py13
-rw-r--r--news/views.py7
-rw-r--r--packages/views.py53
-rw-r--r--todolists/views.py23
5 files changed, 47 insertions, 65 deletions
diff --git a/devel/views.py b/devel/views.py
index baa5fd6..1f43b87 100644
--- a/devel/views.py
+++ b/devel/views.py
@@ -3,10 +3,9 @@ from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
-from django.shortcuts import render_to_response
-from django.template import RequestContext
from django.core.mail import send_mail
from django.views.decorators.cache import never_cache
+from django.views.generic.simple import direct_to_template
from main.models import Package, Todolist, TodolistPkg
from main.models import Arch, Repo
@@ -41,8 +40,7 @@ def index(request):
'todopkgs' : todopkgs,
}
- return render_to_response('devel/index.html',
- RequestContext(request, page_dict))
+ return direct_to_template(request, 'devel/index.html', page_dict)
@login_required
def change_notify(request):
@@ -78,14 +76,13 @@ def change_profile(request):
return HttpResponseRedirect('/devel/')
else:
form = ProfileForm(initial={'email': request.user.email})
- return render_to_response('devel/profile.html',
- RequestContext(request, {'form': form}))
+ return direct_to_template(request, 'devel/profile.html', {'form': form})
@login_required
def mirrorlist(request):
mirrors = Mirror.objects.select_related().order_by('tier', 'country')
- return render_to_response('devel/mirrorlist.html',
- RequestContext(request, {'mirror_list': mirrors}))
+ return direct_to_template(request, 'devel/mirrorlist.html',
+ {'mirror_list': mirrors})
class NewUserForm(forms.ModelForm):
class Meta:
@@ -140,7 +137,6 @@ def new_user_form(request):
'title': 'Create User',
'submit_text': 'Create User'
}
- return render_to_response('general_form.html',
- RequestContext(request, context))
+ return direct_to_template(request, 'general_form.html', context)
# vim: set ts=4 sw=4 et:
diff --git a/mirrors/views.py b/mirrors/views.py
index 378a0b4..b9a02d2 100644
--- a/mirrors/views.py
+++ b/mirrors/views.py
@@ -1,7 +1,7 @@
from django import forms
-from django.shortcuts import render_to_response
-from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt
+from django.views.generic.simple import direct_to_template
+
from main.models import Mirror, MirrorUrl, MirrorProtocol
from main.utils import make_choice
@@ -31,8 +31,7 @@ def generate(request):
else:
form = MirrorlistForm()
- return render_to_response('mirrors/index.html', {'mirrorlist_form': form},
- context_instance=RequestContext(request))
+ return direct_to_template(request, 'mirrors/index.html', {'mirrorlist_form': form})
def find_mirrors(request, countries=None, protocols=None):
print 'protocols', protocols
@@ -46,11 +45,9 @@ def find_mirrors(request, countries=None, protocols=None):
if countries and 'all' not in countries:
qset = qset.filter(mirror__country__in=countries)
qset = qset.order_by('mirror__country', 'mirror__name', 'url')
- res = render_to_response('mirrors/mirrorlist.txt', {
+ return direct_to_template(request, 'mirrors/mirrorlist.txt', {
'mirror_urls': qset,
},
- mimetype='text/plain',
- context_instance=RequestContext(request))
- return res
+ mimetype='text/plain')
# vim: set ts=4 sw=4 et:
diff --git a/news/views.py b/news/views.py
index 887fe1d..3977393 100644
--- a/news/views.py
+++ b/news/views.py
@@ -1,10 +1,10 @@
from django import forms
from django.contrib.auth.decorators import permission_required
from django.http import HttpResponse
-from django.shortcuts import render_to_response, redirect
-from django.template import RequestContext
+from django.shortcuts import redirect
from django.views.decorators.cache import never_cache
from django.views.generic import list_detail, create_update
+from django.views.generic.simple import direct_to_template
import markdown
@@ -39,8 +39,7 @@ def add(request):
return redirect(newsitem.get_absolute_url())
else:
form = NewsForm()
- return render_to_response('news/add.html',
- RequestContext(request, { 'form': form }))
+ return direct_to_template(request, 'news/add.html', { 'form': form })
@permission_required('main.delete_news')
@never_cache
diff --git a/packages/views.py b/packages/views.py
index 2fe515c..37f5a20 100644
--- a/packages/views.py
+++ b/packages/views.py
@@ -1,16 +1,16 @@
from django import forms
from django.contrib import messages
from django.core.mail import send_mail
-from django.shortcuts import render_to_response
from django.template import loader, Context, RequestContext
-from django.http import HttpResponse, HttpResponseRedirect, Http404
-from django.shortcuts import get_object_or_404
+from django.http import HttpResponse, Http404
+from django.shortcuts import get_object_or_404, redirect
from django.contrib.auth.models import User
from django.contrib.auth.decorators import permission_required
from django.contrib.admin.widgets import AdminDateWidget
from django.views.decorators.cache import never_cache
from django.views.decorators.vary import vary_on_headers
from django.views.generic import list_detail
+from django.views.generic.simple import direct_to_template
from django.db.models import Q
from datetime import datetime
@@ -28,13 +28,10 @@ def opensearch(request):
domain = "https://%s" % request.META['HTTP_HOST']
else:
domain = "http://%s" % request.META['HTTP_HOST']
- response = HttpResponse(mimetype='application/opensearchdescription+xml')
- template = loader.get_template('packages/opensearch.xml')
- ctx = Context({
- 'domain': domain,
- })
- response.write(template.render(ctx))
- return response
+
+ return direct_to_template(request, 'packages/opensearch.xml',
+ {'domain': domain},
+ mimetype='application/opensearchdescription+xml')
@permission_required('main.change_package')
def update(request):
@@ -73,22 +70,20 @@ def update(request):
))
else:
messages.error(request, "Are you trying to adopt or disown?")
- return HttpResponseRedirect('/packages/')
+ return redirect('/packages/')
def details(request, name='', repo='', arch=''):
if all([name, repo, arch]):
pkg = get_object_or_404(Package,
pkgname=name, repo__name__iexact=repo, arch__name=arch)
- return render_to_response('packages/details.html', RequestContext(
- request, {'pkg': pkg, }))
+ return direct_to_template(request, 'packages/details.html', {'pkg': pkg, })
else:
- return HttpResponseRedirect("/packages/?arch=%s&repo=%s&q=%s" % (
+ return redirect("/packages/?arch=%s&repo=%s&q=%s" % (
arch.lower(), repo.title(), name))
def groups(request):
grps = get_group_info()
- return render_to_response('packages/groups.html',
- RequestContext(request, {'groups': grps}))
+ return direct_to_template(request, 'packages/groups.html', {'groups': grps})
def group_details(request, arch, name):
arch = get_object_or_404(Arch, name=arch)
@@ -102,8 +97,7 @@ def group_details(request, arch, name):
'arch': arch,
'packages': pkgs,
}
- return render_to_response('packages/group_details.html',
- RequestContext(request, context))
+ return direct_to_template(request, 'packages/group_details.html', context)
def getmaintainer(request, name, repo, arch):
"Returns the maintainers as plaintext."
@@ -200,7 +194,7 @@ def search(request, page=None):
'current_query': current_query
}
if packages.count() == 1:
- return HttpResponseRedirect(packages[0].get_absolute_url())
+ return redirect(packages[0])
allowed_sort = ["arch", "repo", "pkgname", "last_update"]
allowed_sort += ["-" + s for s in allowed_sort]
@@ -228,8 +222,8 @@ def files(request, name='', repo='', arch=''):
template = 'packages/files.html'
if request.is_ajax():
template = 'packages/files-list.html'
- return render_to_response(template, RequestContext(request,
- {'pkg':pkg, 'files':fileslist}))
+ return direct_to_template(request, template,
+ {'pkg':pkg, 'files':fileslist})
@permission_required('main.change_package')
def unflag(request, name='', repo='', arch=''):
@@ -237,7 +231,7 @@ def unflag(request, name='', repo='', arch=''):
pkgname=name, repo__name__iexact=repo, arch__name=arch)
pkg.flag_date = None
pkg.save()
- return HttpResponseRedirect(pkg.get_absolute_url())
+ return redirect(pkg)
@permission_required('main.change_package')
@never_cache
@@ -257,8 +251,8 @@ def signoffs(request):
else:
repo = "Unknown"
package_list.append((package, repo))
- return render_to_response('packages/signoffs.html',
- RequestContext(request, {'packages': package_list}))
+ return direct_to_template(request, 'packages/signoffs.html',
+ {'packages': package_list})
@permission_required('main.change_package')
@never_cache
@@ -285,7 +279,7 @@ def signoff_package(request, arch, pkgname):
return signoffs(request)
def flaghelp(request):
- return render_to_response('packages/flaghelp.html')
+ return direct_to_template(request, 'packages/flaghelp.html')
class FlagForm(forms.Form):
email = forms.EmailField(label='* E-mail Address')
@@ -303,7 +297,7 @@ def flag(request, name='', repo='', arch=''):
context = {'pkg': pkg}
if pkg.flag_date is not None:
# already flagged. do nothing.
- return render_to_response('packages/flagged.html', context)
+ return direct_to_template(request, 'packages/flagged.html', context)
if request.POST:
form = FlagForm(request.POST)
@@ -347,7 +341,7 @@ def flag(request, name='', repo='', arch=''):
context['form'] = form
- return render_to_response('packages/flag.html', RequestContext(request, context))
+ return direct_to_template(request, 'packages/flag.html', context)
def download(request, name='', repo='', arch=''):
pkg = get_object_or_404(Package,
@@ -362,7 +356,7 @@ def download(request, name='', repo='', arch=''):
'file': pkg.filename,
}
url = string.Template('${host}${repo}/os/${arch}/${file}').substitute(details)
- return HttpResponseRedirect(url)
+ return redirect(url)
def arch_differences(request):
# TODO: we have some hardcoded magic here with respect to the arches.
@@ -374,7 +368,6 @@ def arch_differences(request):
'arch_b': arch_b,
'differences': differences,
}
- return render_to_response('packages/differences.html',
- RequestContext(request, context))
+ return direct_to_template(request, 'packages/differences.html', context)
# vim: set ts=4 sw=4 et:
diff --git a/todolists/views.py b/todolists/views.py
index 6f1c6ed..e366333 100644
--- a/todolists/views.py
+++ b/todolists/views.py
@@ -1,12 +1,12 @@
from django import forms
-from django.http import HttpResponse, HttpResponseRedirect
-from django.template import RequestContext
+from django.http import HttpResponse
from django.core.mail import send_mail
-from django.shortcuts import get_object_or_404, render_to_response, redirect
+from django.shortcuts import get_object_or_404, redirect
from django.contrib.auth.decorators import login_required, permission_required
from django.views.decorators.cache import never_cache
from django.views.generic.create_update import delete_object
+from django.views.generic.simple import direct_to_template
from django.template import Context, loader
from django.utils import simplejson
@@ -48,8 +48,7 @@ def flag(request, listid, pkgid):
@never_cache
def view(request, listid):
list = get_object_or_404(Todolist, id=listid)
- return render_to_response('todolists/view.html',
- RequestContext(request, {'list':list}))
+ return direct_to_template(request, 'todolists/view.html', {'list': list})
@login_required
@never_cache
@@ -58,8 +57,7 @@ def list(request):
for l in lists:
l.complete = TodolistPkg.objects.filter(
list=l.id,complete=False).count() == 0
- return render_to_response('todolists/list.html',
- RequestContext(request, {'lists':lists}))
+ return direct_to_template(request, 'todolists/list.html', {'lists': lists})
@permission_required('main.add_todolist')
@never_cache
@@ -76,7 +74,7 @@ def add(request):
tpkg = TodolistPkg.objects.create(list = todo, pkg = pkg)
send_todolist_email(tpkg)
- return HttpResponseRedirect('/todo/')
+ return redirect('/todo/')
else:
form = TodoListForm()
@@ -85,8 +83,7 @@ def add(request):
'form': form,
'submit_text': 'Create List'
}
- return render_to_response('general_form.html',
- RequestContext(request, page_dict))
+ return direct_to_template(request, 'general_form.html', page_dict)
@permission_required('main.change_todolist')
@never_cache
@@ -125,7 +122,7 @@ def edit(request, list_id):
'form': form,
'submit_text': 'Save List'
}
- return render_to_response('general_form.html', RequestContext(request, page_dict))
+ return direct_to_template(request, 'general_form.html', page_dict)
@permission_required('main.delete_todolist')
@never_cache
@@ -156,8 +153,8 @@ def send_todolist_email(todo):
def public_list(request):
todo_lists = Todolist.objects.incomplete()
- return render_to_response("todolists/public_list.html",
- RequestContext(request, {"todo_lists": todo_lists}))
+ return direct_to_template(request, "todolists/public_list.html",
+ {"todo_lists": todo_lists})
# vim: set ts=4 sw=4 et: