diff --git a/backend/backend/settings.py b/backend/backend/settings.py index eddbd9e..bc91b49 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -323,6 +323,11 @@ 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 +MAX_LEN_COVER_LETTER = 530 +MESSAGE_COVER_LETTER_VALID = ( + f'Длина поля от {MIN_LEN_COVER_LETTER} до {MAX_LEN_COVER_LETTER} символов' +) diff --git a/backend/projects/migrations/0003_alter_address_address_line_and_more.py b/backend/projects/migrations/0003_alter_address_address_line_and_more.py new file mode 100644 index 0000000..921e928 --- /dev/null +++ b/backend/projects/migrations/0003_alter_address_address_line_and_more.py @@ -0,0 +1,31 @@ +# Generated by Django 4.2.6 on 2023-11-30 23:44 + +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='address', + name='address_line', + field=models.CharField(max_length=100, validators=[projects.validators.validate_address], verbose_name='Адрес в одну строчку'), + ), + 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='Дата рождения'), + ), + ] diff --git a/backend/projects/models.py b/backend/projects/models.py index 3375ac1..8f8ce7e 100644 --- a/backend/projects/models.py +++ b/backend/projects/models.py @@ -16,6 +16,7 @@ validate_ogrn, validate_phone_number, validate_telegram, + validate_text_cover_letter, validate_text_field, validate_title, ) @@ -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, diff --git a/backend/projects/validators.py b/backend/projects/validators.py index e35fbbb..23ddf5a 100644 --- a/backend/projects/validators.py +++ b/backend/projects/validators.py @@ -11,7 +11,8 @@ 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): @@ -127,7 +128,8 @@ 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, @@ -207,7 +209,8 @@ def validate_text_field(value): Валидирует длину и символы в информации об организации. """ regex_validator = RegexValidator( - regex=r"(^[%!#$&*'+/=?^_;():@,.<>`{|}~-«»0-9A-ZА-ЯЁ\s]+)\Z", + # regex=r"(^[%!#$&*'+/=?^_;():@,.<>`{|}~-«»0-9A-ZА-ЯЁ\s]+)\Z", + regex=r'^[A-Za-zА-Яа-я0-9 №«»\\!"#$%&\'()*+,-./:;<=>?@\[\]^_`{|}~]+$', message=settings.MESSAGE_ABOUT_US_REGEX_VALID, flags=re.I, ) @@ -249,3 +252,27 @@ def validate_address(value): min_length_validator(value) max_length_validator(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, + ) + + min_length_validator(value) + max_length_validator(value) + regex_validator(value)