Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

For readability, use _() as an alias to mark translatable strings.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6642 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2184248c056a6d341ad815f1145406eb99ddbf40 1 parent 4e8864a
@malcolmt malcolmt authored
Showing with 36 additions and 34 deletions.
  1. +36 −34 django/newforms/fields.py
View
70 django/newforms/fields.py
@@ -16,7 +16,7 @@
except NameError:
from sets import Set as set
-from django.utils.translation import ugettext_lazy
+from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import StrAndUnicode, smart_unicode
from util import ErrorList, ValidationError
@@ -42,8 +42,8 @@ class Field(object):
widget = TextInput # Default widget to use when rendering this type of Field.
hidden_widget = HiddenInput # Default widget to use when rendering this as "hidden".
default_error_messages = {
- 'required': ugettext_lazy(u'This field is required.'),
- 'invalid': ugettext_lazy(u'Enter a valid value.'),
+ 'required': _(u'This field is required.'),
+ 'invalid': _(u'Enter a valid value.'),
}
# Tracks each time a Field instance is created. Used to retain order.
@@ -87,11 +87,13 @@ def __init__(self, required=True, widget=None, label=None, initial=None,
def _build_error_messages(self, extra_error_messages):
error_messages = {}
+
def get_default_error_messages(klass):
for base_class in klass.__bases__:
get_default_error_messages(base_class)
if hasattr(klass, 'default_error_messages'):
error_messages.update(klass.default_error_messages)
+
get_default_error_messages(self.__class__)
if extra_error_messages:
error_messages.update(extra_error_messages)
@@ -124,8 +126,8 @@ def __deepcopy__(self, memo):
class CharField(Field):
default_error_messages = {
- 'max_length': ugettext_lazy(u'Ensure this value has at most %(max)d characters (it has %(length)d).'),
- 'min_length': ugettext_lazy(u'Ensure this value has at least %(min)d characters (it has %(length)d).'),
+ 'max_length': _(u'Ensure this value has at most %(max)d characters (it has %(length)d).'),
+ 'min_length': _(u'Ensure this value has at least %(min)d characters (it has %(length)d).'),
}
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
@@ -152,9 +154,9 @@ def widget_attrs(self, widget):
class IntegerField(Field):
default_error_messages = {
- 'invalid': ugettext_lazy(u'Enter a whole number.'),
- 'max_value': ugettext_lazy(u'Ensure this value is less than or equal to %s.'),
- 'min_value': ugettext_lazy(u'Ensure this value is greater than or equal to %s.'),
+ 'invalid': _(u'Enter a whole number.'),
+ 'max_value': _(u'Ensure this value is less than or equal to %s.'),
+ 'min_value': _(u'Ensure this value is greater than or equal to %s.'),
}
def __init__(self, max_value=None, min_value=None, *args, **kwargs):
@@ -181,9 +183,9 @@ def clean(self, value):
class FloatField(Field):
default_error_messages = {
- 'invalid': ugettext_lazy(u'Enter a number.'),
- 'max_value': ugettext_lazy(u'Ensure this value is less than or equal to %s.'),
- 'min_value': ugettext_lazy(u'Ensure this value is greater than or equal to %s.'),
+ 'invalid': _(u'Enter a number.'),
+ 'max_value': _(u'Ensure this value is less than or equal to %s.'),
+ 'min_value': _(u'Ensure this value is greater than or equal to %s.'),
}
def __init__(self, max_value=None, min_value=None, *args, **kwargs):
@@ -210,12 +212,12 @@ def clean(self, value):
class DecimalField(Field):
default_error_messages = {
- 'invalid': ugettext_lazy(u'Enter a number.'),
- 'max_value': ugettext_lazy(u'Ensure this value is less than or equal to %s.'),
- 'min_value': ugettext_lazy(u'Ensure this value is greater than or equal to %s.'),
- 'max_digits': ugettext_lazy('Ensure that there are no more than %s digits in total.'),
- 'max_decimal_places': ugettext_lazy('Ensure that there are no more than %s decimal places.'),
- 'max_whole_digits': ugettext_lazy('Ensure that there are no more than %s digits before the decimal point.')
+ 'invalid': _(u'Enter a number.'),
+ 'max_value': _(u'Ensure this value is less than or equal to %s.'),
+ 'min_value': _(u'Ensure this value is greater than or equal to %s.'),
+ 'max_digits': _('Ensure that there are no more than %s digits in total.'),
+ 'max_decimal_places': _('Ensure that there are no more than %s decimal places.'),
+ 'max_whole_digits': _('Ensure that there are no more than %s digits before the decimal point.')
}
def __init__(self, max_value=None, min_value=None, max_digits=None, decimal_places=None, *args, **kwargs):
@@ -263,7 +265,7 @@ def clean(self, value):
class DateField(Field):
default_error_messages = {
- 'invalid': ugettext_lazy(u'Enter a valid date.'),
+ 'invalid': _(u'Enter a valid date.'),
}
def __init__(self, input_formats=None, *args, **kwargs):
@@ -296,7 +298,7 @@ def clean(self, value):
class TimeField(Field):
default_error_messages = {
- 'invalid': ugettext_lazy(u'Enter a valid time.')
+ 'invalid': _(u'Enter a valid time.')
}
def __init__(self, input_formats=None, *args, **kwargs):
@@ -335,7 +337,7 @@ def clean(self, value):
class DateTimeField(Field):
widget = DateTimeInput
default_error_messages = {
- 'invalid': ugettext_lazy(u'Enter a valid date/time.'),
+ 'invalid': _(u'Enter a valid date/time.'),
}
def __init__(self, input_formats=None, *args, **kwargs):
@@ -403,7 +405,7 @@ def clean(self, value):
class EmailField(RegexField):
default_error_messages = {
- 'invalid': ugettext_lazy(u'Enter a valid e-mail address.'),
+ 'invalid': _(u'Enter a valid e-mail address.'),
}
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
@@ -433,9 +435,9 @@ def __unicode__(self):
class FileField(Field):
widget = FileInput
default_error_messages = {
- 'invalid': ugettext_lazy(u"No file was submitted. Check the encoding type on the form."),
- 'missing': ugettext_lazy(u"No file was submitted."),
- 'empty': ugettext_lazy(u"The submitted file is empty."),
+ 'invalid': _(u"No file was submitted. Check the encoding type on the form."),
+ 'missing': _(u"No file was submitted."),
+ 'empty': _(u"The submitted file is empty."),
}
def __init__(self, *args, **kwargs):
@@ -457,7 +459,7 @@ def clean(self, data):
class ImageField(FileField):
default_error_messages = {
- 'invalid_image': ugettext_lazy(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image."),
+ 'invalid_image': _(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image."),
}
def clean(self, data):
@@ -493,8 +495,8 @@ def clean(self, data):
class URLField(RegexField):
default_error_messages = {
- 'invalid': ugettext_lazy(u'Enter a valid URL.'),
- 'invalid_link': ugettext_lazy(u'This URL appears to be a broken link.'),
+ 'invalid': _(u'Enter a valid URL.'),
+ 'invalid_link': _(u'This URL appears to be a broken link.'),
}
def __init__(self, max_length=None, min_length=None, verify_exists=False,
@@ -555,7 +557,7 @@ def clean(self, value):
class ChoiceField(Field):
widget = Select
default_error_messages = {
- 'invalid_choice': ugettext_lazy(u'Select a valid choice. That choice is not one of the available choices.'),
+ 'invalid_choice': _(u'Select a valid choice. That choice is not one of the available choices.'),
}
def __init__(self, choices=(), required=True, widget=None, label=None,
@@ -594,8 +596,8 @@ class MultipleChoiceField(ChoiceField):
hidden_widget = MultipleHiddenInput
widget = SelectMultiple
default_error_messages = {
- 'invalid_choice': ugettext_lazy(u'Select a valid choice. %(value)s is not one of the available choices.'),
- 'invalid_list': ugettext_lazy(u'Enter a list of values.'),
+ 'invalid_choice': _(u'Select a valid choice. %(value)s is not one of the available choices.'),
+ 'invalid_list': _(u'Enter a list of values.'),
}
def clean(self, value):
@@ -657,7 +659,7 @@ class MultiValueField(Field):
You'll probably want to use this with MultiWidget.
"""
default_error_messages = {
- 'invalid': ugettext_lazy(u'Enter a list of values.'),
+ 'invalid': _(u'Enter a list of values.'),
}
def __init__(self, fields=(), *args, **kwargs):
@@ -719,8 +721,8 @@ def compress(self, data_list):
class SplitDateTimeField(MultiValueField):
default_error_messages = {
- 'invalid_date': ugettext_lazy(u'Enter a valid date.'),
- 'invalid_time': ugettext_lazy(u'Enter a valid time.'),
+ 'invalid_date': _(u'Enter a valid date.'),
+ 'invalid_time': _(u'Enter a valid time.'),
}
def __init__(self, *args, **kwargs):
@@ -748,7 +750,7 @@ def compress(self, data_list):
class IPAddressField(RegexField):
default_error_messages = {
- 'invalid': ugettext_lazy(u'Enter a valid IPv4 address.'),
+ 'invalid': _(u'Enter a valid IPv4 address.'),
}
def __init__(self, *args, **kwargs):
Please sign in to comment.
Something went wrong with that request. Please try again.