summaryrefslogtreecommitdiff
path: root/django/forms/util.py
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2013-09-10 14:23:31 -0400
committerTim Graham <timograham@gmail.com>2013-09-10 14:24:34 -0400
commit8165c2cfd1922bb9d56a9e68e6456736acacf445 (patch)
treeb6152f2e69988447ed7166ccbea291ecc9a7186a /django/forms/util.py
parent4e96dac450e3546bf86220932f5a64fea1ad5bac (diff)
Improved deprecation warning for change in form boolean values.
refs #20684 Thanks jacob, jcd, and shai for the suggestions.
Diffstat (limited to 'django/forms/util.py')
-rw-r--r--django/forms/util.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/django/forms/util.py b/django/forms/util.py
index 320a74e721..bb5bb8c2e4 100644
--- a/django/forms/util.py
+++ b/django/forms/util.py
@@ -23,11 +23,18 @@ def flatatt(attrs):
The result is passed through 'mark_safe'.
"""
- if [v for v in attrs.values() if v is True or v is False]:
- warnings.warn(
- 'The meaning of boolean values for widget attributes will change in Django 1.8',
- DeprecationWarning
- )
+ for attr_name, value in attrs.items():
+ if type(value) is bool:
+ warnings.warn(
+ "In Django 1.8, widget attribute %(attr_name)s=%(bool_value)s "
+ "will %(action)s. To preserve current behavior, use the "
+ "string '%(bool_value)s' instead of the boolean value." % {
+ 'attr_name': attr_name,
+ 'action': "be rendered as '%s'" % attr_name if value else "not be rendered",
+ 'bool_value': value,
+ },
+ DeprecationWarning
+ )
return format_html_join('', ' {0}="{1}"', sorted(attrs.items()))
@python_2_unicode_compatible