50 lines
1.9 KiB
Python
50 lines
1.9 KiB
Python
"""Базовые протоколы и сериализаторы для рендереров резюме.
|
||
|
||
Содержит `ProfileSerializer` для подготовки данных профиля к выводу
|
||
и протокол `Renderer` с контрактом метода `render`.
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from io import BytesIO
|
||
from typing import Any, Protocol
|
||
|
||
|
||
class ProfileSerializer:
|
||
"""Сериализатор данных профиля для рендереров.
|
||
|
||
Готовит словарь с данными, необходимыми для HTML/PDF/DOCX рендеринга.
|
||
"""
|
||
|
||
def serialize(self, profile: Any) -> dict[str, Any]:
|
||
"""Собрать слепок профиля для рендеринга.
|
||
|
||
Args:
|
||
profile: Экземпляр модели профиля.
|
||
|
||
Returns:
|
||
dict[str, Any]: Сериализованные поля профиля, контактов, опыта и навыков.
|
||
"""
|
||
return {
|
||
"full_name": profile.full_name,
|
||
"role": getattr(profile, "role", ""),
|
||
"summary": getattr(profile, "summary", ""),
|
||
"location": getattr(profile, "location", ""),
|
||
"languages": getattr(profile, "languages", []) or [],
|
||
"contacts": {
|
||
"email": getattr(profile, "email", ""),
|
||
"phone": getattr(profile, "phone", ""),
|
||
"telegram": getattr(profile, "telegram", ""),
|
||
},
|
||
"experience": list(profile.experience.all()),
|
||
"skills_map": list(profile.skills_map.all()),
|
||
}
|
||
|
||
|
||
class Renderer(Protocol):
|
||
"""Протокол рендерера документов с методом `render`."""
|
||
|
||
def render(self, profile: Any) -> BytesIO:
|
||
"""Сгенерировать бинарный документ по профилю."""
|
||
...
|