Permalink
Browse files

Fixed #8566 -- Allow safe-strings in the "attrs" parameter to form wi…

…dgets.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8601 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 5f39619 commit 1fc8f84f58d53033cd74afb9b26ca60dd18a055c @malcolmt malcolmt committed Aug 26, 2008
Showing with 8 additions and 2 deletions.
  1. +2 −2 django/forms/util.py
  2. +1 −0 django/utils/translation/trans_real.py
  3. +5 −0 tests/regressiontests/forms/widgets.py
View
@@ -1,4 +1,4 @@
-from django.utils.html import escape
+from django.utils.html import conditional_escape
from django.utils.encoding import smart_unicode, StrAndUnicode, force_unicode
from django.utils.safestring import mark_safe
@@ -9,7 +9,7 @@ def flatatt(attrs):
XML-style pairs. It is assumed that the keys do not need to be XML-escaped.
If the passed dictionary is empty, then return an empty string.
"""
- return u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()])
+ return u''.join([u' %s="%s"' % (k, conditional_escape(v)) for k, v in attrs.items()])
class ErrorDict(dict, StrAndUnicode):
"""
@@ -403,6 +403,7 @@ def get_date_formats():
date_format = ugettext('DATE_FORMAT')
datetime_format = ugettext('DATETIME_FORMAT')
time_format = ugettext('TIME_FORMAT')
+ datetime_full_format = ugettext('DATE_WITH_TIME_FULL')
if date_format == 'DATE_FORMAT':
date_format = settings.DATE_FORMAT
if datetime_format == 'DATETIME_FORMAT':
@@ -50,6 +50,11 @@
>>> w.render('email', '', attrs={'class': 'special'})
u'<input type="text" class="special" name="email" />'
+'attrs' can be safe-strings if needed
+>>> w = TextInput(attrs={'onBlur': mark_safe("function('foo')")})
+>>> print w.render('email', '')
+<input onBlur="function('foo')" type="text" name="email" />
+
# PasswordInput Widget ############################################################
>>> w = PasswordInput()

0 comments on commit 1fc8f84

Please sign in to comment.