Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
authored November 21, 2005

Showing 1 changed file with 10 additions and 8 deletions. Show diff stats Hide diff stats

  1. 18  django/core/validators.py
18  django/core/validators.py
@@ -27,7 +27,9 @@
27 27
 
28 28
 from django.conf.settings import JING_PATH
29 29
 from django.utils.translation import gettext_lazy, ngettext
30  
-from django.utils.functional import Promise
  30
+from django.utils.functional import Promise, lazy
  31
+
  32
+lazy_inter = lazy(lambda a,b: str(a) % b, str)
31 33
 
32 34
 class ValidationError(Exception):
33 35
     def __init__(self, message):
@@ -233,7 +235,7 @@ def hasNoProfanities(field_data, all_data):
233 235
 class AlwaysMatchesOtherField:
234 236
     def __init__(self, other_field_name, error_message=None):
235 237
         self.other = other_field_name
236  
-        self.error_message = error_message or gettext_lazy("This field must match the '%s' field.") % self.other
  238
+        self.error_message = error_message or lazy_inter(gettext_lazy("This field must match the '%s' field."), self.other)
237 239
         self.always_test = True
238 240
 
239 241
     def __call__(self, field_data, all_data):
@@ -279,8 +281,8 @@ class RequiredIfOtherFieldEquals:
279 281
     def __init__(self, other_field, other_value, error_message=None):
280 282
         self.other_field = other_field
281 283
         self.other_value = other_value
282  
-        self.error_message = error_message or gettext_lazy("This field must be given if %(field)s is %(value)s") % {
283  
-            'field': other_field, 'value': other_value}
  284
+        self.error_message = error_message or lazy_inter(gettext_lazy("This field must be given if %(field)s is %(value)s"), {
  285
+            'field': other_field, 'value': other_value})
284 286
         self.always_test = True
285 287
 
286 288
     def __call__(self, field_data, all_data):
@@ -291,8 +293,8 @@ class RequiredIfOtherFieldDoesNotEqual:
291 293
     def __init__(self, other_field, other_value, error_message=None):
292 294
         self.other_field = other_field
293 295
         self.other_value = other_value
294  
-        self.error_message = error_message or gettext_lazy("This field must be given if %(field)s is not %(value)s") % {
295  
-            'field': other_field, 'value': other_value}
  296
+        self.error_message = error_message or lazy_inter(gettext_lazy("This field must be given if %(field)s is not %(value)s"), {
  297
+            'field': other_field, 'value': other_value})
296 298
         self.always_test = True
297 299
 
298 300
     def __call__(self, field_data, all_data):
@@ -359,8 +361,8 @@ class HasAllowableSize:
359 361
     """
360 362
     def __init__(self, min_size=None, max_size=None, min_error_message=None, max_error_message=None):
361 363
         self.min_size, self.max_size = min_size, max_size
362  
-        self.min_error_message = min_error_message or gettext_lazy("Make sure your uploaded file is at least %s bytes big.") % min_size
363  
-        self.max_error_message = max_error_message or gettext_lazy("Make sure your uploaded file is at most %s bytes big.") % min_size
  364
+        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)
  365
+        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)
364 366
 
365 367
     def __call__(self, field_data, all_data):
366 368
         if self.min_size is not None and len(field_data['content']) < self.min_size:

0 notes on commit a87d43f

Please sign in to comment.
Something went wrong with that request. Please try again.