Добавил игнор статистики
This commit is contained in:
parent
4494d2f2de
commit
32b1ec4379
Binary file not shown.
@ -20,6 +20,87 @@ menu = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# === ДОБАВЬТЕ ЭТИ ФУНКЦИИ ЗДЕСЬ ===
|
||||||
|
|
||||||
|
def get_client_ip(request):
|
||||||
|
"""Получаем реальный IP клиента"""
|
||||||
|
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
|
||||||
|
if x_forwarded_for:
|
||||||
|
ip = x_forwarded_for.split(',')[0]
|
||||||
|
else:
|
||||||
|
ip = request.META.get('REMOTE_ADDR')
|
||||||
|
return ip
|
||||||
|
|
||||||
|
|
||||||
|
def should_track_request(request):
|
||||||
|
"""Определяем, нужно ли отслеживать запрос"""
|
||||||
|
|
||||||
|
client_ip = get_client_ip(request)
|
||||||
|
path = request.path
|
||||||
|
|
||||||
|
# Игнорируемые пути (Nextcloud специфичные)
|
||||||
|
nextcloud_paths = [
|
||||||
|
'/index.php',
|
||||||
|
'/status.php',
|
||||||
|
'/cron',
|
||||||
|
'/remote.php',
|
||||||
|
'/ocs',
|
||||||
|
'/apps/',
|
||||||
|
'/custom_apps/',
|
||||||
|
]
|
||||||
|
|
||||||
|
# Игнорируемые IP (Docker сети)
|
||||||
|
docker_ips = [
|
||||||
|
'192.168.64.1',
|
||||||
|
'192.168.65.1',
|
||||||
|
'172.17.0.1',
|
||||||
|
'172.18.0.1',
|
||||||
|
'172.19.0.1',
|
||||||
|
]
|
||||||
|
|
||||||
|
# Игнорируем статические файлы и админку
|
||||||
|
if path.startswith('/static/') or path.startswith('/admin/'):
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Не отслеживаем Nextcloud и Docker запросы
|
||||||
|
if any(path.startswith(p) for p in nextcloud_paths):
|
||||||
|
return False
|
||||||
|
if client_ip in docker_ips:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def track_page_view(request):
|
||||||
|
"""Основная функция отслеживания просмотров"""
|
||||||
|
if not should_track_request(request):
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
PageView.objects.create(
|
||||||
|
url=request.path,
|
||||||
|
ip_address=get_client_ip(request),
|
||||||
|
user_agent=request.META.get('HTTP_USER_AGENT', '')[:500],
|
||||||
|
referer=request.META.get('HTTP_REFERER', '')[:500],
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error tracking page: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
def track_view(view_func):
|
||||||
|
"""Декоратор для отслеживания просмотров страниц"""
|
||||||
|
from functools import wraps
|
||||||
|
|
||||||
|
@wraps(view_func)
|
||||||
|
def _wrapped_view(request, *args, **kwargs):
|
||||||
|
# Отслеживаем просмотр перед выполнением view
|
||||||
|
track_page_view(request)
|
||||||
|
return view_func(request, *args, **kwargs)
|
||||||
|
|
||||||
|
return _wrapped_view
|
||||||
|
|
||||||
|
|
||||||
|
@track_view
|
||||||
def index(request):
|
def index(request):
|
||||||
posts = Home.objects.filter(is_published=True)
|
posts = Home.objects.filter(is_published=True)
|
||||||
context = {
|
context = {
|
||||||
@ -31,6 +112,7 @@ def index(request):
|
|||||||
return render(request, 'programmer/index.html', context=context)
|
return render(request, 'programmer/index.html', context=context)
|
||||||
|
|
||||||
|
|
||||||
|
@track_view
|
||||||
def about(request):
|
def about(request):
|
||||||
context = {
|
context = {
|
||||||
'menu': menu,
|
'menu': menu,
|
||||||
@ -39,6 +121,7 @@ def about(request):
|
|||||||
return render(request, 'programmer/about.html', context=context)
|
return render(request, 'programmer/about.html', context=context)
|
||||||
|
|
||||||
|
|
||||||
|
@track_view
|
||||||
def solution(request):
|
def solution(request):
|
||||||
posts = Solution.objects.filter(is_published=True)
|
posts = Solution.objects.filter(is_published=True)
|
||||||
context = {
|
context = {
|
||||||
@ -49,6 +132,7 @@ def solution(request):
|
|||||||
return render(request, 'programmer/solution.html', context=context)
|
return render(request, 'programmer/solution.html', context=context)
|
||||||
|
|
||||||
|
|
||||||
|
@track_view
|
||||||
def ability(request):
|
def ability(request):
|
||||||
posts = Competence.objects.filter(is_published=True)
|
posts = Competence.objects.filter(is_published=True)
|
||||||
context = {
|
context = {
|
||||||
@ -59,6 +143,7 @@ def ability(request):
|
|||||||
return render(request, 'programmer/competence.html', context=context)
|
return render(request, 'programmer/competence.html', context=context)
|
||||||
|
|
||||||
|
|
||||||
|
@track_view
|
||||||
def recall(request):
|
def recall(request):
|
||||||
posts = Recall.objects.filter(is_published=True)
|
posts = Recall.objects.filter(is_published=True)
|
||||||
context = {
|
context = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user