summaryrefslogtreecommitdiff
path: root/django/newforms
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-04-04 06:34:19 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-04-04 06:34:19 +0000
commit1bddac37b69152d919a3af29f2844ae3e34c7237 (patch)
tree1d6663957982521930b1ff5d85e12d5b7d7e9917 /django/newforms
parentf791a598a8e207a6f362ea75b9474f7739b518c7 (diff)
Moved smart_unicode and StrAndUnicode to django.utils.encoding. They are useful
outside of newforms. This is backwards compatible as far as smart_unicode goes (since newforms.util still imports it). All imports of smart_unicode and StrAndUnicode have also been updated. git-svn-id: http://code.djangoproject.com/svn/django/trunk@4918 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms')
-rw-r--r--django/newforms/fields.py3
-rw-r--r--django/newforms/forms.py3
-rw-r--r--django/newforms/util.py31
-rw-r--r--django/newforms/widgets.py3
4 files changed, 7 insertions, 33 deletions
diff --git a/django/newforms/fields.py b/django/newforms/fields.py
index 72c5047030..c3b74e93f7 100644
--- a/django/newforms/fields.py
+++ b/django/newforms/fields.py
@@ -3,7 +3,8 @@ Field classes
"""
from django.utils.translation import gettext
-from util import ErrorList, ValidationError, smart_unicode
+from django.utils.encoding import smart_unicode
+from util import ErrorList, ValidationError
from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple
import datetime
import re
diff --git a/django/newforms/forms.py b/django/newforms/forms.py
index 2b3aa97428..9affe2fc82 100644
--- a/django/newforms/forms.py
+++ b/django/newforms/forms.py
@@ -4,9 +4,10 @@ Form classes
from django.utils.datastructures import SortedDict, MultiValueDict
from django.utils.html import escape
+from django.utils.encoding import StrAndUnicode
from fields import Field
from widgets import TextInput, Textarea, HiddenInput, MultipleHiddenInput
-from util import flatatt, StrAndUnicode, ErrorDict, ErrorList, ValidationError
+from util import flatatt, ErrorDict, ErrorList, ValidationError
import copy
__all__ = ('BaseForm', 'Form')
diff --git a/django/newforms/util.py b/django/newforms/util.py
index f98027c2e3..5fc0223f5b 100644
--- a/django/newforms/util.py
+++ b/django/newforms/util.py
@@ -1,41 +1,12 @@
from django.conf import settings
from django.utils.html import escape
from django.utils.functional import Promise, lazy
+from django.utils.encoding import smart_unicode
# 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):
- if isinstance(s, Promise):
- # The input is something from gettext_lazy or similar. We don't want to
- # translate it until render time, so defer the conversion.
- return smart_unicode_lazy(s)
- else:
- return smart_unicode_immediate(s)
-
-def smart_unicode_immediate(s):
- if not isinstance(s, basestring):
- if hasattr(s, '__unicode__'):
- s = unicode(s)
- else:
- s = unicode(str(s), settings.DEFAULT_CHARSET)
- elif not isinstance(s, unicode):
- s = unicode(s, settings.DEFAULT_CHARSET)
- return s
-
-smart_unicode_lazy = lazy(smart_unicode_immediate, unicode)
-
-class StrAndUnicode(object):
- """
- A class whose __str__ returns its __unicode__ as a bytestring
- according to settings.DEFAULT_CHARSET.
-
- Useful as a mix-in.
- """
- def __str__(self):
- return self.__unicode__().encode(settings.DEFAULT_CHARSET)
-
class ErrorDict(dict):
"""
A collection of errors that knows how to display itself in various formats.
diff --git a/django/newforms/widgets.py b/django/newforms/widgets.py
index 58d8ab1322..8d292673a5 100644
--- a/django/newforms/widgets.py
+++ b/django/newforms/widgets.py
@@ -9,10 +9,11 @@ __all__ = (
'MultiWidget', 'SplitDateTimeWidget',
)
-from util import flatatt, StrAndUnicode, smart_unicode
+from util import flatatt
from django.utils.datastructures import MultiValueDict
from django.utils.html import escape
from django.utils.translation import gettext
+from django.utils.encoding import StrAndUnicode, smart_unicode
from itertools import chain
try: