mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
[1.11.x] Fixed #28502 -- Made stringformat template filter accept tuples.
Backport of4ead705cb3anded77bea582from master
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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`).
|
||||
|
||||
@@ -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'), '')
|
||||
|
||||
Reference in New Issue
Block a user