Django

Code

Changeset 1330

Show
Ignore:
Timestamp:
11/21/05 05:10:19 (3 years ago)
Author:
hugo
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/validators.py

    r1328 r1330  
    2828from django.conf.settings import JING_PATH 
    2929from django.utils.translation import gettext_lazy, ngettext 
    30 from django.utils.functional import Promise 
     30from django.utils.functional import Promise, lazy 
     31 
     32lazy_inter = lazy(lambda a,b: str(a) % b, str) 
    3133 
    3234class ValidationError(Exception): 
     
    234236    def __init__(self, other_field_name, error_message=None): 
    235237        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) 
    237239        self.always_test = True 
    238240 
     
    280282        self.other_field = other_field 
    281283        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}) 
    284286        self.always_test = True 
    285287 
     
    292294        self.other_field = other_field 
    293295        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}) 
    296298        self.always_test = True 
    297299 
     
    360362    def __init__(self, min_size=None, max_size=None, min_error_message=None, max_error_message=None): 
    361363        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) 
    364366 
    365367    def __call__(self, field_data, all_data):