summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2018-01-21 13:38:52 -0800
committerTim Graham <timograham@gmail.com>2018-01-23 10:30:10 -0500
commit7d607127e39792aa45b6abc2619b99fc55bcc672 (patch)
treebec3a8e16ac489b669d63fb5025b0f05896f683c
parentf0f383b6350c7b2f64bb2a6491a395abdd3313d6 (diff)
Refs #21221 -- Deprecated staticfiles and admin_static template tag libraries.
-rw-r--r--django/contrib/admin/templatetags/admin_static.py9
-rw-r--r--django/contrib/staticfiles/templatetags/staticfiles.py17
-rw-r--r--docs/internals/deprecation.txt5
-rw-r--r--docs/releases/2.1.txt6
-rw-r--r--tests/admin_views/test_static_deprecation.py30
-rw-r--r--tests/admin_views/tests.py14
-rw-r--r--tests/staticfiles_tests/cases.py4
-rw-r--r--tests/staticfiles_tests/test_forms.py2
-rw-r--r--tests/staticfiles_tests/test_templatetag_deprecation.py45
9 files changed, 109 insertions, 23 deletions
diff --git a/django/contrib/admin/templatetags/admin_static.py b/django/contrib/admin/templatetags/admin_static.py
index cfd55c737b..6b1738dd87 100644
--- a/django/contrib/admin/templatetags/admin_static.py
+++ b/django/contrib/admin/templatetags/admin_static.py
@@ -1,11 +1,16 @@
+import warnings
+
from django.template import Library
from django.templatetags.static import static as _static
+from django.utils.deprecation import RemovedInDjango30Warning
register = Library()
@register.simple_tag
def static(path):
- # Backwards compatibility alias for django.templatetags.static.static().
- # Deprecation should start in Django 2.0.
+ warnings.warn(
+ '{% load admin_static %} is deprecated in favor of {% load static %}.',
+ RemovedInDjango30Warning,
+ )
return _static(path)
diff --git a/django/contrib/staticfiles/templatetags/staticfiles.py b/django/contrib/staticfiles/templatetags/staticfiles.py
index eeb7452dbf..9fa3926412 100644
--- a/django/contrib/staticfiles/templatetags/staticfiles.py
+++ b/django/contrib/staticfiles/templatetags/staticfiles.py
@@ -1,19 +1,28 @@
+import warnings
+
from django import template
from django.templatetags.static import (
do_static as _do_static, static as _static,
)
+from django.utils.deprecation import RemovedInDjango30Warning
register = template.Library()
def static(path):
- # Backwards compatibility alias for django.templatetags.static.static().
- # Deprecation should start in Django 2.0.
+ warnings.warn(
+ 'django.contrib.staticfiles.templatetags.static() is deprecated in '
+ 'favor of django.templatetags.static.static().',
+ RemovedInDjango30Warning,
+ stacklevel=2,
+ )
return _static(path)
@register.tag('static')
def do_static(parser, token):
- # Backwards compatibility alias for django.templatetags.static.do_static().
- # Deprecation should start in Django 2.0.
+ warnings.warn(
+ '{% load staticfiles %} is deprecated in favor of {% load static %}.',
+ RemovedInDjango30Warning,
+ )
return _do_static(parser, token)
diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt
index f601b035ca..df817041df 100644
--- a/docs/internals/deprecation.txt
+++ b/docs/internals/deprecation.txt
@@ -33,6 +33,11 @@ details on these changes.
* ``django.utils.http.cookie_date()`` will be removed.
+* The ``staticfiles`` and ``admin_static`` template tag libraries will be
+ removed.
+
+* ``django.contrib.staticfiles.templatetags.static()`` will be removed.
+
See the :ref:`Django 2.1 release notes <deprecated-features-2.1>` for more
details on these changes.
diff --git a/docs/releases/2.1.txt b/docs/releases/2.1.txt
index 3465f41ce5..d7de90903c 100644
--- a/docs/releases/2.1.txt
+++ b/docs/releases/2.1.txt
@@ -274,6 +274,12 @@ Miscellaneous
:func:`~django.utils.http.http_date`, which follows the format of the latest
RFC.
+* ``{% load staticfiles %}`` and ``{% load admin_static %}`` are deprecated
+ in favor of ``{% load static %}``, which works the same.
+
+* ``django.contrib.staticfiles.templatetags.static()`` is deprecated in favor
+ of ``django.templatetags.static.static()``.
+
.. _removed-features-2.1:
Features removed in 2.1
diff --git a/tests/admin_views/test_static_deprecation.py b/tests/admin_views/test_static_deprecation.py
new file mode 100644
index 0000000000..fb64df6f5f
--- /dev/null
+++ b/tests/admin_views/test_static_deprecation.py
@@ -0,0 +1,30 @@
+import warnings
+
+from django.contrib.admin.templatetags.admin_static import static
+from django.contrib.staticfiles.storage import staticfiles_storage
+from django.test import SimpleTestCase
+from django.utils.deprecation import RemovedInDjango30Warning
+
+
+class AdminStaticDeprecationTests(SimpleTestCase):
+ def test(self):
+ """
+ admin_static.static points to the collectstatic version
+ (as django.contrib.collectstatic is in INSTALLED_APPS).
+ """
+ msg = (
+ '{% load admin_static %} is deprecated in favor of '
+ '{% load static %}.'
+ )
+ old_url = staticfiles_storage.base_url
+ staticfiles_storage.base_url = '/test/'
+ try:
+ with warnings.catch_warnings(record=True) as recorded:
+ warnings.simplefilter('always')
+ url = static('path')
+ self.assertEqual(url, '/test/path')
+ self.assertEqual(len(recorded), 1)
+ self.assertIs(recorded[0].category, RemovedInDjango30Warning)
+ self.assertEqual(str(recorded[0].message), msg)
+ finally:
+ staticfiles_storage.base_url = old_url
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index a9746d9add..68094e0053 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -10,7 +10,6 @@ from django.contrib.admin import AdminSite, ModelAdmin
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.contrib.admin.models import ADDITION, DELETION, LogEntry
from django.contrib.admin.options import TO_FIELD_VAR
-from django.contrib.admin.templatetags.admin_static import static
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
from django.contrib.admin.tests import AdminSeleniumTestCase
from django.contrib.admin.utils import quote
@@ -18,7 +17,6 @@ from django.contrib.admin.views.main import IS_POPUP_VAR
from django.contrib.auth import REDIRECT_FIELD_NAME, get_permission_codename
from django.contrib.auth.models import Group, Permission, User
from django.contrib.contenttypes.models import ContentType
-from django.contrib.staticfiles.storage import staticfiles_storage
from django.core import mail
from django.core.checks import Error
from django.core.files import temp as tempfile
@@ -200,18 +198,6 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
response = self.client.get(add_url[:-1])
self.assertRedirects(response, add_url, status_code=301)
- def test_admin_static_template_tag(self):
- """
- admin_static.static points 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):
"""
A smoke test to ensure GET on the add_view works.
diff --git a/tests/staticfiles_tests/cases.py b/tests/staticfiles_tests/cases.py
index 3adf5cf211..918ec4f99e 100644
--- a/tests/staticfiles_tests/cases.py
+++ b/tests/staticfiles_tests/cases.py
@@ -34,8 +34,8 @@ class BaseStaticFilesMixin:
def static_template_snippet(self, path, asvar=False):
if asvar:
- return "{%% load static from staticfiles %%}{%% static '%s' as var %%}{{ var }}" % path
- return "{%% load static from staticfiles %%}{%% static '%s' %%}" % path
+ return "{%% load static from static %%}{%% static '%s' as var %%}{{ var }}" % path
+ return "{%% load static from static %%}{%% static '%s' %%}" % path
def assertStaticRenders(self, path, result, asvar=False, **kwargs):
template = self.static_template_snippet(path, asvar)
diff --git a/tests/staticfiles_tests/test_forms.py b/tests/staticfiles_tests/test_forms.py
index c5dc66de61..0178bab931 100644
--- a/tests/staticfiles_tests/test_forms.py
+++ b/tests/staticfiles_tests/test_forms.py
@@ -1,8 +1,8 @@
from urllib.parse import urljoin
from django.contrib.staticfiles import storage
-from django.contrib.staticfiles.templatetags.staticfiles import static
from django.forms import Media
+from django.templatetags.static import static
from django.test import SimpleTestCase, override_settings
diff --git a/tests/staticfiles_tests/test_templatetag_deprecation.py b/tests/staticfiles_tests/test_templatetag_deprecation.py
new file mode 100644
index 0000000000..0194b0745e
--- /dev/null
+++ b/tests/staticfiles_tests/test_templatetag_deprecation.py
@@ -0,0 +1,45 @@
+import warnings
+from urllib.parse import urljoin
+
+from django.contrib.staticfiles import storage
+from django.contrib.staticfiles.templatetags.staticfiles import static
+from django.template import Context, Template
+from django.test import SimpleTestCase, override_settings
+from django.utils.deprecation import RemovedInDjango30Warning
+
+
+class StaticTestStorage(storage.StaticFilesStorage):
+ def url(self, name):
+ return urljoin('https://example.com/assets/', name)
+
+
+@override_settings(
+ STATIC_URL='http://media.example.com/static/',
+ INSTALLED_APPS=('django.contrib.staticfiles',),
+ STATICFILES_STORAGE='staticfiles_tests.test_forms.StaticTestStorage',
+)
+class StaticDeprecationTests(SimpleTestCase):
+ def test_templatetag_deprecated(self):
+ msg = '{% load staticfiles %} is deprecated in favor of {% load static %}.'
+ template = "{% load staticfiles %}{% static 'main.js' %}"
+ with warnings.catch_warnings(record=True) as recorded:
+ warnings.simplefilter('always')
+ template = Template(template)
+ rendered = template.render(Context())
+ self.assertEqual(rendered, 'https://example.com/assets/main.js')
+ self.assertEqual(len(recorded), 1)
+ self.assertIs(recorded[0].category, RemovedInDjango30Warning)
+ self.assertEqual(str(recorded[0].message), msg)
+
+ def test_static_deprecated(self):
+ msg = (
+ 'django.contrib.staticfiles.templatetags.static() is deprecated in '
+ 'favor of django.templatetags.static.static().'
+ )
+ with warnings.catch_warnings(record=True) as recorded:
+ warnings.simplefilter('always')
+ url = static('main.js')
+ self.assertEqual(url, 'https://example.com/assets/main.js')
+ self.assertEqual(len(recorded), 1)
+ self.assertIs(recorded[0].category, RemovedInDjango30Warning)
+ self.assertEqual(str(recorded[0].message), msg)