Skip to content

Commit

Permalink
Merge pull request #395 from Pet-projects-CodePET/refactor/requests_a…
Browse files Browse the repository at this point in the history
…nd_serializers

refactor: Все вернул назад, плюс разрешил теги
  • Loading branch information
Denis-Shtanskiy authored Jan 5, 2025
2 parents 04ae0d3 + 592b067 commit 9635e7f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
16 changes: 16 additions & 0 deletions src/backend/api/v1/profile/constants.py
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
PROFILES_PAGE_SIZE = 7
ALLOWED_TAGS_BY_FRONT = [
"ol",
"ul",
"li",
"em",
"strong",
"u",
"br",
"p",
"span",
# разрешенные теги котоыре не нужно очищать
]
ALLOWED_ATTRIBUTES_BY_FRONT = {
"span": ["class", "style", "contenteditable"],
# разрещенные атрибуты.
}
20 changes: 14 additions & 6 deletions src/backend/api/v1/profile/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# import html
import html
from typing import ClassVar, Optional

import bleach
Expand All @@ -14,6 +14,10 @@
ProfessionSerializer,
SkillSerializer,
)
from api.v1.profile.constants import (
ALLOWED_ATTRIBUTES_BY_FRONT,
ALLOWED_TAGS_BY_FRONT,
)
from apps.general.constants import MAX_SKILLS, MAX_SKILLS_MESSAGE
from apps.general.models import Profession
from apps.profile.constants import MAX_SPECIALISTS, MAX_SPECIALISTS_MESSAGE
Expand Down Expand Up @@ -233,10 +237,10 @@ class Meta(BaseProfileSerializer.Meta):
)
read_only_fields = fields

# def to_representation(self, instance):
# rep = super().to_representation(instance)
# rep["about"] = html.unescape(rep["about"])
# return rep
def to_representation(self, instance):
rep = super().to_representation(instance)
rep["about"] = html.unescape(rep["about"])
return rep


class ProfileMeWriteSerializer(ProfileMeReadSerializer):
Expand Down Expand Up @@ -265,5 +269,9 @@ def validate_about(self, value):
HTML-тегов и атрибутов.
"""

safe_about = bleach.clean(value)
safe_about = bleach.clean(
value,
tags=ALLOWED_TAGS_BY_FRONT,
attributes=ALLOWED_ATTRIBUTES_BY_FRONT,
)
return safe_about
8 changes: 4 additions & 4 deletions src/backend/api/v1/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,10 @@ class Meta(BaseParticipationRequestSerializer.Meta):
)
read_only_field = ("request_participants",)

# def to_representation(self, instance):
# rep = super().to_representation(instance)
# rep["cover_letter"] = instance.cover_letter
# return rep
def to_representation(self, instance):
rep = super().to_representation(instance)
rep["cover_letter"] = instance.cover_letter
return rep

def get_request_status(self, obj) -> str:
"""Метод получения статуса запроса."""
Expand Down

0 comments on commit 9635e7f

Please sign in to comment.