diff options
| author | Christopher Long <indirecthit@gmail.com> | 2007-06-17 22:18:54 +0000 |
|---|---|---|
| committer | Christopher Long <indirecthit@gmail.com> | 2007-06-17 22:18:54 +0000 |
| commit | ae22b6d403dcf25098c77f0dfcf59ae58b186461 (patch) | |
| tree | c37fc631e99a7e4d909d6b6d236f495003731ea7 /django/newforms/util.py | |
| parent | 0cf7bc439129c66df8d64601e885f83b256b4f25 (diff) | |
per-object-permissions: Merged to trunk [5486] NOTE: Not fully tested, will be working on this over the next few weeks.
git-svn-id: http://code.djangoproject.com/svn/django/branches/per-object-permissions@5488 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms/util.py')
| -rw-r--r-- | django/newforms/util.py | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/django/newforms/util.py b/django/newforms/util.py index a78623a17b..891585cba2 100644 --- a/django/newforms/util.py +++ b/django/newforms/util.py @@ -1,21 +1,14 @@ -from django.conf import settings +from django.utils.html import escape +from django.utils.encoding import smart_unicode -def smart_unicode(s): - if not isinstance(s, basestring): - s = unicode(str(s)) - elif not isinstance(s, unicode): - s = unicode(s, settings.DEFAULT_CHARSET) - return s - -class StrAndUnicode(object): +def flatatt(attrs): """ - A class whose __str__ returns its __unicode__ as a bytestring - according to settings.DEFAULT_CHARSET. - - Useful as a mix-in. + 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. """ - def __str__(self): - return self.__unicode__().encode(settings.DEFAULT_CHARSET) + return u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()]) class ErrorDict(dict): """ |
