Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved deprecation warning for change in form boolean values.

refs #20684

Thanks jacob, jcd, and shai for the suggestions.
  • Loading branch information...
commit 8165c2cfd1922bb9d56a9e68e6456736acacf445 1 parent 4e96dac
@timgraham timgraham authored
Showing with 12 additions and 5 deletions.
  1. +12 −5 django/forms/util.py
View
17 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
Please sign in to comment.
Something went wrong with that request. Please try again.