Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix validate telegramm, phone, add letter Ёё #262

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
MAX_LEN_SLUG = 50
LEN_OGRN = 13
MESSAGE_PHONE_REGEX = (
f'Номер должен начинаться с +7 и содержать {LEN_PHONE} символов.'
f'Номер должен начинаться с +7, и содержать {LEN_PHONE} символов. Вторая цифра в номере не может быть 0'
)
MESSAGE_EMAIL_VALID = (
f'Длина поля от {MIN_LENGTH_EMAIL} до {MAX_LENGTH_EMAIL} символов'
Expand Down Expand Up @@ -323,7 +323,7 @@
MESSAGE_ABOUT_US_VALID = (
f'Длина поля от {MIN_LEN_ABOUT_US} до {MAX_LEN_ABOUT_US} символов'
)
MESSAGE_ABOUT_US_REGEX_VALID = """Допускаются цифры, буквы, пробелы и спецсимволы: %% №\!#$&*'+/=?^_;():@,.<>`{|}[]~-«»"""
MESSAGE_ABOUT_US_REGEX_VALID = """Допускаются цифры, буквы, пробелы и спецсимволы: %% №\\!#$&*'+/=?^_;():@,.<>`{|}[]~-«»"""

MAX_LEN_PHOTOS = 10
MIN_LEN_COVER_LETTER = 10
Expand Down
16 changes: 9 additions & 7 deletions backend/projects/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
ERROR_MESSAGE_REGEX = 'Недопустимые символы. Разрешены латинские '
'и кириллические буквы, цифры и спецсимволы.',
# REGEX_PATTERN = r'^[A-Za-zА-Яа-я0-9 !"#$%&\'()*+,\-./:;<=>?@\[\]^_`{|}~]+$'
REGEX_PATTERN = r'^[A-Za-zА-Яа-я0-9 №«»\\!"#$%&\'()*+,-./:;<=>?@\[\]^_`{|}~]+$'
REGEX_PATTERN = r'^[A-Za-zА-Яа-яЁё0-9 №«»\\!"#$%&\'()*+,-./:;<=>?@\[\]^_`{|}~]+$'


def validate_ogrn(value):
Expand Down Expand Up @@ -52,7 +52,8 @@ def validate_phone_number(value):
None
"""
regex_validator = RegexValidator(
regex=r'^\+7\d{10}$',
# regex=r'^\+7\d{10}$',
regex=r'^\+7[1-9]\d{9}$',
message=settings.MESSAGE_PHONE_REGEX,
)
# phone_max_length = MaxLengthValidator(
Expand Down Expand Up @@ -83,7 +84,8 @@ def validate_telegram(value):
None
"""
regex_validator = RegexValidator(
regex=r'^@[\w]+$',
# regex=r'^@[\w]+$',
regex=r'^@[A-Za-z0-9_]*[A-Za-z0-9][A-Za-z0-9_]*$',
message=settings.TELEGRAM_ERROR_MESSAGE,
)
min_length_validator = MinLengthValidator(
Expand Down Expand Up @@ -129,7 +131,7 @@ def validate_name(value):
MIN_LEN = settings.MIN_LEN_NAME_PROJECT
MAX_LEN = settings.MAX_LEN_NAME_PROJECT
# NAME_REGEX = r'^[A-Za-zА-Яа-я0-9 !"#$%&\'()*+,-./:;<=>?@\[\]^_`{|}~]+$'
NAME_REGEX = r'^[A-Za-zА-Яа-я0-9 №«»\\!"#$%&\'()*+,-./:;<=>?@\[\]^_`{|}~]+$'
NAME_REGEX = r'^[A-Za-zА-Яа-яЁё0-9 №«»\\!"#$%&\'()*+,-./:;<=>?@\[\]^_`{|}~]+$'

min_length_validator = MinLengthValidator(
MIN_LEN,
Expand Down Expand Up @@ -210,7 +212,7 @@ def validate_text_field(value):
"""
regex_validator = RegexValidator(
# regex=r"(^[%!#$&*'+/=?^_;():@,.<>`{|}~-«»0-9A-ZА-ЯЁ\s]+)\Z",
regex=r'^[A-Za-zА-Яа-я0-9 №«»\\!"#$%&\'()*+,-./:;<=>?@\[\]^_`{|}~]+$',
regex=r'^[A-Za-zА-Яа-яЁё0-9 №«»\\!"#$%&\'()*+,-./:;<=>?@\[\]^_`{|}~]+$',
message=settings.MESSAGE_ABOUT_US_REGEX_VALID,
flags=re.I,
)
Expand All @@ -234,7 +236,7 @@ def validate_address(value):
"""
MIN_LEN = 2
MAX_LEN = 100
NAME_REGEX = r'^[A-Za-zА-Яа-я0-9 ,-.]+$'
NAME_REGEX = r'^[A-Za-zА-Яа-яЁё0-9 ,-.]+$'

min_length_validator = MinLengthValidator(
MIN_LEN,
Expand All @@ -259,7 +261,7 @@ def validate_text_cover_letter(value):
Валидирует длину и символы в информации об организации.
"""
regex_validator = RegexValidator(
regex=r'^[A-Za-zА-Яа-я0-9 №«»\\!"#$%&\'()*+,-./:;<=>?@\[\]^_`{|}~]+$',
regex=r'^[A-Za-zА-Яа-яЁё0-9 №«»\\!"#$%&\'()*+,-./:;<=>?@\[\]^_`{|}~]+$',
# regex=r"(^[%!#$&*'+/=?^_;():@,.<>`{|}~-«»0-9A-ZА-ЯЁ\s]+)\Z",
message=settings.MESSAGE_ABOUT_US_REGEX_VALID,
flags=re.I,
Expand Down