Files
resume/cv/services/dowload/base.py
Pavel Sobolev d5ff05abdb add linters
2025-11-13 01:33:00 +03:00

50 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Базовые протоколы и сериализаторы для рендереров резюме.
Содержит `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:
"""Сгенерировать бинарный документ по профилю."""
...