=== modified file 'django/newforms/util.py'
|
|
|
3 | 3 | from django.utils.functional import Promise, lazy |
4 | 4 | from django.utils.encoding import smart_unicode |
5 | 5 | |
6 | | # Converts a dictionary to a single string with key="value", XML-style with |
7 | | # a leading space. Assumes keys do not need to be XML-escaped. |
8 | | flatatt = lambda attrs: u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()]) |
| 6 | def flatatt(attrs): |
| 7 | """ |
| 8 | Convert a dictionary of attributes to a single string. |
| 9 | The returned string will contain a leading space followed by key="value", |
| 10 | XML-style pairs. It is assumed that the keys do not need to be XML-escaped. |
| 11 | If the passed dictionary is empty, then return an empty string. |
| 12 | """ |
| 13 | return u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()]) |
9 | 14 | |
10 | 15 | class ErrorDict(dict): |
11 | 16 | """ |
=== modified file 'tests/regressiontests/forms/tests.py'
|
|
|
3515 | 3515 | u'1' |
3516 | 3516 | >>> smart_unicode('foo') |
3517 | 3517 | u'foo' |
| 3518 | |
| 3519 | # flatatt tests |
| 3520 | >>> from django.newforms.util import flatatt |
| 3521 | >>> flatatt({'id': "header"}) |
| 3522 | u' id="header"' |
| 3523 | >>> flatatt({'class': "news", 'title': "Read this"}) |
| 3524 | u' class="news" title="Read this"' |
| 3525 | >>> flatatt({}) |
| 3526 | u'' |
3518 | 3527 | """ |
3519 | 3528 | |
3520 | 3529 | __test__ = { |