Compare commits
2 Commits
47cb55ab92
...
3d76637d84
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d76637d84 | |||
| b5b5be3007 |
@ -9,7 +9,14 @@ class AnalyticsMiddleware:
|
|||||||
self.get_response = get_response
|
self.get_response = get_response
|
||||||
|
|
||||||
def __call__(self, request):
|
def __call__(self, request):
|
||||||
ip = request.META.get('REMOTE_ADDR')
|
# ip = request.META.get('REMOTE_ADDR')
|
||||||
|
# 1. Get the real IP
|
||||||
|
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
|
||||||
|
if x_forwarded_for:
|
||||||
|
# Get the first IP in the list (the original client)
|
||||||
|
ip = x_forwarded_for.split(',')[0].strip()
|
||||||
|
else:
|
||||||
|
ip = request.META.get('REMOTE_ADDR')
|
||||||
|
|
||||||
# LOG 1: Check if Middleware is even being triggered
|
# LOG 1: Check if Middleware is even being triggered
|
||||||
print(f"DEBUG: Middleware triggered for IP: {ip}")
|
print(f"DEBUG: Middleware triggered for IP: {ip}")
|
||||||
|
|||||||
@ -5,14 +5,9 @@ from .models import VisitorLog
|
|||||||
def log_visitor_location(ip_address):
|
def log_visitor_location(ip_address):
|
||||||
# if ip_address in ['127.0.0.1', 'localhost']:
|
# if ip_address in ['127.0.0.1', 'localhost']:
|
||||||
# return
|
# return
|
||||||
if ip_address.startswith(('127.', '192.168.', '10.', '172.16.')):
|
if ip_address.startswith(('127.', '10.')):
|
||||||
VisitorLog.objects.create(
|
|
||||||
ip_address=ip_address,
|
print(f"DEBUG: Logged Skipped local IP {ip_address}")
|
||||||
country="Local Network",
|
|
||||||
city="Development Machine",
|
|
||||||
region="Home"
|
|
||||||
)
|
|
||||||
print(f"DEBUG: Logged local IP {ip_address}")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -151,7 +151,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = 'en-us'
|
||||||
|
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = 'Asia/Riyadh'
|
||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user