Ticket #159: ticket159.diff

File ticket159.diff, 2.5 KB (added by Ash Christopher, 13 years ago)

Needs review, but couldn't think of a nicer way without major changes to the admin views.

  • django/contrib/admin/sites.py

    diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
    old mode 100644
    new mode 100755
    index 3a5c12b..03deab2
    a b from django.utils.text import capfirst  
    1414from django.utils.translation import ugettext as _
    1515from django.views.decorators.cache import never_cache
    1616from django.conf import settings
     17from django.http import HttpResponseRedirect
    1718
    1819LOGIN_FORM_KEY = 'this_is_the_login_form'
    1920
    class AdminSite(object):  
    188189        """
    189190        def inner(request, *args, **kwargs):
    190191            if not self.has_permission(request):
    191                 return self.login(request)
     192                extra_context = {}
     193                if request.path.endswith(reverse('admin:logout')):
     194                    extra_context[REDIRECT_FIELD_NAME] = reverse('admin:index')
     195                return self.login(request, extra_context)
    192196            return view(request, *args, **kwargs)
    193197        if not cacheable:
    194198            inner = never_cache(inner)
  • tests/regressiontests/admin_views/tests.py

    diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
    old mode 100644
    new mode 100755
    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    old mode 100644
    new mode 100755
    index b6e7b9e..95d935d
    a b class AdminCustomSaveRelatedTests(TestCase):  
    32553255
    32563256        self.assertEqual('Josh Stone', Parent.objects.latest('id').name)
    32573257        self.assertEqual([u'Catherine Stone', u'Paul Stone'], children_names)
     3258
     3259
     3260class AdminViewLogoutTest(TestCase):
     3261    urls = "regressiontests.admin_views.urls"
     3262    fixtures = ['admin-views-users.xml', ]
     3263
     3264    def setUp(self):
     3265        self.client.login(username='super', password='secret')
     3266
     3267    def tearDown(self):
     3268        self.client.logout()
     3269
     3270    def test_client_logout_url_can_be_used_to_login(self):
     3271        response = self.client.get('/test_admin/admin/logout/')
     3272        self.assertEqual(response.status_code, 200)
     3273        self.assertEqual(response.template_name, 'registration/logged_out.html')
     3274        self.assertEqual(response.request['PATH_INFO'], '/test_admin/admin/logout/')
     3275
     3276        # we are now logged out - issue a GET request to `/test_admin/admin/logout/`
     3277        response = self.client.get('/test_admin/admin/logout/')
     3278        self.assertTrue(
     3279            '<input type="hidden" name="next" value="/test_admin/admin/" />' in response.content)
Back to Top