From dd82f1df556561233eab6a4a2032c2bb306dec87 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Tue, 22 Aug 2017 14:45:08 +0200 Subject: [PATCH] [1.11.x] Fixed #28502 -- Made stringformat template filter accept tuples. Backport of 4ead705cb3cf04bb7551ac037d1e11f682b62bcf and ed77bea58274e11e5a9e4c8b9650f50deb8a2b26 from master --- django/template/defaultfilters.py | 2 ++ docs/releases/1.11.5.txt | 2 ++ tests/template_tests/filter_tests/test_stringformat.py | 3 +++ 3 files changed, 7 insertions(+) diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index a1f96f5e2e..bfa6cff668 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -249,6 +249,8 @@ def stringformat(value, arg): See https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting for documentation of Python string formatting. """ + if isinstance(value, tuple): + value = six.text_type(value) try: return ("%" + six.text_type(arg)) % value except (ValueError, TypeError): diff --git a/docs/releases/1.11.5.txt b/docs/releases/1.11.5.txt index 556cc73793..e7c6c91a5d 100644 --- a/docs/releases/1.11.5.txt +++ b/docs/releases/1.11.5.txt @@ -13,3 +13,5 @@ Bugfixes in GEOS 3.6.2) (:ticket:`28441`). * Fixed test database creation with ``cx_Oracle`` 6 (:ticket:`28498`). + +* Fixed select widget rendering when option values are tuples (:ticket:`28502`). diff --git a/tests/template_tests/filter_tests/test_stringformat.py b/tests/template_tests/filter_tests/test_stringformat.py index 9501878ebd..19e2d9eb17 100644 --- a/tests/template_tests/filter_tests/test_stringformat.py +++ b/tests/template_tests/filter_tests/test_stringformat.py @@ -29,6 +29,9 @@ class FunctionTests(SimpleTestCase): def test_format(self): self.assertEqual(stringformat(1, '03d'), '001') + self.assertEqual(stringformat((1, 2, 3), 's'), '(1, 2, 3)') + self.assertEqual(stringformat((1,), 's'), '(1,)') def test_invalid(self): self.assertEqual(stringformat(1, 'z'), '') + self.assertEqual(stringformat((1, 2, 3), 'd'), '')