Fixed #25519 -- Made the admin "View site" link point to sites running on a subpath.
Used request.META['SCRIPT_NAME'] as the site_url if it hasn't been customized from the default value of '/'.
This commit is contained in:
parent
3f300efede
commit
59e85f09c6
|
@ -306,11 +306,16 @@ class AdminSite(object):
|
|||
"""
|
||||
Returns a dictionary of variables to put in the template context for
|
||||
*every* page in the admin site.
|
||||
|
||||
For sites running on a subpath, use the SCRIPT_NAME value if site_url
|
||||
hasn't been customized.
|
||||
"""
|
||||
script_name = request.META['SCRIPT_NAME']
|
||||
site_url = script_name if self.site_url == '/' and script_name else self.site_url
|
||||
return {
|
||||
'site_title': self.site_title,
|
||||
'site_header': self.site_header,
|
||||
'site_url': self.site_url,
|
||||
'site_url': site_url,
|
||||
'has_permission': self.has_permission(request),
|
||||
'available_apps': self.get_app_list(request),
|
||||
}
|
||||
|
|
|
@ -2513,6 +2513,15 @@ Templates can override or extend base admin templates as described in
|
|||
The URL for the "View site" link at the top of each admin page. By default,
|
||||
``site_url`` is ``/``. Set it to ``None`` to remove the link.
|
||||
|
||||
For sites running on a subpath, the :meth:`each_context` method checks if
|
||||
the current request has ``request.META['SCRIPT_NAME']`` set and uses that
|
||||
value if ``site_url`` isn't set to something other than ``/``.
|
||||
|
||||
.. versionchanged:: 1.10
|
||||
|
||||
The ``SCRIPT_NAME`` support described in the previous paragraph was
|
||||
added.
|
||||
|
||||
.. attribute:: AdminSite.index_title
|
||||
|
||||
The text to put at the top of the admin index page (a string). By default,
|
||||
|
|
|
@ -32,7 +32,9 @@ Minor features
|
|||
:mod:`django.contrib.admin`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
* ...
|
||||
* For sites running on a subpath, the default :attr:`URL for the "View site"
|
||||
link <django.contrib.admin.AdminSite.site_url>` at the top of each admin page
|
||||
will now point to ``request.META['SCRIPT_NAME']`` if set, instead of ``/``.
|
||||
|
||||
:mod:`django.contrib.admindocs`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -51,6 +51,11 @@ class SiteEachContextTest(TestCase):
|
|||
self.assertEqual(ctx['site_url'], '/')
|
||||
self.assertEqual(ctx['has_permission'], True)
|
||||
|
||||
def test_each_context_site_url_with_script_name(self):
|
||||
request = RequestFactory().get(reverse('test_adminsite:index'), SCRIPT_NAME='/my-script-name/')
|
||||
request.user = self.u1
|
||||
self.assertEqual(site.each_context(request)['site_url'], '/my-script-name/')
|
||||
|
||||
def test_available_apps(self):
|
||||
ctx = self.ctx
|
||||
apps = ctx['available_apps']
|
||||
|
|
Loading…
Reference in New Issue