Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

from django.core.validators import BaseValidator 

from django.utils.deconstruct import deconstructible 

from django.utils.translation import ungettext_lazy 

 

 

@deconstructible 

class ByteLengthValidator(BaseValidator): 

    compare = lambda self, a, b: a > b 

    clean = lambda self, x: len(x.encode('utf8')) 

    message = ungettext_lazy( 

        ('Ensure this value has at most %(limit_value)d byte ' 

         '(it has %(show_value)d).'), 

        ('Ensure this value has at most %(limit_value)d bytes ' 

         '(it has %(show_value)d).'), 

        'limit_value') 

    code = 'max_length'