initial commit
This commit is contained in:
3
core/apps/companies/validators/__init__.py
Normal file
3
core/apps/companies/validators/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .accounts import * # noqa
|
||||
from .companies import * # noqa
|
||||
from .folders import * # noqa
|
||||
10
core/apps/companies/validators/accounts.py
Normal file
10
core/apps/companies/validators/accounts.py
Normal file
@@ -0,0 +1,10 @@
|
||||
# from django.core.exceptions import ValidationError
|
||||
from django_core.models.base import AbstractBaseModel # type: ignore
|
||||
|
||||
|
||||
class CompanyAccountValidator:
|
||||
def __init__(self, instance: AbstractBaseModel):
|
||||
self.instance = instance
|
||||
|
||||
def __call__(self):
|
||||
return True
|
||||
62
core/apps/companies/validators/companies.py
Normal file
62
core/apps/companies/validators/companies.py
Normal file
@@ -0,0 +1,62 @@
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import RegexValidator
|
||||
from django_core.models.base import AbstractBaseModel # type: ignore
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
phone_validator = RegexValidator(
|
||||
regex=r'^\+?[1-9]\d{1,14}$',
|
||||
message=_(
|
||||
"Enter a valid international phone number "
|
||||
"(E.164 format, e.g., +14155552671)."
|
||||
)
|
||||
)
|
||||
|
||||
iin_validator = RegexValidator(
|
||||
regex=r'^\d{14}$',
|
||||
message=_("IIN code must be exactly 14 digits.")
|
||||
)
|
||||
|
||||
pinfl_validator = RegexValidator(
|
||||
regex=r'^\d{14}$',
|
||||
message=_("PINFL code must be exactly 14 digits.")
|
||||
)
|
||||
|
||||
iik_validator = RegexValidator(
|
||||
regex=r'^[A-Z0-9]{10,30}$',
|
||||
message=_(
|
||||
"IIK code must be alphanumeric and " \
|
||||
"between 10 and 30 characters."
|
||||
),
|
||||
)
|
||||
|
||||
name_validator = RegexValidator(
|
||||
regex=r'^[A-Za-z0-9\s\.\-\,\&]+$',
|
||||
message=_("Company name contains invalid characters.")
|
||||
)
|
||||
|
||||
|
||||
class CompanyValidator:
|
||||
def __init__(self, instance: AbstractBaseModel):
|
||||
self.instance = instance
|
||||
|
||||
def __call__(self):
|
||||
if (
|
||||
self.instance.iin_code is None # type: ignore
|
||||
and self.instance.pinfl_code is None # type: ignore
|
||||
):
|
||||
|
||||
raise ValidationError(_(
|
||||
"Either IIN code or PINFL " \
|
||||
"code must be provided."
|
||||
))
|
||||
|
||||
if (
|
||||
self.instance.iin_code is not None # type: ignore
|
||||
and self.instance.pinfl_code is not None # type: ignore
|
||||
):
|
||||
raise ValidationError(_(
|
||||
"One of IIN code and PINFL "
|
||||
"code must be None"
|
||||
))
|
||||
10
core/apps/companies/validators/folders.py
Normal file
10
core/apps/companies/validators/folders.py
Normal file
@@ -0,0 +1,10 @@
|
||||
# from django.core.exceptions import ValidationError
|
||||
from django_core.models.base import AbstractBaseModel # type: ignore
|
||||
|
||||
|
||||
class CompanyFolderValidator:
|
||||
def __init__(self, instance: AbstractBaseModel):
|
||||
self.instance = instance
|
||||
|
||||
def __call__(self):
|
||||
return
|
||||
Reference in New Issue
Block a user