summaryrefslogtreecommitdiff
path: root/django/newforms/util.py
diff options
context:
space:
mode:
authorJoseph Kocherhans <joseph@jkocherhans.com>2006-12-07 23:15:08 +0000
committerJoseph Kocherhans <joseph@jkocherhans.com>2006-12-07 23:15:08 +0000
commitd87c354b65da2b1a3602bbd462f9b694e4519b8d (patch)
tree5d6e760655502b860befe1bd9f8041527e1c42b9 /django/newforms/util.py
parent4542f21fc1b82dd0faa7be634640d2173339cb1e (diff)
generic-auth: Merged to trunk [4183].
git-svn-id: http://code.djangoproject.com/svn/django/branches/generic-auth@4184 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms/util.py')
-rw-r--r--django/newforms/util.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/django/newforms/util.py b/django/newforms/util.py
index a5cc4932ea..a78623a17b 100644
--- a/django/newforms/util.py
+++ b/django/newforms/util.py
@@ -1,13 +1,22 @@
-# Default encoding for input byte strings.
-DEFAULT_ENCODING = 'utf-8' # TODO: First look at django.conf.settings, then fall back to this.
+from django.conf import settings
def smart_unicode(s):
if not isinstance(s, basestring):
s = unicode(str(s))
elif not isinstance(s, unicode):
- s = unicode(s, DEFAULT_ENCODING)
+ s = unicode(s, settings.DEFAULT_CHARSET)
return s
+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.