Fixed #22306 -- Deprecated future versions of cycle and firstof template tags.

This commit is contained in:
Maxime Turcotte 2014-03-27 16:24:19 -04:00 committed by Tim Graham
parent 12e9adcd71
commit 5e4e0b6fe9
11 changed files with 33 additions and 12 deletions

View File

@ -633,6 +633,7 @@ answer newbie questions, and generally made Django that much better:
tt@gurgle.no
David Tulig <david.tulig@gmail.com>
Justine Tunney <jtunney@lobstertech.com>
Maxime Turcotte <maxocub@riseup.net>
Amit Upadhyay <http://www.amitu.com/blog/>
Adam Vandenberg
Geert Vanderkelen

View File

@ -1,4 +1,4 @@
{% load admin_static %}{% load firstof from future %}<!DOCTYPE html>
{% load admin_static %}<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
<head>
<title>{% block title %}{% endblock %}</title>

View File

@ -1,4 +1,4 @@
{% load i18n admin_static %}{% load cycle from future %}
{% load i18n admin_static %}
{% if result_hidden_fields %}
<div class="hiddenfields">{# DIV for HTML validation #}
{% for item in result_hidden_fields %}{{ item }}{% endfor %}

View File

@ -1,4 +1,4 @@
{% load i18n admin_static admin_modify %}{% load cycle from future %}
{% load i18n admin_static admin_modify %}
<div class="inline-group" id="{{ inline_admin_formset.formset.prefix }}-group">
<div class="tabular inline-related {% if forloop.last %}last-related{% endif %}">
{{ inline_admin_formset.formset.management_form }}

View File

@ -1,5 +1,5 @@
{% extends "admin/base_site.html" %}
{% load i18n %}{% load firstof from future %}
{% load i18n %}
{% block coltype %}colSM{% endblock %}
{% block breadcrumbs %}

View File

@ -1,5 +1,5 @@
{% extends "admin/base_site.html" %}
{% load i18n %}{% load firstof from future %}
{% load i18n %}
{% block coltype %}colSM{% endblock %}
{% block breadcrumbs %}

View File

@ -2,7 +2,7 @@ import warnings
from django.template import Library
from django.template import defaulttags
from django.utils.deprecation import RemovedInDjango19Warning
from django.utils.deprecation import RemovedInDjango19Warning, RemovedInDjango20Warning
register = Library()
@ -30,7 +30,7 @@ def cycle(parser, token):
"""
This is the future version of `cycle` with auto-escaping.
The deprecation is now complete and this version is no different
from the non-future version so this can be deprecated (#22306)
from the non-future version so this is deprecated.
By default all strings are escaped.
@ -44,6 +44,10 @@ def cycle(parser, token):
{% cycle var1 var2|safe var3|safe as somecycle %}
"""
warnings.warn(
"Loading the `cycle` tag from the `future` library is deprecated and "
"will be removed in Django 2.0. Use the default `cycle` tag instead.",
RemovedInDjango20Warning)
return defaulttags.cycle(parser, token)
@ -52,7 +56,7 @@ def firstof(parser, token):
"""
This is the future version of `firstof` with auto-escaping.
The deprecation is now complete and this version is no different
from the non-future version so this can be deprecated (#22306)
from the non-future version so this is deprecated.
This is equivalent to::
@ -75,4 +79,8 @@ def firstof(parser, token):
{% firstof var1 var2|safe var3 "<strong>fallback value</strong>"|safe %}
"""
warnings.warn(
"Loading the `firstof` tag from the `future` library is deprecated and "
"will be removed in Django 2.0. Use the default `firstof` tag instead.",
RemovedInDjango20Warning)
return defaulttags.firstof(parser, token)

View File

@ -984,7 +984,7 @@ Exception Value: {{ exception_value|force_escape }}
</html>
"""
TECHNICAL_500_TEXT_TEMPLATE = """{% load firstof from future %}{% firstof exception_type 'Report' %}{% if request %} at {{ request.path_info }}{% endif %}
TECHNICAL_500_TEXT_TEMPLATE = """{% firstof exception_type 'Report' %}{% if request %} at {{ request.path_info }}{% endif %}
{% firstof exception_value 'No exception message supplied' %}
{% if request %}
Request Method: {{ request.META.REQUEST_METHOD }}

View File

@ -12,6 +12,9 @@ about each item can often be found in the release notes of two versions prior.
2.0
---
* ``cycle`` and ``firstof`` template tags will be removed from the ``future``
template tag library (used during the 1.6/1.7 deprecation period).
.. _deprecation-removed-in-1.9:
1.9

View File

@ -180,4 +180,11 @@ Miscellaneous
Features deprecated in 1.8
==========================
...
Loading ``cycle`` and ``firstof`` template tags from ``future`` library
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Django 1.6 introduced ``{% load cycle from future %}`` and
``{% load firstof from future %}`` syntax for forward compatibility of the
:ttag:`cycle` and :ttag:`firstof` template tags. This syntax is now deprecated
and will be removed in Django 2.0. You can simply remove the
``{% load ... from future %}`` tags.

View File

@ -17,7 +17,7 @@ from django.template.loaders import app_directories, filesystem, cached
from django.test import RequestFactory, TestCase
from django.test.utils import (setup_test_template_loader,
restore_template_loaders, override_settings, extend_sys_path)
from django.utils.deprecation import RemovedInDjango19Warning
from django.utils.deprecation import RemovedInDjango19Warning, RemovedInDjango20Warning
from django.utils.encoding import python_2_unicode_compatible
from django.utils.formats import date_format
from django.utils._os import upath
@ -511,7 +511,7 @@ class TemplateRegressionTests(TestCase):
def test_ifchanged_render_once(self):
""" Test for ticket #19890. The content of ifchanged template tag was
rendered twice."""
template = Template('{% load cycle from future %}{% ifchanged %}{% cycle "1st time" "2nd time" %}{% endifchanged %}')
template = Template('{% ifchanged %}{% cycle "1st time" "2nd time" %}{% endifchanged %}')
output = template.render(Context({}))
self.assertEqual(output, '1st time')
@ -595,6 +595,8 @@ class TemplateTests(TestCase):
with warnings.catch_warnings():
# Ignore pending deprecations of loading 'ssi' and 'url' tags from future.
warnings.filterwarnings("ignore", category=RemovedInDjango19Warning, module='django.templatetags.future')
# Ignore deprecations of loading 'cycle' and 'firstof' tags from future.
warnings.filterwarnings("ignore", category=RemovedInDjango20Warning, module="django.templatetags.future")
test_template = loader.get_template(name)
except ShouldNotExecuteException:
failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template loading invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name))