added geo support to track_user view
This commit is contained in:
@@ -8,8 +8,10 @@ from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from rest_framework.permissions import AllowAny
|
||||
|
||||
from ipware import get_client_ip
|
||||
from django.contrib.gis.geoip2 import GeoIP2
|
||||
from django.contrib.gis.geos import Point
|
||||
|
||||
from ipware import get_client_ip
|
||||
|
||||
from back_latienda.permissions import IsStaff
|
||||
|
||||
@@ -44,7 +46,7 @@ def track_user(request):
|
||||
id: 1,
|
||||
},
|
||||
'ip': '2134.234.234.2134',
|
||||
'geo': (latitude: 324.32., longitud: 32423.23)
|
||||
'geo': (324.32, 32423.23)
|
||||
}
|
||||
"""
|
||||
try:
|
||||
@@ -56,7 +58,7 @@ def track_user(request):
|
||||
'user': None if request.user.is_anonymous else request.user,
|
||||
'anonymous': request.user.is_anonymous,
|
||||
'ip_address': data.get('ip'),
|
||||
'geo': data.get('geo'),
|
||||
'geo': Point(data.get('geo')),
|
||||
}
|
||||
|
||||
if data['action_object'].get('model') == 'product':
|
||||
@@ -73,7 +75,5 @@ def track_user(request):
|
||||
new_stat = StatsLog.objects.create(**instance_data)
|
||||
return Response(status=status.HTTP_201_CREATED)
|
||||
except Exception as e:
|
||||
import ipdb; ipdb.set_trace()
|
||||
|
||||
logging.error(f"Stats could not be created: {str(e)}")
|
||||
return Response(f"Process could not be registered: {str(type(e))}", status=status.HTTP_406_NOT_ACCEPTABLE)
|
||||
|
||||
Reference in New Issue
Block a user