Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed a bug with some validators that used parameterized gettext_lazy…

… strings and forced them to the default language because of the % operator. Now lazy string interpolation is used.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1330 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a87d43f809c7614a749e9ef6af1c45ff4e075c0c 1 parent 7b201f6
Georg Bauer authored
Showing with 10 additions and 8 deletions.
  1. +10 −8 django/core/validators.py
View
18 django/core/validators.py
@@ -27,7 +27,9 @@
from django.conf.settings import JING_PATH
from django.utils.translation import gettext_lazy, ngettext
-from django.utils.functional import Promise
+from django.utils.functional import Promise, lazy
+
+lazy_inter = lazy(lambda a,b: str(a) % b, str)
class ValidationError(Exception):
def __init__(self, message):
@@ -233,7 +235,7 @@ def hasNoProfanities(field_data, all_data):
class AlwaysMatchesOtherField:
def __init__(self, other_field_name, error_message=None):
self.other = other_field_name
- self.error_message = error_message or gettext_lazy("This field must match the '%s' field.") % self.other
+ self.error_message = error_message or lazy_inter(gettext_lazy("This field must match the '%s' field."), self.other)
self.always_test = True
def __call__(self, field_data, all_data):
@@ -279,8 +281,8 @@ class RequiredIfOtherFieldEquals:
def __init__(self, other_field, other_value, error_message=None):
self.other_field = other_field
self.other_value = other_value
- self.error_message = error_message or gettext_lazy("This field must be given if %(field)s is %(value)s") % {
- 'field': other_field, 'value': other_value}
+ self.error_message = error_message or lazy_inter(gettext_lazy("This field must be given if %(field)s is %(value)s"), {
+ 'field': other_field, 'value': other_value})
self.always_test = True
def __call__(self, field_data, all_data):
@@ -291,8 +293,8 @@ class RequiredIfOtherFieldDoesNotEqual:
def __init__(self, other_field, other_value, error_message=None):
self.other_field = other_field
self.other_value = other_value
- self.error_message = error_message or gettext_lazy("This field must be given if %(field)s is not %(value)s") % {
- 'field': other_field, 'value': other_value}
+ self.error_message = error_message or lazy_inter(gettext_lazy("This field must be given if %(field)s is not %(value)s"), {
+ 'field': other_field, 'value': other_value})
self.always_test = True
def __call__(self, field_data, all_data):
@@ -359,8 +361,8 @@ class HasAllowableSize:
"""
def __init__(self, min_size=None, max_size=None, min_error_message=None, max_error_message=None):
self.min_size, self.max_size = min_size, max_size
- self.min_error_message = min_error_message or gettext_lazy("Make sure your uploaded file is at least %s bytes big.") % min_size
- self.max_error_message = max_error_message or gettext_lazy("Make sure your uploaded file is at most %s bytes big.") % min_size
+ self.min_error_message = min_error_message or lazy_inter(gettext_lazy("Make sure your uploaded file is at least %s bytes big."), min_size)
+ self.max_error_message = max_error_message or lazy_inter(gettext_lazy("Make sure your uploaded file is at most %s bytes big."), min_size)
def __call__(self, field_data, all_data):
if self.min_size is not None and len(field_data['content']) < self.min_size:
Please sign in to comment.
Something went wrong with that request. Please try again.