Django

Code

Changeset 5291

Show
Ignore:
Timestamp:
05/19/07 13:49:35 (2 years ago)
Author:
mtredinnick
Message:

Fixed #4316 -- Added docstring and tests for django.newforms.utils.flatatt().
Thanks, Gary Wilson.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/newforms/util.py

    r5263 r5291  
    22from django.utils.encoding import smart_unicode 
    33 
    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()]) 
     4def 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()]) 
    712 
    813class ErrorDict(dict): 
  • django/trunk/tests/regressiontests/forms/tests.py

    r5237 r5291  
    35163516>>> smart_unicode('foo') 
    35173517u'foo' 
     3518 
     3519# flatatt tests 
     3520>>> from django.newforms.util import flatatt 
     3521>>> flatatt({'id': "header"}) 
     3522u' id="header"' 
     3523>>> flatatt({'class': "news", 'title': "Read this"}) 
     3524u' class="news" title="Read this"' 
     3525>>> flatatt({}) 
     3526u'' 
    35183527""" 
    35193528