Permalink
Browse files

unicode: Fixed #4152 -- Converted a lot of internal [n]gettext() call…

…s into

u[n]gettext() calls. Thanks, Ivan Sagalaev.


git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5082 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent dfc5536 commit 0da72ff885ee4e21214e477f883497e30ddee404 @malcolmt malcolmt committed Apr 26, 2007
Oops, something went wrong.
@@ -8,7 +8,7 @@
from django.utils.functional import curry
from django.utils.itercompat import tee
from django.utils.text import capfirst
-from django.utils.translation import gettext, gettext_lazy
+from django.utils.translation import ugettext, ugettext_lazy
import datetime, os, time
class NOT_PROVIDED:
@@ -39,7 +39,7 @@ def manipulator_validator_unique(f, opts, self, field_data, all_data):
return
if getattr(self, 'original_object', None) and self.original_object._get_pk_val() == old_obj._get_pk_val():
return
- raise validators.ValidationError, gettext("%(optname)s with this %(fieldname)s already exists.") % {'optname': capfirst(opts.verbose_name), 'fieldname': f.verbose_name}
+ raise validators.ValidationError, ugettext("%(optname)s with this %(fieldname)s already exists.") % {'optname': capfirst(opts.verbose_name), 'fieldname': f.verbose_name}
# A guide to Field parameters:
#
@@ -114,7 +114,7 @@ def validate_full(self, field_data, all_data):
Subclasses should implement validate(), not validate_full().
"""
if not self.blank and not field_data:
- return [gettext_lazy('This field is required.')]
+ return [ugettext_lazy('This field is required.')]
try:
self.validate(field_data, all_data)
except validators.ValidationError, e:
@@ -271,7 +271,7 @@ def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=
core_field_names.extend(f.get_manipulator_field_names(name_prefix))
# Now, if there are any, add the validator to this FormField.
if core_field_names:
- params['validator_list'].append(validators.RequiredIfOtherFieldsGiven(core_field_names, gettext_lazy("This field is required.")))
+ params['validator_list'].append(validators.RequiredIfOtherFieldsGiven(core_field_names, ugettext_lazy("This field is required.")))
# Finally, add the field_names.
field_names = self.get_manipulator_field_names(name_prefix)
@@ -364,7 +364,7 @@ def to_python(self, value):
try:
return int(value)
except (TypeError, ValueError):
- raise validators.ValidationError, gettext("This value must be an integer.")
+ raise validators.ValidationError, ugettext("This value must be an integer.")
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True):
if not rel:
@@ -399,7 +399,7 @@ def to_python(self, value):
if value in (True, False): return value
if value in ('t', 'True', '1'): return True
if value in ('f', 'False', '0'): return False
- raise validators.ValidationError, gettext("This value must be either True or False.")
+ raise validators.ValidationError, ugettext("This value must be either True or False.")
def get_manipulator_field_objs(self):
return [oldforms.CheckboxField]
@@ -420,7 +420,7 @@ def to_python(self, value):
if self.null:
return value
else:
- raise validators.ValidationError, gettext_lazy("This field cannot be null.")
+ raise validators.ValidationError, ugettext_lazy("This field cannot be null.")
return str(value)
def formfield(self, **kwargs):
@@ -454,7 +454,7 @@ def to_python(self, value):
try:
return datetime.date(*time.strptime(value, '%Y-%m-%d')[:3])
except ValueError:
- raise validators.ValidationError, gettext('Enter a valid date in YYYY-MM-DD format.')
+ raise validators.ValidationError, ugettext('Enter a valid date in YYYY-MM-DD format.')
def get_db_prep_lookup(self, lookup_type, value):
if lookup_type == 'range':
@@ -523,7 +523,7 @@ def to_python(self, value):
try:
return datetime.datetime(*time.strptime(value, '%Y-%m-%d')[:3])
except ValueError:
- raise validators.ValidationError, gettext('Enter a valid date/time in YYYY-MM-DD HH:MM format.')
+ raise validators.ValidationError, ugettext('Enter a valid date/time in YYYY-MM-DD HH:MM format.')
def get_db_prep_save(self, value):
# Casts dates into string format for entry into database.
@@ -607,7 +607,7 @@ def __init__(self, other_field_names, other_file_field_name):
self.always_test = True
def __call__(self, field_data, all_data):
if not all_data.get(self.other_file_field_name, False):
- c = validators.RequiredIfOtherFieldsGiven(self.other_field_names, gettext_lazy("This field is required."))
+ c = validators.RequiredIfOtherFieldsGiven(self.other_field_names, ugettext_lazy("This field is required."))
c(field_data, all_data)
# First, get the core fields, if any.
core_field_names = []
@@ -618,7 +618,7 @@ def __call__(self, field_data, all_data):
if core_field_names:
field_list[0].validator_list.append(RequiredFileField(core_field_names, field_list[1].field_name))
else:
- v = validators.RequiredIfOtherFieldNotGiven(field_list[1].field_name, gettext_lazy("This field is required."))
+ v = validators.RequiredIfOtherFieldNotGiven(field_list[1].field_name, ugettext_lazy("This field is required."))
v.always_test = True
field_list[0].validator_list.append(v)
field_list[0].is_required = field_list[1].is_required = False
@@ -748,7 +748,7 @@ def to_python(self, value):
if value in ('None'): return None
if value in ('t', 'True', '1'): return True
if value in ('f', 'False', '0'): return False
- raise validators.ValidationError, gettext("This value must be either None, True or False.")
+ raise validators.ValidationError, ugettext("This value must be either None, True or False.")
def get_manipulator_field_objs(self):
return [oldforms.NullBooleanField]
@@ -2,7 +2,7 @@
Field classes
"""
-from django.utils.translation import gettext
+from django.utils.translation import ugettext
from django.utils.encoding import smart_unicode
from util import ErrorList, ValidationError
from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple
@@ -77,7 +77,7 @@ def clean(self, value):
Raises ValidationError for any errors.
"""
if self.required and value in EMPTY_VALUES:
- raise ValidationError(gettext(u'This field is required.'))
+ raise ValidationError(ugettext(u'This field is required.'))
return value
def widget_attrs(self, widget):
@@ -100,9 +100,9 @@ def clean(self, value):
return u''
value = smart_unicode(value)
if self.max_length is not None and len(value) > self.max_length:
- raise ValidationError(gettext(u'Ensure this value has at most %d characters.') % self.max_length)
+ raise ValidationError(ugettext(u'Ensure this value has at most %d characters.') % self.max_length)
if self.min_length is not None and len(value) < self.min_length:
- raise ValidationError(gettext(u'Ensure this value has at least %d characters.') % self.min_length)
+ raise ValidationError(ugettext(u'Ensure this value has at least %d characters.') % self.min_length)
return value
def widget_attrs(self, widget):
@@ -125,11 +125,11 @@ def clean(self, value):
try:
value = int(value)
except (ValueError, TypeError):
- raise ValidationError(gettext(u'Enter a whole number.'))
+ raise ValidationError(ugettext(u'Enter a whole number.'))
if self.max_value is not None and value > self.max_value:
- raise ValidationError(gettext(u'Ensure this value is less than or equal to %s.') % self.max_value)
+ raise ValidationError(ugettext(u'Ensure this value is less than or equal to %s.') % self.max_value)
if self.min_value is not None and value < self.min_value:
- raise ValidationError(gettext(u'Ensure this value is greater than or equal to %s.') % self.min_value)
+ raise ValidationError(ugettext(u'Ensure this value is greater than or equal to %s.') % self.min_value)
return value
DEFAULT_DATE_INPUT_FORMATS = (
@@ -162,7 +162,7 @@ def clean(self, value):
return datetime.date(*time.strptime(value, format)[:3])
except ValueError:
continue
- raise ValidationError(gettext(u'Enter a valid date.'))
+ raise ValidationError(ugettext(u'Enter a valid date.'))
DEFAULT_TIME_INPUT_FORMATS = (
'%H:%M:%S', # '14:30:59'
@@ -189,7 +189,7 @@ def clean(self, value):
return datetime.time(*time.strptime(value, format)[3:6])
except ValueError:
continue
- raise ValidationError(gettext(u'Enter a valid time.'))
+ raise ValidationError(ugettext(u'Enter a valid time.'))
DEFAULT_DATETIME_INPUT_FORMATS = (
'%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59'
@@ -225,7 +225,7 @@ def clean(self, value):
return datetime.datetime(*time.strptime(value, format)[:6])
except ValueError:
continue
- raise ValidationError(gettext(u'Enter a valid date/time.'))
+ raise ValidationError(ugettext(u'Enter a valid date/time.'))
class RegexField(Field):
def __init__(self, regex, max_length=None, min_length=None, error_message=None, *args, **kwargs):
@@ -239,7 +239,7 @@ def __init__(self, regex, max_length=None, min_length=None, error_message=None,
regex = re.compile(regex)
self.regex = regex
self.max_length, self.min_length = max_length, min_length
- self.error_message = error_message or gettext(u'Enter a valid value.')
+ self.error_message = error_message or ugettext(u'Enter a valid value.')
def clean(self, value):
"""
@@ -253,9 +253,9 @@ def clean(self, value):
if value == u'':
return value
if self.max_length is not None and len(value) > self.max_length:
- raise ValidationError(gettext(u'Ensure this value has at most %d characters.') % self.max_length)
+ raise ValidationError(ugettext(u'Ensure this value has at most %d characters.') % self.max_length)
if self.min_length is not None and len(value) < self.min_length:
- raise ValidationError(gettext(u'Ensure this value has at least %d characters.') % self.min_length)
+ raise ValidationError(ugettext(u'Ensure this value has at least %d characters.') % self.min_length)
if not self.regex.search(value):
raise ValidationError(self.error_message)
return value
@@ -268,7 +268,7 @@ def clean(self, value):
class EmailField(RegexField):
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
RegexField.__init__(self, email_re, max_length, min_length,
- gettext(u'Enter a valid e-mail address.'), *args, **kwargs)
+ ugettext(u'Enter a valid e-mail address.'), *args, **kwargs)
url_re = re.compile(
r'^https?://' # http:// or https://
@@ -286,7 +286,7 @@ def __init__(self, max_length=None, min_length=None, *args, **kwargs):
class URLField(RegexField):
def __init__(self, max_length=None, min_length=None, verify_exists=False,
validator_user_agent=URL_VALIDATOR_USER_AGENT, *args, **kwargs):
- super(URLField, self).__init__(url_re, max_length, min_length, gettext(u'Enter a valid URL.'), *args, **kwargs)
+ super(URLField, self).__init__(url_re, max_length, min_length, ugettext(u'Enter a valid URL.'), *args, **kwargs)
self.verify_exists = verify_exists
self.user_agent = validator_user_agent
@@ -308,9 +308,9 @@ def clean(self, value):
req = urllib2.Request(value, None, headers)
u = urllib2.urlopen(req)
except ValueError:
- raise ValidationError(gettext(u'Enter a valid URL.'))
+ raise ValidationError(ugettext(u'Enter a valid URL.'))
except: # urllib2.URLError, httplib.InvalidURL, etc.
- raise ValidationError(gettext(u'This URL appears to be a broken link.'))
+ raise ValidationError(ugettext(u'This URL appears to be a broken link.'))
return value
class BooleanField(Field):
@@ -361,7 +361,7 @@ def clean(self, value):
return value
valid_values = set([str(k) for k, v in self.choices])
if value not in valid_values:
- raise ValidationError(gettext(u'Select a valid choice. That choice is not one of the available choices.'))
+ raise ValidationError(ugettext(u'Select a valid choice. That choice is not one of the available choices.'))
return value
class MultipleChoiceField(ChoiceField):
@@ -373,11 +373,11 @@ def clean(self, value):
Validates that the input is a list or tuple.
"""
if self.required and not value:
- raise ValidationError(gettext(u'This field is required.'))
+ raise ValidationError(ugettext(u'This field is required.'))
elif not self.required and not value:
return []
if not isinstance(value, (list, tuple)):
- raise ValidationError(gettext(u'Enter a list of values.'))
+ raise ValidationError(ugettext(u'Enter a list of values.'))
new_value = []
for val in value:
val = smart_unicode(val)
@@ -386,7 +386,7 @@ def clean(self, value):
valid_values = set([smart_unicode(k) for k, v in self.choices])
for val in new_value:
if val not in valid_values:
- raise ValidationError(gettext(u'Select a valid choice. %s is not one of the available choices.') % val)
+ raise ValidationError(ugettext(u'Select a valid choice. %s is not one of the available choices.') % val)
return new_value
class ComboField(Field):
@@ -449,18 +449,18 @@ def clean(self, value):
clean_data = []
errors = ErrorList()
if self.required and not value:
- raise ValidationError(gettext(u'This field is required.'))
+ raise ValidationError(ugettext(u'This field is required.'))
elif not self.required and not value:
return self.compress([])
if not isinstance(value, (list, tuple)):
- raise ValidationError(gettext(u'Enter a list of values.'))
+ raise ValidationError(ugettext(u'Enter a list of values.'))
for i, field in enumerate(self.fields):
try:
field_value = value[i]
except KeyError:
field_value = None
if self.required and field_value in EMPTY_VALUES:
- raise ValidationError(gettext(u'This field is required.'))
+ raise ValidationError(ugettext(u'This field is required.'))
try:
clean_data.append(field.clean(field_value))
except ValidationError, e:
Oops, something went wrong.

0 comments on commit 0da72ff

Please sign in to comment.