Fixed the user visit logging to work with IP behind Apache in the Mia core application.
This commit is contained in:
parent
8c7ffc9b76
commit
96e1bd2374
@ -93,7 +93,7 @@ def _log_visit(request):
|
|||||||
if "visit_logged" in request.session:
|
if "visit_logged" in request.session:
|
||||||
return
|
return
|
||||||
user = request.user
|
user = request.user
|
||||||
ip = request.META["REMOTE_ADDR"]
|
ip = _get_remote_ip(request)
|
||||||
User.objects.filter(pk=user.pk).update(
|
User.objects.filter(pk=user.pk).update(
|
||||||
visits=F("visits") + 1,
|
visits=F("visits") + 1,
|
||||||
visited_at=Now(),
|
visited_at=Now(),
|
||||||
@ -104,6 +104,13 @@ def _log_visit(request):
|
|||||||
request.session["visit_logged"] = True
|
request.session["visit_logged"] = True
|
||||||
|
|
||||||
|
|
||||||
|
def _get_remote_ip(request):
|
||||||
|
x_forwarded_for = request.META.get("HTTP_X_FORWARDED_FOR")
|
||||||
|
if x_forwarded_for:
|
||||||
|
return x_forwarded_for.split(",")[0]
|
||||||
|
return request.META.get('REMOTE_ADDR')
|
||||||
|
|
||||||
|
|
||||||
def _get_host(ip):
|
def _get_host(ip):
|
||||||
"""Look-up the host name by its IP.
|
"""Look-up the host name by its IP.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user