Changeset 5291
- Timestamp:
- 05/19/07 13:49:35 (2 years ago)
- Files:
-
- django/trunk/django/newforms/util.py (modified) (1 diff)
- django/trunk/tests/regressiontests/forms/tests.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/newforms/util.py
r5263 r5291 2 2 from django.utils.encoding import smart_unicode 3 3 4 # Converts a dictionary to a single string with key="value", XML-style with 5 # a leading space. Assumes keys do not need to be XML-escaped. 6 flatatt = lambda attrs: u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()]) 4 def flatatt(attrs): 5 """ 6 Convert a dictionary of attributes to a single string. 7 The returned string will contain a leading space followed by key="value", 8 XML-style pairs. It is assumed that the keys do not need to be XML-escaped. 9 If the passed dictionary is empty, then return an empty string. 10 """ 11 return u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()]) 7 12 8 13 class ErrorDict(dict): django/trunk/tests/regressiontests/forms/tests.py
r5237 r5291 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
