Ticket #9881: patch-9881.diff

File patch-9881.diff, 3.7 KB (added by nessita, 6 years ago)
  • django/contrib/auth/views.py

     
    11from django.conf import settings
    2 from django.contrib.auth import REDIRECT_FIELD_NAME
     2from django.contrib.auth import REDIRECT_FIELD_NAME, SITE_KEYWORD
    33from django.contrib.auth.decorators import login_required
    44from django.contrib.auth.forms import AuthenticationForm
    55from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm, PasswordChangeForm
     
    3838    return render_to_response(template_name, {
    3939        'form': form,
    4040        redirect_field_name: redirect_to,
    41         'site_name': current_site.name,
     41        'site_name': current_site.name, # do not remove for backward compatibility
     42        SITE_KEYWORD: current_site,
    4243    }, context_instance=RequestContext(request))
    4344login = never_cache(login)
    4445
  • django/contrib/auth/__init__.py

     
    55SESSION_KEY = '_auth_user_id'
    66BACKEND_SESSION_KEY = '_auth_user_backend'
    77REDIRECT_FIELD_NAME = 'next'
     8SITE_KEYWORD = 'site'
    89
    910def load_backend(path):
    1011    i = path.rfind('.')
  • django/contrib/auth/tests/views.py

     
    33import re
    44
    55from django.conf import settings
     6from django.contrib.sites.models import Site, RequestSite
    67from django.contrib.auth.models import User
     8from django.contrib.auth.views import login as login_view, SITE_KEYWORD
    79from django.test import TestCase
    810from django.core import mail
     11from django.core.urlresolvers import reverse
    912
    1013class PasswordResetTest(TestCase):
    1114    fixtures = ['authtestdata.json']
     
    162165        self.fail_login()
    163166        self.login(password='password1')
    164167
     168class LoginTest(TestCase):
     169    fixtures = ['authtestdata.json']
     170    urls = 'django.contrib.auth.urls'
     171
     172    def setUp(self):
     173        self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
     174        settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'),)
     175
     176    def tearDown(self):
     177        settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
     178
     179    def test_current_site_in_context_after_login(self):
     180        response = self.client.get(reverse(login_view))
     181        self.assertEquals(response.status_code, 200)
     182        self.assertTrue(SITE_KEYWORD in response.context)
     183
     184        if Site._meta.installed:
     185            current_site = Site.objects.get_current()
     186        else:
     187            current_site = RequestSite(request)
     188
     189        self.assertEquals(current_site, response.context[SITE_KEYWORD])
  • django/contrib/auth/tests/__init__.py

     
    11from django.contrib.auth.tests.basic import BASIC_TESTS
    22from django.contrib.auth.tests.views \
    3         import PasswordResetTest, ChangePasswordTest
     3        import PasswordResetTest, ChangePasswordTest, LoginTest
    44from django.contrib.auth.tests.forms import FORM_TESTS
    55from django.contrib.auth.tests.remote_user \
    66        import RemoteUserTest, RemoteUserNoCreateTest, RemoteUserCustomTest
     
    1414    'FORM_TESTS': FORM_TESTS,
    1515    'TOKEN_GENERATOR_TESTS': TOKEN_GENERATOR_TESTS,
    1616    'CHANGEPASSWORD_TESTS': ChangePasswordTest,
     17    'LOGIN_TESTS': LoginTest,
    1718}
Back to Top