Skip to content

Commit

Permalink
Merge pull request #259 from volunteers-for-city-projects/fix-bags-te…
Browse files Browse the repository at this point in the history
…legram-letter

fix bag validator telegram and cover-letter
  • Loading branch information
1yunker authored Dec 1, 2023
2 parents 18e2877 + eb75529 commit 2523d14
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
7 changes: 6 additions & 1 deletion backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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} символов'
)
Original file line number Diff line number Diff line change
@@ -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='Дата рождения'),
),
]
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
33 changes: 30 additions & 3 deletions backend/projects/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
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"(^[%!#$&*'+/=?^_;():@,.<>`{|}~-«»0-9A-ZА-ЯЁ\s]+)\Z",
regex=r'^[A-Za-zА-Яа-я0-9 №«»\\!"#$%&\'()*+,-./:;<=>?@\[\]^_`{|}~]+$',
message=settings.MESSAGE_ABOUT_US_REGEX_VALID,
flags=re.I,
)
Expand Down Expand Up @@ -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)

0 comments on commit 2523d14

Please sign in to comment.