add linters
This commit is contained in:
72
cv/views.py
72
cv/views.py
@@ -1,14 +1,30 @@
|
||||
from django.http import Http404, FileResponse
|
||||
"""Представления (views) приложения `cv`."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from django.http import FileResponse, Http404, HttpRequest
|
||||
from django.views.generic.base import TemplateView, View
|
||||
|
||||
from cv.models import Profile
|
||||
from cv.services.dowload.docx import DocxRenderer
|
||||
from cv.services.dowload.pdf import PdfRenderer
|
||||
|
||||
|
||||
class ProfileView(TemplateView):
|
||||
template_name = 'index.html'
|
||||
"""Отображение профиля на главной странице."""
|
||||
|
||||
template_name = "index.html"
|
||||
extra_context = {}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
|
||||
"""Собрать контекст для шаблона.
|
||||
|
||||
Args:
|
||||
**kwargs: Дополнительные параметры контекста.
|
||||
|
||||
Returns:
|
||||
dict: Словарь контекста для рендеринга шаблона.
|
||||
"""
|
||||
kwargs.setdefault("view", self)
|
||||
extra_context = self._get_extra_context()
|
||||
self.extra_context.update(extra_context)
|
||||
@@ -16,19 +32,42 @@ class ProfileView(TemplateView):
|
||||
kwargs.update(self.extra_context)
|
||||
return kwargs
|
||||
|
||||
def _get_extra_context(self):
|
||||
profile = Profile.objects.prefetch_related('experience', 'skills_map').first()
|
||||
def _get_extra_context(self) -> dict[str, Any]:
|
||||
"""Получить дополнительные данные для контекста (профиль и связанные сущности).
|
||||
|
||||
Returns:
|
||||
dict: Дополнительные пары ключ/значение для контекста.
|
||||
|
||||
Raises:
|
||||
Http404: Если профиль не найден.
|
||||
"""
|
||||
profile = Profile.objects.prefetch_related("experience", "skills_map").first()
|
||||
if not profile:
|
||||
raise Http404("Профиль не найден")
|
||||
return {
|
||||
'profile': profile,
|
||||
"profile": profile,
|
||||
}
|
||||
|
||||
|
||||
class DownloadDocxView(View):
|
||||
"""Скачать резюме в формате DOCX."""
|
||||
|
||||
_docx = DocxRenderer()
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
def get(self, _request: HttpRequest, *_args: Any, **_kwargs: Any) -> FileResponse:
|
||||
"""Вернуть файл DOCX с содержимым резюме.
|
||||
|
||||
Args:
|
||||
request: HTTP‑запрос.
|
||||
*args: Позиционные аргументы.
|
||||
**kwargs: Именованные аргументы.
|
||||
|
||||
Returns:
|
||||
FileResponse: Ответ c приложением DOCX.
|
||||
|
||||
Raises:
|
||||
Http404: Если профиль не найден.
|
||||
"""
|
||||
profile = Profile.objects.prefetch_related("experience", "skills_map").first()
|
||||
if not profile:
|
||||
raise Http404("Профиль не найден")
|
||||
@@ -48,9 +87,24 @@ class DownloadDocxView(View):
|
||||
|
||||
|
||||
class DownloadPdfView(View):
|
||||
"""Скачать резюме в формате PDF."""
|
||||
|
||||
_pdf = PdfRenderer()
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
def get(self, _request: HttpRequest, *_args: Any, **_kwargs: Any) -> FileResponse:
|
||||
"""Вернуть файл PDF с содержимым резюме.
|
||||
|
||||
Args:
|
||||
request: HTTP‑запрос.
|
||||
*args: Позиционные аргументы.
|
||||
**kwargs: Именованные аргументы.
|
||||
|
||||
Returns:
|
||||
FileResponse: Ответ c приложением PDF.
|
||||
|
||||
Raises:
|
||||
Http404: Если профиль не найден.
|
||||
"""
|
||||
profile = Profile.objects.prefetch_related("experience", "skills_map").first()
|
||||
if not profile:
|
||||
raise Http404("Профиль не найден")
|
||||
@@ -65,4 +119,4 @@ class DownloadPdfView(View):
|
||||
content_type="application/pdf",
|
||||
)
|
||||
resp["Cache-Control"] = "no-store"
|
||||
return resp
|
||||
return resp
|
||||
|
||||
Reference in New Issue
Block a user