diff --git a/src/backend/api/v1/projects/serializers.py b/src/backend/api/v1/projects/serializers.py index 4075e12..6b8a1c2 100644 --- a/src/backend/api/v1/projects/serializers.py +++ b/src/backend/api/v1/projects/serializers.py @@ -13,7 +13,7 @@ class DirectionSerializer(serializers.ModelSerializer): - """Сериализатор специалиста.""" + """Сериализатор направления разработки.""" class Meta: model = Direction diff --git a/src/backend/apps/general/constants.py b/src/backend/apps/general/constants.py index dd37333..3d26f8d 100644 --- a/src/backend/apps/general/constants.py +++ b/src/backend/apps/general/constants.py @@ -4,7 +4,7 @@ MIN_LENGTH_SPECIALIZATION_NAME = 2 LENGTH_SPECIALIZATION_NAME_ERROR_TEXT = ( f"Длина поля от {MIN_LENGTH_SPECIALIZATION_NAME} до " - f"{MIN_LENGTH_SPECIALIZATION_NAME} символов." + f"{MAX_LENGTH_SPECIALIZATION_NAME} символов." ) REGEX_SPECIALIZATION_NAME = r"(^[A-Za-zА-Яа-яЁё\s\/]+)\Z" REGEX_SPECIALIZATION_NAME_ERROR_TEXT = ( diff --git a/src/backend/apps/general/migrations/0002_alter_specialist_specialization_and_more.py b/src/backend/apps/general/migrations/0002_alter_specialist_specialization_and_more.py index 10d4255..fbe52f9 100644 --- a/src/backend/apps/general/migrations/0002_alter_specialist_specialization_and_more.py +++ b/src/backend/apps/general/migrations/0002_alter_specialist_specialization_and_more.py @@ -17,7 +17,7 @@ class Migration(migrations.Migration): max_length=100, validators=[ django.core.validators.MinLengthValidator( - limit_value=2, message="Длина поля от 2 до 2 символов." + limit_value=2, message="Длина поля от 2 до 100 символов." ), django.core.validators.RegexValidator( message="Специализация может содержать: кириллические и латинские символы,пробелы и символ /", diff --git a/src/backend/apps/projects/apps.py b/src/backend/apps/projects/apps.py index cbd9abe..2414b56 100644 --- a/src/backend/apps/projects/apps.py +++ b/src/backend/apps/projects/apps.py @@ -4,3 +4,8 @@ class ProjectConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" name = "apps.projects" + + def ready(self): + from . import signals # noqa: F401, + + return super().ready() diff --git a/src/backend/apps/projects/constants.py b/src/backend/apps/projects/constants.py index 686ff2e..abcf978 100644 --- a/src/backend/apps/projects/constants.py +++ b/src/backend/apps/projects/constants.py @@ -20,8 +20,8 @@ MAX_LENGTH_DIRECTION_NAME = 20 MIN_LENGTH_DIRECTION_NAME = 2 LENGTH_DIRECTION_NAME_ERROR_TEXT = ( - f"Длина поля от {MIN_LENGTH_PROJECT_NAME} до {MAX_LENGTH_PROJECT_NAME} " - "символов." + f"Длина поля от {MIN_LENGTH_DIRECTION_NAME} до " + f"{MAX_LENGTH_DIRECTION_NAME} символов." ) REGEX_DIRECTION_NAME = r"(^[A-Za-zА-Яа-яЁё]+)\Z" REGEX_DIRECTION_NAME_ERROR_TEXT = ( @@ -47,5 +47,4 @@ (3, "Черновик"), ) - PROJECTS_PER_PAGE = 10 diff --git a/src/backend/apps/projects/migrations/0003_alter_direction_name_and_more.py b/src/backend/apps/projects/migrations/0003_alter_direction_name_and_more.py new file mode 100644 index 0000000..b3c914f --- /dev/null +++ b/src/backend/apps/projects/migrations/0003_alter_direction_name_and_more.py @@ -0,0 +1,40 @@ +# Generated by Django 5.0.1 on 2024-03-27 19:19 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("general", "0002_alter_specialist_specialization_and_more"), + ("projects", "0002_alter_project_busyness"), + ] + + operations = [ + migrations.AlterField( + model_name="direction", + name="name", + field=models.CharField( + max_length=20, + unique=True, + validators=[ + django.core.validators.MinLengthValidator( + limit_value=2, + message="Длина поля от 2 до 20 символов.", + ), + django.core.validators.RegexValidator( + message="Направление разработки может содержать: кириллические и латинские символы.", + regex="(^[A-Za-zА-Яа-яЁё]+)\\Z", + ), + ], + verbose_name="Название", + ), + ), + migrations.AddConstraint( + model_name="projectspecialist", + constraint=models.UniqueConstraint( + fields=("project", "specialist", "level"), + name="projects_projectspecialist_unique_specialist_per_project", + ), + ), + ] diff --git a/src/backend/apps/projects/models.py b/src/backend/apps/projects/models.py index f59c1d7..a26f29e 100644 --- a/src/backend/apps/projects/models.py +++ b/src/backend/apps/projects/models.py @@ -199,3 +199,9 @@ class Meta: verbose_name = "Специалист проекта" verbose_name_plural = "Специалисты проекта" default_related_name = "project_specialists" + constraints = ( + models.UniqueConstraint( + fields=("project", "specialist", "level"), + name="%(app_label)s_%(class)s_unique_specialist_per_project", + ), + ) diff --git a/src/backend/apps/projects/signals.py b/src/backend/apps/projects/signals.py new file mode 100644 index 0000000..70085ab --- /dev/null +++ b/src/backend/apps/projects/signals.py @@ -0,0 +1,13 @@ +from django.db.models.signals import post_save +from django.dispatch import receiver + +from apps.projects.models import Project + + +@receiver(post_save, sender=Project) +def create_user_profile(sender, instance, created, **kwargs): + """Метод присвоения статуса is_organizer пользователю.""" + + if created and not instance.creator.is_organizer: + instance.creator.is_organizer = True + instance.creator.save()