Skip to content

Commit 1fc8f84

Browse files
committed
Fixed #8566 -- Allow safe-strings in the "attrs" parameter to form widgets.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8601 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 5f39619 commit 1fc8f84

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

django/forms/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.utils.html import escape
1+
from django.utils.html import conditional_escape
22
from django.utils.encoding import smart_unicode, StrAndUnicode, force_unicode
33
from django.utils.safestring import mark_safe
44

@@ -9,7 +9,7 @@ def flatatt(attrs):
99
XML-style pairs. It is assumed that the keys do not need to be XML-escaped.
1010
If the passed dictionary is empty, then return an empty string.
1111
"""
12-
return u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()])
12+
return u''.join([u' %s="%s"' % (k, conditional_escape(v)) for k, v in attrs.items()])
1313

1414
class ErrorDict(dict, StrAndUnicode):
1515
"""

django/utils/translation/trans_real.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ def get_date_formats():
403403
date_format = ugettext('DATE_FORMAT')
404404
datetime_format = ugettext('DATETIME_FORMAT')
405405
time_format = ugettext('TIME_FORMAT')
406+
datetime_full_format = ugettext('DATE_WITH_TIME_FULL')
406407
if date_format == 'DATE_FORMAT':
407408
date_format = settings.DATE_FORMAT
408409
if datetime_format == 'DATETIME_FORMAT':

tests/regressiontests/forms/widgets.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
>>> w.render('email', '', attrs={'class': 'special'})
5151
u'<input type="text" class="special" name="email" />'
5252
53+
'attrs' can be safe-strings if needed
54+
>>> w = TextInput(attrs={'onBlur': mark_safe("function('foo')")})
55+
>>> print w.render('email', '')
56+
<input onBlur="function('foo')" type="text" name="email" />
57+
5358
# PasswordInput Widget ############################################################
5459
5560
>>> w = PasswordInput()

0 commit comments

Comments
 (0)