Converted django.views.auth.login to use load_and_render

git-svn-id: http://code.djangoproject.com/svn/django/trunk@659 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-09-22 05:18:23 +00:00
parent 48f0820337
commit aec3e32c7b
1 changed files with 5 additions and 11 deletions

View File

@ -1,6 +1,6 @@
from django.parts.auth.formfields import AuthenticationForm from django.parts.auth.formfields import AuthenticationForm
from django.core import formfields, template_loader from django.core import formfields, template_loader
from django.core.extensions import DjangoContext as Context from django.core.extensions import DjangoContext, load_and_render
from django.models.auth import users from django.models.auth import users
from django.models.core import sites from django.models.core import sites
from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
@ -21,27 +21,21 @@ def login(request):
return HttpResponseRedirect(redirect_to) return HttpResponseRedirect(redirect_to)
else: else:
errors = {} errors = {}
response = HttpResponse()
request.session.set_test_cookie() request.session.set_test_cookie()
t = template_loader.get_template('registration/login') return load_and_render('registration/login', {
c = Context(request, {
'form': formfields.FormWrapper(manipulator, request.POST, errors), 'form': formfields.FormWrapper(manipulator, request.POST, errors),
REDIRECT_FIELD_NAME: redirect_to, REDIRECT_FIELD_NAME: redirect_to,
'site_name': sites.get_current().name, 'site_name': sites.get_current().name,
}) }, context_instance=DjangoContext(request))
response.write(t.render(c))
return response
def logout(request, next_page=None): def logout(request, next_page=None):
"Logs out the user and displays 'You are logged out' message." "Logs out the user and displays 'You are logged out' message."
try: try:
del request.session[users.SESSION_KEY] del request.session[users.SESSION_KEY]
except KeyError: except KeyError:
t = template_loader.get_template('registration/logged_out') return load_and_render('registration/logged_out', context_instance=DjangoContext(request))
c = Context(request)
return HttpResponse(t.render(c))
else: else:
# Do a redirect to this page until the session has been cleared. # Redirect to this page until the session has been cleared.
return HttpResponseRedirect(next_page or request.path) return HttpResponseRedirect(next_page or request.path)
def logout_then_login(request): def logout_then_login(request):