Ticket #19034: 19034.diff

File 19034.diff, 1.8 KB (added by claudep, 3 years ago)

Use ungettext for min/max length validators

  • django/core/validators.py

    diff --git a/django/core/validators.py b/django/core/validators.py
    index c7bda68..0a2cc2a 100644
    a b except ImportError: # Python 2 
    77    from urlparse import urlsplit, urlunsplit
    88
    99from django.core.exceptions import ValidationError
    10 from django.utils.translation import ugettext_lazy as _
     10from django.utils.translation import ugettext_lazy as _, ungettext
    1111from django.utils.encoding import force_text
    1212from django.utils.ipv6 import is_valid_ipv6_address
    1313from django.utils import six
    class MinValueValidator(BaseValidator): 
    186186class MinLengthValidator(BaseValidator):
    187187    compare = lambda self, a, b: a < b
    188188    clean = lambda self, x: len(x)
    189     message = _('Ensure this value has at least %(limit_value)d characters (it has %(show_value)d).')
    190189    code = 'min_length'
    191190
     191    def __call__(self, value):
     192        self.message = ungettext(
     193            'Ensure this value has at least %(limit_value)d character (it has %(show_value)d).',
     194            'Ensure this value has at least %(limit_value)d characters (it has %(show_value)d).',
     195            self.limit_value
     196        )
     197        super(MinLengthValidator, self).__call__(value)
     198
    192199
    193200class MaxLengthValidator(BaseValidator):
    194201    compare = lambda self, a, b: a > b
    195202    clean = lambda self, x: len(x)
    196     message = _('Ensure this value has at most %(limit_value)d characters (it has %(show_value)d).')
    197203    code = 'max_length'
     204
     205    def __call__(self, value):
     206        self.message = ungettext(
     207            'Ensure this value has at most %(limit_value)d character (it has %(show_value)d).',
     208            'Ensure this value has at most %(limit_value)d characters (it has %(show_value)d).',
     209            self.limit_value
     210        )
     211        super(MaxLengthValidator, self).__call__(value)
Back to Top