[1.11.x] Fixed #28502 -- Made stringformat template filter accept tuples.

Backport of 4ead705cb3cf04bb7551ac037d1e11f682b62bcf and
ed77bea58274e11e5a9e4c8b9650f50deb8a2b26 from master
This commit is contained in:
Claude Paroz 2017-08-22 14:45:08 +02:00 committed by Tim Graham
parent be24b5eaa5
commit dd82f1df55
3 changed files with 7 additions and 0 deletions

View File

@ -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):

View File

@ -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`).

View File

@ -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'), '')