Fixed #22939 -- Delayed admin_static backend detection

Thanks generalov for the report.
This commit is contained in:
Claude Paroz 2014-07-07 09:54:58 +02:00 committed by Aymeric Augustin
parent a764a9ccff
commit 22b2fb0ba1
2 changed files with 24 additions and 5 deletions

View File

@ -3,9 +3,14 @@ from django.template import Library
register = Library() register = Library()
if apps.is_installed('django.contrib.staticfiles'): _static = None
from django.contrib.staticfiles.templatetags.staticfiles import static
else:
from django.templatetags.static import static
static = register.simple_tag(static) @register.simple_tag
def static(path):
global _static
if _static is None:
if apps.is_installed('django.contrib.staticfiles'):
from django.contrib.staticfiles.templatetags.staticfiles import static as _static
else:
from django.templatetags.static import static as _static
return _static(path)

View File

@ -18,6 +18,7 @@ from django.contrib.auth import get_permission_codename
from django.contrib.admin import ModelAdmin from django.contrib.admin import ModelAdmin
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.contrib.admin.models import LogEntry, DELETION from django.contrib.admin.models import LogEntry, DELETION
from django.contrib.admin.templatetags.admin_static import static
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
from django.contrib.admin.tests import AdminSeleniumWebDriverTestCase from django.contrib.admin.tests import AdminSeleniumWebDriverTestCase
from django.contrib.admin.utils import quote from django.contrib.admin.utils import quote
@ -26,6 +27,7 @@ from django.contrib.admin.views.main import IS_POPUP_VAR
from django.contrib.auth import REDIRECT_FIELD_NAME from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.models import Group, User, Permission from django.contrib.auth.models import Group, User, Permission
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.contrib.staticfiles.storage import staticfiles_storage
from django.forms.utils import ErrorList from django.forms.utils import ErrorList
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.test import TestCase, skipUnlessDBFeature from django.test import TestCase, skipUnlessDBFeature
@ -101,6 +103,18 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
'/test_admin/%s/admin_views/article/add/' % self.urlbit, '/test_admin/%s/admin_views/article/add/' % self.urlbit,
status_code=301) status_code=301)
def test_admin_static_template_tag(self):
"""
Test that admin_static.static is pointing to the collectstatic version
(as django.contrib.collectstatic is in installed apps).
"""
old_url = staticfiles_storage.base_url
staticfiles_storage.base_url = '/test/'
try:
self.assertEqual(static('path'), '/test/path')
finally:
staticfiles_storage.base_url = old_url
def test_basic_add_GET(self): def test_basic_add_GET(self):
""" """
A smoke test to ensure GET on the add_view works. A smoke test to ensure GET on the add_view works.