Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed #4316 -- Added docstring and tests for django.newforms.utils.fl…


Thanks, Gary Wilson.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 5ab9c3a commit 534c0d8442e9646c10e746b45c48b8092c105d35 @malcolmt malcolmt committed
Showing with 17 additions and 3 deletions.
  1. +8 −3 django/newforms/
  2. +9 −0 tests/regressiontests/forms/
11 django/newforms/
@@ -1,9 +1,14 @@
from django.utils.html import escape
from django.utils.encoding import smart_unicode
-# Converts a dictionary to a single string with key="value", XML-style with
-# a leading space. Assumes keys do not need to be XML-escaped.
-flatatt = lambda attrs: u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()])
+def flatatt(attrs):
+ """
+ Convert a dictionary of attributes to a single string.
+ The returned string will contain a leading space followed by key="value",
+ 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()])
class ErrorDict(dict):
9 tests/regressiontests/forms/
@@ -3515,6 +3515,15 @@
>>> smart_unicode('foo')
+# flatatt tests
+>>> from django.newforms.util import flatatt
+>>> flatatt({'id': "header"})
+u' id="header"'
+>>> flatatt({'class': "news", 'title': "Read this"})
+u' class="news" title="Read this"'
+>>> flatatt({})
__test__ = {

0 comments on commit 534c0d8

Please sign in to comment.
Something went wrong with that request. Please try again.