newforms: Moved flatatt function from widgets.py to util.py

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4370 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2007-01-20 20:33:23 +00:00
parent a154d94e45
commit 93eebd95cb
3 changed files with 8 additions and 7 deletions

View File

@ -5,8 +5,8 @@ Form classes
from django.utils.datastructures import SortedDict, MultiValueDict from django.utils.datastructures import SortedDict, MultiValueDict
from django.utils.html import escape from django.utils.html import escape
from fields import Field from fields import Field
from widgets import flatatt, TextInput, Textarea, HiddenInput, MultipleHiddenInput from widgets import TextInput, Textarea, HiddenInput, MultipleHiddenInput
from util import StrAndUnicode, ErrorDict, ErrorList, ValidationError from util import flatatt, StrAndUnicode, ErrorDict, ErrorList, ValidationError
__all__ = ('BaseForm', 'Form') __all__ = ('BaseForm', 'Form')

View File

@ -1,4 +1,9 @@
from django.conf import settings from django.conf import settings
from django.utils.html import escape
# 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 smart_unicode(s): def smart_unicode(s):
if not isinstance(s, basestring): if not isinstance(s, basestring):

View File

@ -8,7 +8,7 @@ __all__ = (
'Select', 'SelectMultiple', 'RadioSelect', 'CheckboxSelectMultiple', 'Select', 'SelectMultiple', 'RadioSelect', 'CheckboxSelectMultiple',
) )
from util import StrAndUnicode, smart_unicode from util import flatatt, StrAndUnicode, smart_unicode
from django.utils.datastructures import MultiValueDict from django.utils.datastructures import MultiValueDict
from django.utils.html import escape from django.utils.html import escape
from itertools import chain from itertools import chain
@ -18,10 +18,6 @@ try:
except NameError: except NameError:
from sets import Set as set # Python 2.3 fallback from sets import Set as set # Python 2.3 fallback
# 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()])
class Widget(object): class Widget(object):
is_hidden = False # Determines whether this corresponds to an <input type="hidden">. is_hidden = False # Determines whether this corresponds to an <input type="hidden">.