Skip to content

Commit

Permalink
refactor: Add id and is_favorite
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis-Shtanskiy committed Jan 6, 2025
1 parent 7b5b398 commit 0c0efd1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/backend/api/v1/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ class Meta(BaseParticipationRequestSerializer.Meta):
"cover_letter",
"is_favorite_profile",
)
read_only_field = ("request_participants",)
read_only_fields = ("request_participants",)

def to_representation(self, instance):
rep = super().to_representation(instance)
Expand All @@ -587,16 +587,17 @@ def to_representation(self, instance):
)
return rep

def get_is_favorite_profile(self, profile) -> bool:
def get_is_favorite_profile(self, obj) -> bool:
"""
Метод возвращает True если Владелец добавил участника в избранное.
В противном случе возвращает False.
"""
user = self.context.get("request", None).user
return (
user.is_authenticated
and profile.favorited_by.filter(id=user.pk).exists()
)
user = self.context.get("request").user
if user.is_authenticated:
return obj.request_participants.favorited_by.filter(
id=user.pk
).exists()
return False

def get_request_status(self, obj) -> str:
"""Метод получения статуса запроса."""
Expand Down
6 changes: 4 additions & 2 deletions src/backend/apps/profile/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
MIN_LENGTH_NAME = 2
MIN_LENGTH_NAME_MESSAGE = "Должно быть минимум символов"
MIN_LENGTH_ABOUT = 20
REGEX_PROFILE_NAME = r"^[a-zA-Zа-яА-Я -]+$"
REGEX_PROFILE_NAME = r"^[a-zA-Zа-яА-ЯёЁ-]+$"
REGEX_PROFILE_NAME_MESSAGE = "Введите кириллицу или латиницу"
REGEX_PROFILE_ABOUT = r"(^[\Wa-zа-яё0-9\s]+)\Z"
REGEX_PROFILE_ABOUT = (
r"^[\wа-яА-ЯёЁ0-9\s<>,.?!'\"/\-+:;@#\$%\^&\*\(\)\[\]\{\}]*$"
)
REGEX_PROFILE_ABOUT_MESSAGE = "Введите кириллицу или латиницу"
MAX_SPECIALISTS = 2
MAX_BIRTHDAY_MESSAGE = "Дата не может быть в будущем."
Expand Down

0 comments on commit 0c0efd1

Please sign in to comment.