Loading django/core/formfields.py +13 −11 Original line number Diff line number Diff line Loading @@ -2,6 +2,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 from django.utils.translation import gettext_lazy, ngettext FORM_FIELD_ID_PREFIX = 'id_' Loading @@ -23,7 +24,7 @@ class Manipulator: for field in self.fields: if field.field_name == field_name: return field raise KeyError, "Field %s not found" % field_name raise KeyError, "Field %s not found\n%s" % (field_name, repr(self.fields)) def __delitem__(self, field_name): "Deletes the field with the given field name; raises KeyError on failure" Loading Loading @@ -55,7 +56,7 @@ class Manipulator: errors = {} for field in self.fields: if field.is_required and not new_data.get(field.field_name, False): errors.setdefault(field.field_name, []).append('This field is required.') errors.setdefault(field.field_name, []).append(gettext_lazy('This field is required.')) continue try: validator_list = field.validator_list Loading Loading @@ -237,11 +238,12 @@ class TextField(FormField): def isValidLength(self, data, form): 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 raise validators.ValidationError, ngettext("Ensure your text is less than %s character.", "Ensure your text is less than %s characters.", self.maxlength) % self.maxlength def hasNoNewlines(self, data, form): if data and '\n' in data: raise validators.ValidationError, "Line breaks are not allowed here." raise validators.ValidationError, _("Line breaks are not allowed here.") def render(self, data): if data is None: Loading Loading @@ -334,7 +336,7 @@ class SelectField(FormField): str_data = str(data) str_choices = [str(item[0]) for item in self.choices] if str_data not in str_choices: raise validators.ValidationError, "Select a valid choice; '%s' is not in %s." % (str_data, str_choices) raise validators.ValidationError, _("Select a valid choice; '%(data)s' is not in %(choices)s.") % {'data': str_data, 'choices': str_choices} class NullSelectField(SelectField): "This SelectField converts blank fields to None" Loading Loading @@ -403,7 +405,7 @@ class RadioSelectField(FormField): str_data = str(data) str_choices = [str(item[0]) for item in self.choices] if str_data not in str_choices: raise validators.ValidationError, "Select a valid choice; '%s' is not in %s." % (str_data, str_choices) raise validators.ValidationError, _("Select a valid choice; '%(data)s' is not in %(choices)s.") % {'data':str_data, 'choices':str_choices} class NullBooleanField(SelectField): "This SelectField provides 'Yes', 'No' and 'Unknown', mapping results to True, False or None" Loading Loading @@ -441,7 +443,7 @@ class SelectMultipleField(SelectField): str_choices = [str(item[0]) for item in self.choices] for val in map(str, field_data): if val not in str_choices: raise validators.ValidationError, "Select a valid choice; '%s' is not in %s." % (val, str_choices) raise validators.ValidationError, _("Select a valid choice; '%(data)s' is not in %(choices)s.") % {'data':val, 'choices':str_choices} def html2python(data): if data is None: Loading Loading @@ -497,7 +499,7 @@ class FileUploadField(FormField): def isNonEmptyFile(self, field_data, all_data): if not field_data['content']: raise validators.CriticalValidationError, "The submitted file is empty." raise validators.CriticalValidationError, _("The submitted file is empty.") def render(self, data): return '<input type="file" id="%s" class="v%s" name="%s" />' % \ Loading Loading @@ -549,7 +551,7 @@ class SmallIntegerField(IntegerField): def isSmallInteger(self, field_data, all_data): if not -32768 <= int(field_data) <= 32767: raise validators.CriticalValidationError, "Enter a whole number between -32,768 and 32,767." raise validators.CriticalValidationError, _("Enter a whole number between -32,768 and 32,767.") class PositiveIntegerField(IntegerField): def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=[]): Loading @@ -558,7 +560,7 @@ class PositiveIntegerField(IntegerField): def isPositive(self, field_data, all_data): if int(field_data) < 0: raise validators.CriticalValidationError, "Enter a positive number." raise validators.CriticalValidationError, _("Enter a positive number.") class PositiveSmallIntegerField(IntegerField): def __init__(self, field_name, length=5, maxlength=None, is_required=False, validator_list=[]): Loading @@ -567,7 +569,7 @@ class PositiveSmallIntegerField(IntegerField): def isPositiveSmall(self, field_data, all_data): if not 0 <= int(field_data) <= 32767: raise validators.CriticalValidationError, "Enter a whole number between 0 and 32,767." raise validators.CriticalValidationError, _("Enter a whole number between 0 and 32,767.") class FloatField(TextField): def __init__(self, field_name, max_digits, decimal_places, is_required=False, validator_list=[]): Loading Loading
django/core/formfields.py +13 −11 Original line number Diff line number Diff line Loading @@ -2,6 +2,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 from django.utils.translation import gettext_lazy, ngettext FORM_FIELD_ID_PREFIX = 'id_' Loading @@ -23,7 +24,7 @@ class Manipulator: for field in self.fields: if field.field_name == field_name: return field raise KeyError, "Field %s not found" % field_name raise KeyError, "Field %s not found\n%s" % (field_name, repr(self.fields)) def __delitem__(self, field_name): "Deletes the field with the given field name; raises KeyError on failure" Loading Loading @@ -55,7 +56,7 @@ class Manipulator: errors = {} for field in self.fields: if field.is_required and not new_data.get(field.field_name, False): errors.setdefault(field.field_name, []).append('This field is required.') errors.setdefault(field.field_name, []).append(gettext_lazy('This field is required.')) continue try: validator_list = field.validator_list Loading Loading @@ -237,11 +238,12 @@ class TextField(FormField): def isValidLength(self, data, form): 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 raise validators.ValidationError, ngettext("Ensure your text is less than %s character.", "Ensure your text is less than %s characters.", self.maxlength) % self.maxlength def hasNoNewlines(self, data, form): if data and '\n' in data: raise validators.ValidationError, "Line breaks are not allowed here." raise validators.ValidationError, _("Line breaks are not allowed here.") def render(self, data): if data is None: Loading Loading @@ -334,7 +336,7 @@ class SelectField(FormField): str_data = str(data) str_choices = [str(item[0]) for item in self.choices] if str_data not in str_choices: raise validators.ValidationError, "Select a valid choice; '%s' is not in %s." % (str_data, str_choices) raise validators.ValidationError, _("Select a valid choice; '%(data)s' is not in %(choices)s.") % {'data': str_data, 'choices': str_choices} class NullSelectField(SelectField): "This SelectField converts blank fields to None" Loading Loading @@ -403,7 +405,7 @@ class RadioSelectField(FormField): str_data = str(data) str_choices = [str(item[0]) for item in self.choices] if str_data not in str_choices: raise validators.ValidationError, "Select a valid choice; '%s' is not in %s." % (str_data, str_choices) raise validators.ValidationError, _("Select a valid choice; '%(data)s' is not in %(choices)s.") % {'data':str_data, 'choices':str_choices} class NullBooleanField(SelectField): "This SelectField provides 'Yes', 'No' and 'Unknown', mapping results to True, False or None" Loading Loading @@ -441,7 +443,7 @@ class SelectMultipleField(SelectField): str_choices = [str(item[0]) for item in self.choices] for val in map(str, field_data): if val not in str_choices: raise validators.ValidationError, "Select a valid choice; '%s' is not in %s." % (val, str_choices) raise validators.ValidationError, _("Select a valid choice; '%(data)s' is not in %(choices)s.") % {'data':val, 'choices':str_choices} def html2python(data): if data is None: Loading Loading @@ -497,7 +499,7 @@ class FileUploadField(FormField): def isNonEmptyFile(self, field_data, all_data): if not field_data['content']: raise validators.CriticalValidationError, "The submitted file is empty." raise validators.CriticalValidationError, _("The submitted file is empty.") def render(self, data): return '<input type="file" id="%s" class="v%s" name="%s" />' % \ Loading Loading @@ -549,7 +551,7 @@ class SmallIntegerField(IntegerField): def isSmallInteger(self, field_data, all_data): if not -32768 <= int(field_data) <= 32767: raise validators.CriticalValidationError, "Enter a whole number between -32,768 and 32,767." raise validators.CriticalValidationError, _("Enter a whole number between -32,768 and 32,767.") class PositiveIntegerField(IntegerField): def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=[]): Loading @@ -558,7 +560,7 @@ class PositiveIntegerField(IntegerField): def isPositive(self, field_data, all_data): if int(field_data) < 0: raise validators.CriticalValidationError, "Enter a positive number." raise validators.CriticalValidationError, _("Enter a positive number.") class PositiveSmallIntegerField(IntegerField): def __init__(self, field_name, length=5, maxlength=None, is_required=False, validator_list=[]): Loading @@ -567,7 +569,7 @@ class PositiveSmallIntegerField(IntegerField): def isPositiveSmall(self, field_data, all_data): if not 0 <= int(field_data) <= 32767: raise validators.CriticalValidationError, "Enter a whole number between 0 and 32,767." raise validators.CriticalValidationError, _("Enter a whole number between 0 and 32,767.") class FloatField(TextField): def __init__(self, field_name, max_digits, decimal_places, is_required=False, validator_list=[]): Loading