Site/programmer/mixins.py

35 lines
1.2 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.

from typing import Any, Dict
from django.views.generic.base import ContextMixin
from .services import track_page_view
class PageViewTrackingMixin(ContextMixin):
"""
Миксин для отслеживания просмотров страниц.
Добавляет трекинг при вызове view.
"""
def dispatch(self, request, *args, **kwargs):
# Отслеживаем просмотр перед обработкой запроса
track_page_view(request)
return super().dispatch(request, *args, **kwargs)
class MenuContextMixin(ContextMixin):
"""
Миксин для добавления меню в контекст.
"""
menu = [
{'title': "Главная", 'url_name': 'home'},
{'title': "Проекты", 'url_name': 'solution'},
{'title': "Статьи", 'url_name': 'blog'},
{'title': "Отзывы", 'url_name': 'recall'},
{'title': "Обо мне", 'url_name': 'about'}
]
def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
context = super().get_context_data(**kwargs)
context['menu'] = self.menu
return context