forked from mongodb/django-mongodb-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidators.py
35 lines (27 loc) · 1.16 KB
/
validators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from django.core.validators import BaseValidator, MaxLengthValidator, MinLengthValidator
from django.utils.deconstruct import deconstructible
from django.utils.translation import ngettext_lazy
class ArrayMaxLengthValidator(MaxLengthValidator):
message = ngettext_lazy(
"List contains %(show_value)d item, it should contain no more than %(limit_value)d.",
"List contains %(show_value)d items, it should contain no more than %(limit_value)d.",
"show_value",
)
class ArrayMinLengthValidator(MinLengthValidator):
message = ngettext_lazy(
"List contains %(show_value)d item, it should contain no fewer than %(limit_value)d.",
"List contains %(show_value)d items, it should contain no fewer than %(limit_value)d.",
"show_value",
)
@deconstructible
class LengthValidator(BaseValidator):
message = ngettext_lazy(
"List contains %(show_value)d item, it should contain %(limit_value)d.",
"List contains %(show_value)d items, it should contain %(limit_value)d.",
"show_value",
)
code = "length"
def compare(self, a, b):
return a != b
def clean(self, x):
return len(x)