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
This commit is contained in:
Georg Bauer 2005-11-21 11:10:19 +00:00
parent 7b201f6e52
commit a87d43f809
1 changed files with 10 additions and 8 deletions

View File

@ -27,7 +27,9 @@ url_re = re.compile(r'^http://\S+$')
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: