From f032bbc8b107ab9274542f8d233fc88aa1c6e04d Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Mon, 7 Nov 2016 18:19:34 -0500 Subject: [PATCH] Refs #18651 -- Removed assignment_tag per deprecation timeline. --- django/template/library.py | 10 ------- docs/howto/custom-template-tags.txt | 29 --------------------- docs/releases/1.9.txt | 5 ++-- docs/releases/2.0.txt | 2 ++ tests/template_tests/templatetags/custom.py | 17 ------------ tests/template_tests/test_custom.py | 23 ---------------- 6 files changed, 4 insertions(+), 82 deletions(-) diff --git a/django/template/library.py b/django/template/library.py index 04f4a7322d..8a6c98ee09 100644 --- a/django/template/library.py +++ b/django/template/library.py @@ -1,9 +1,7 @@ import functools -import warnings from importlib import import_module from django.utils import six -from django.utils.deprecation import RemovedInDjango20Warning from django.utils.html import conditional_escape from django.utils.inspect import getargspec from django.utils.itercompat import is_iterable @@ -136,14 +134,6 @@ class Library(object): else: raise ValueError("Invalid arguments provided to simple_tag") - def assignment_tag(self, func=None, takes_context=None, name=None): - warnings.warn( - "assignment_tag() is deprecated. Use simple_tag() instead", - RemovedInDjango20Warning, - stacklevel=2, - ) - return self.simple_tag(func, takes_context, name) - def inclusion_tag(self, filename, func=None, takes_context=None, name=None): """ Register a callable as an inclusion tag: diff --git a/docs/howto/custom-template-tags.txt b/docs/howto/custom-template-tags.txt index 53ea433137..448576784f 100644 --- a/docs/howto/custom-template-tags.txt +++ b/docs/howto/custom-template-tags.txt @@ -629,35 +629,6 @@ positional arguments. For example: {% my_tag 123 "abcd" book.title warning=message|lower profile=user.profile %} -Assignment tags ---------------- - -.. method:: django.template.Library.assignment_tag() - -.. deprecated:: 1.9 - - ``simple_tag`` can now store results in a template variable and should - be used instead. - -To ease the creation of tags setting a variable in the context, Django provides -a helper function, ``assignment_tag``. This function works the same way as -:meth:`~django.template.Library.simple_tag` except that it stores the tag's -result in a specified context variable instead of directly outputting it. - -Our earlier ``current_time`` function could thus be written like this:: - - @register.assignment_tag - def get_current_time(format_string): - return datetime.datetime.now().strftime(format_string) - -You may then store the result in a template variable using the ``as`` argument -followed by the variable name, and output it yourself where you see fit: - -.. code-block:: html+django - - {% get_current_time "%Y-%m-%d %I:%M %p" as the_time %} -

The time is {{ the_time }}.

- Advanced custom template tags ----------------------------- diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt index adcd6c949b..b7b489499d 100644 --- a/docs/releases/1.9.txt +++ b/docs/releases/1.9.txt @@ -938,9 +938,8 @@ define built-in libraries via the ``'builtins'`` key of :setting:`OPTIONS In general, template tags do not autoescape their contents, and this behavior is :ref:`documented `. For tags like :class:`~django.template.Library.inclusion_tag`, this is not a problem because -the included template will perform autoescaping. For -:class:`~django.template.Library.assignment_tag`, the output will be escaped -when it is used as a variable in the template. +the included template will perform autoescaping. For ``assignment_tag()``, +the output will be escaped when it is used as a variable in the template. For the intended use cases of :class:`~django.template.Library.simple_tag`, however, it is very easy to end up with incorrect HTML and possibly an XSS diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt index 97e59ca26f..751b46cccf 100644 --- a/docs/releases/2.0.txt +++ b/docs/releases/2.0.txt @@ -241,3 +241,5 @@ these features. is removed. * The ``django.forms.extras`` package is removed. + +* The ``assignment_tag`` helper is removed. diff --git a/tests/template_tests/templatetags/custom.py b/tests/template_tests/templatetags/custom.py index fffef022ac..3c3e4ce8ed 100644 --- a/tests/template_tests/templatetags/custom.py +++ b/tests/template_tests/templatetags/custom.py @@ -1,5 +1,4 @@ import operator -import warnings from django import template from django.template.defaultfilters import stringfilter @@ -168,19 +167,3 @@ def minustwo_overridden_name(value): register.simple_tag(lambda x: x - 1, name='minusone') - - -with warnings.catch_warnings(): - warnings.simplefilter('ignore') - - @register.assignment_tag - def assignment_no_params(): - """Expected assignment_no_params __doc__""" - return "assignment_no_params - Expected result" - assignment_no_params.anything = "Expected assignment_no_params __dict__" - - @register.assignment_tag(takes_context=True) - def assignment_tag_without_context_parameter(arg): - """Expected assignment_tag_without_context_parameter __doc__""" - return "Expected result" - assignment_tag_without_context_parameter.anything = "Expected assignment_tag_without_context_parameter __dict__" diff --git a/tests/template_tests/test_custom.py b/tests/template_tests/test_custom.py index e6a876086e..b63882a9a8 100644 --- a/tests/template_tests/test_custom.py +++ b/tests/template_tests/test_custom.py @@ -306,29 +306,6 @@ class InclusionTagTests(TagTestCase): self.assertEqual(template.render(Context({})).strip(), 'one\ntwo') -class AssignmentTagTests(TagTestCase): - - def test_assignment_tags(self): - c = Context({'value': 42}) - - t = self.engine.from_string('{% load custom %}{% assignment_no_params as var %}The result is: {{ var }}') - self.assertEqual(t.render(c), 'The result is: assignment_no_params - Expected result') - - def test_assignment_tag_registration(self): - # The decorators preserve the decorated function's docstring, name, - # and attributes. - self.verify_tag(custom.assignment_no_params, 'assignment_no_params') - - def test_assignment_tag_missing_context(self): - # The 'context' parameter must be present when takes_context is True - msg = ( - "'assignment_tag_without_context_parameter' is decorated with " - "takes_context=True so it must have a first argument of 'context'" - ) - with self.assertRaisesMessage(TemplateSyntaxError, msg): - self.engine.from_string('{% load custom %}{% assignment_tag_without_context_parameter 123 as var %}') - - class TemplateTagLoadingTests(SimpleTestCase): @classmethod