1
0
mirror of https://github.com/django/django.git synced 2024-12-27 03:25:58 +00:00

Changed django.views.core.flatfiles to use get_object_or_404

git-svn-id: http://code.djangoproject.com/svn/django/trunk@676 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-09-23 21:59:17 +00:00
parent 3b49ecea63
commit a39e6c91b1

View File

@ -1,6 +1,5 @@
from django.core import template_loader from django.core import template_loader
from django.core.exceptions import Http404 from django.core.extensions import get_object_or_404, DjangoContext
from django.core.extensions import DjangoContext as Context
from django.models.core import flatfiles from django.models.core import flatfiles
from django.utils.httpwrappers import HttpResponse from django.utils.httpwrappers import HttpResponse
from django.conf.settings import SITE_ID from django.conf.settings import SITE_ID
@ -18,17 +17,14 @@ def flat_file(request, url):
""" """
if not url.startswith('/'): if not url.startswith('/'):
url = "/" + url url = "/" + url
try: f = get_object_or_404(flatfiles, url__exact=url, sites__id__exact=SITE_ID)
f = flatfiles.get_object(url__exact=url, sites__id__exact=SITE_ID)
except flatfiles.FlatFileDoesNotExist:
raise Http404
# If registration is required for accessing this page, and the user isn't # If registration is required for accessing this page, and the user isn't
# logged in, redirect to the login page. # logged in, redirect to the login page.
if request.user.is_anonymous() and f.registration_required: if request.user.is_anonymous() and f.registration_required:
from django.views.auth.login import redirect_to_login from django.views.auth.login import redirect_to_login
return redirect_to_login(request.path) return redirect_to_login(request.path)
t = template_loader.select_template([f.template_name, 'flatfiles/default']) t = template_loader.select_template([f.template_name, 'flatfiles/default'])
c = Context(request, { c = DjangoContext(request, {
'flatfile': f, 'flatfile': f,
}) })
return HttpResponse(t.render(c)) return HttpResponse(t.render(c))