From 3b050fd0d0b8dbf499bdb44ce12fa926298c0bd0 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Sat, 17 Jun 2017 08:12:05 -0400 Subject: [PATCH] Fixed #28303 -- Prevented localization of attribute values in the DTL attrs.html widget template. --- .../templates/django/forms/widgets/attrs.html | 2 +- docs/releases/1.11.3.txt | 4 ++++ .../forms_tests/widget_tests/test_numberinput.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/forms_tests/widget_tests/test_numberinput.py diff --git a/django/forms/templates/django/forms/widgets/attrs.html b/django/forms/templates/django/forms/widgets/attrs.html index c8bba9f35c5..7a5592afcb2 100644 --- a/django/forms/templates/django/forms/widgets/attrs.html +++ b/django/forms/templates/django/forms/widgets/attrs.html @@ -1 +1 @@ -{% for name, value in widget.attrs.items %}{% if value is not False %} {{ name }}{% if value is not True %}="{{ value }}"{% endif %}{% endif %}{% endfor %} \ No newline at end of file +{% for name, value in widget.attrs.items %}{% if value is not False %} {{ name }}{% if value is not True %}="{{ value|stringformat:'s' }}"{% endif %}{% endif %}{% endfor %} \ No newline at end of file diff --git a/docs/releases/1.11.3.txt b/docs/releases/1.11.3.txt index 5ff33e42e6e..1e2ddddb66d 100644 --- a/docs/releases/1.11.3.txt +++ b/docs/releases/1.11.3.txt @@ -40,3 +40,7 @@ Bugfixes context. It's now an empty string (as it is for the original function-based ``login()`` view) if the corresponding parameter isn't sent in a request (in particular, when the login page is accessed directly) (:ticket:`28229`). + +* Prevented attribute values in the ``django/forms/widgets/attrs.html`` + template from being localized so that numeric attributes (e.g. ``max`` and + ``min``) of ``NumberInput`` work correctly (:ticket:`28303`). diff --git a/tests/forms_tests/widget_tests/test_numberinput.py b/tests/forms_tests/widget_tests/test_numberinput.py new file mode 100644 index 00000000000..95a0a9250ae --- /dev/null +++ b/tests/forms_tests/widget_tests/test_numberinput.py @@ -0,0 +1,15 @@ +from django.forms.widgets import NumberInput +from django.test import override_settings + +from .base import WidgetTest + + +class NumberInputTests(WidgetTest): + + @override_settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True) + def test_attrs_not_localized(self): + widget = NumberInput(attrs={'max': 12345, 'min': 1234, 'step': 9999}) + self.check_html( + widget, 'name', 'value', + '' + )