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 bags validators telegram, cover_letter #258

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 6 additions & 1 deletion backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
MIN_LEN_TELEGRAM = 5
MAX_LEN_TELEGRAM = 32
TELEGRAM_ERROR_MESSAGE = (
f'Ник в Telegram должен начинаться с @ и содержать только буквы, цифры и знаки подчеркивания. '
f'Ник в Telegram должен начинаться с @ и содержать только латинские буквы, цифры и знаки подчеркивания. '
f'Длина поля от {MIN_LEN_TELEGRAM} до {MAX_LEN_TELEGRAM} символов.'
)

Expand All @@ -326,3 +326,8 @@
MESSAGE_ABOUT_US_REGEX_VALID = """Допускаются цифры, буквы, пробелы и спецсимовлы: %%!#$&*'+/=?^_;():@,.<>`{|}[]~-«»"""

MAX_LEN_PHOTOS = 10
MIN_LEN_COVER_LETTER = 10
MAX_LEN_COVER_LETTER = 530
MESSAGE_COVER_LETTER_VALID = (
f'Длина поля от {MIN_LEN_COVER_LETTER} до {MAX_LEN_COVER_LETTER} символов'
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.6 on 2023-11-30 22:27

import datetime
import django.core.validators
from django.db import migrations, models
import projects.validators


class Migration(migrations.Migration):

dependencies = [
('projects', '0002_alter_project_organization_and_more'),
]

operations = [
migrations.AlterField(
model_name='projectincomes',
name='cover_letter',
field=models.TextField(blank=True, null=True, validators=[projects.validators.validate_text_cover_letter], verbose_name='Сопроводительное письмо'),
),
migrations.AlterField(
model_name='volunteer',
name='date_of_birth',
field=models.DateField(validators=[django.core.validators.MinValueValidator(limit_value=datetime.date(1900, 1, 1)), django.core.validators.MaxValueValidator(limit_value=datetime.date(2023, 11, 30))], verbose_name='Дата рождения'),
),
]
3 changes: 2 additions & 1 deletion backend/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
validate_ogrn,
validate_phone_number,
validate_telegram,
validate_text_cover_letter,
validate_text_field,
validate_title,
)
Expand Down Expand Up @@ -553,7 +554,7 @@ class ProjectIncomes(models.Model):
verbose_name='Сопроводительное письмо',
blank=True,
null=True,
validators=[validate_text_field],
validators=[validate_text_cover_letter],
)
created_at = models.DateTimeField(
auto_now_add=True,
Expand Down
28 changes: 26 additions & 2 deletions backend/projects/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ def validate_telegram(value):
Возвращает:
None
"""

regex_validator = RegexValidator(
regex=r'^@[\w]+$',
regex=r'^@[A-Za-z\d_]+$',
# regex=r'^@[\w]+$',
message=settings.TELEGRAM_ERROR_MESSAGE,
)
min_length_validator = MinLengthValidator(
Expand Down Expand Up @@ -207,7 +209,8 @@ def validate_text_field(value):
Валидирует длину и символы в информации об организации.
"""
regex_validator = RegexValidator(
regex=r"(^[%!#$&*'+/=?^_;():@,.<>`{|}~-«»0-9A-ZА-ЯЁ\s]+)\Z",
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 All @@ -225,6 +228,26 @@ def validate_text_field(value):
regex_validator(value)


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


def validate_address(value):
"""
Валидация адреса.
Expand All @@ -246,6 +269,7 @@ def validate_address(value):
message='Недопустимые символы в адресе. Разрешены латинские '
'и кириллические буквы, цифры, пробел, запятая, точка и тире.',
)

min_length_validator(value)
max_length_validator(value)
regex_validator(value)
Loading