summaryrefslogtreecommitdiff
path: root/django/core/formfields.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2005-10-06 02:27:08 +0000
committerAdrian Holovaty <adrian@holovaty.com>2005-10-06 02:27:08 +0000
commitab9aacd4db5d1e69ff2c78bae69fcabe5252d395 (patch)
treed09b59dfbf42b700223f474937fb27fd9d02ea2a /django/core/formfields.py
parent261ab166cef09497ab2204442e74246758341135 (diff)
Fixed #333 and #440 -- Split DEFAULT_MIME_TYPE setting into DEFAULT_CONTENT_TYPE and DEFAULT_CHARSET. Thanks, Maniac.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@786 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core/formfields.py')
-rw-r--r--django/core/formfields.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/django/core/formfields.py b/django/core/formfields.py
index 7587b67170..76721ba5c6 100644
--- a/django/core/formfields.py
+++ b/django/core/formfields.py
@@ -1,6 +1,7 @@
from django.core import validators
from django.core.exceptions import PermissionDenied
from django.utils.html import escape
+from django.conf.settings import DEFAULT_CHARSET
FORM_FIELD_ID_PREFIX = 'id_'
@@ -221,7 +222,7 @@ class TextField(FormField):
self.validator_list = [self.isValidLength, self.hasNoNewlines] + validator_list
def isValidLength(self, data, form):
- if data and self.maxlength and len(data) > self.maxlength:
+ if data and self.maxlength and len(data.decode(DEFAULT_CHARSET)) > self.maxlength:
raise validators.ValidationError, "Ensure your text is less than %s characters." % self.maxlength
def hasNoNewlines(self, data, form):
@@ -235,7 +236,7 @@ class TextField(FormField):
if self.maxlength:
maxlength = 'maxlength="%s" ' % self.maxlength
if isinstance(data, unicode):
- data = data.encode('utf-8')
+ data = data.encode(DEFAULT_CHARSET)
return '<input type="text" id="%s" class="v%s%s" name="%s" size="%s" value="%s" %s/>' % \
(FORM_FIELD_ID_PREFIX + self.field_name, self.__class__.__name__, self.is_required and ' required' or '',
self.field_name, self.length, escape(data), maxlength)
@@ -264,7 +265,7 @@ class LargeTextField(TextField):
if data is None:
data = ''
if isinstance(data, unicode):
- data = data.encode('utf-8')
+ data = data.encode(DEFAULT_CHARSET)
return '<textarea id="%s" class="v%s%s" name="%s" rows="%s" cols="%s">%s</textarea>' % \
(FORM_FIELD_ID_PREFIX + self.field_name, self.__class__.__name__, self.is_required and ' required' or '',
self.field_name, self.rows, self.cols, escape(data))