-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidators.py
More file actions
32 lines (27 loc) · 1.02 KB
/
validators.py
File metadata and controls
32 lines (27 loc) · 1.02 KB
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
from django.core import validators
from django.contrib.auth.validators import UnicodeUsernameValidator
from django.utils.translation import gettext_lazy as _
from django.conf import settings
from django.utils.deconstruct import deconstructible
from django.core.exceptions import ValidationError
@deconstructible
class UsernameValidator(UnicodeUsernameValidator):
regex = settings.USERNAME_REGEX
message = _(
f"Enter a valid username. This value may match the regex {regex}."
)
def __call__(self, value):
if value in settings.RESERVED_USERNAMES:
raise ValidationError(
_("The current username is on the blocklist."),
code=self.code,
params={"value": value}
)
super().__call__(value)
@deconstructible
class OrganizationNameValidator(validators.RegexValidator):
regex = settings.ORGANIZATION_NAME_REGEX
message = _(
f"Enter a valid organization name. This value may match the regex {regex}."
)
flags = 0