stale ip handling: use logger, initialize timestamp in session if it is not there
This commit is contained in:
parent
2529263a48
commit
7cbacedaf1
@ -1,5 +1,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -28,7 +31,9 @@ def remove_stale_ips(request):
|
|||||||
try:
|
try:
|
||||||
timestamp = s[timestamp_key]
|
timestamp = s[timestamp_key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
# should be always there, initialize it:
|
||||||
|
s[key] = ''
|
||||||
|
s[timestamp_key] = t_now
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
stale = timestamp + timedelta(seconds=MAX_IP_AGE) < t_now
|
stale = timestamp + timedelta(seconds=MAX_IP_AGE) < t_now
|
||||||
@ -37,7 +42,7 @@ def remove_stale_ips(request):
|
|||||||
del s[timestamp_key]
|
del s[timestamp_key]
|
||||||
else:
|
else:
|
||||||
if stale:
|
if stale:
|
||||||
print "ts: %s now: %s - killing %s (was: %s)" % (timestamp, t_now, key, s[key])
|
logger.debug("ts: %s now: %s - killing stale %s (was: %s)" % (timestamp, t_now, key, s[key]))
|
||||||
# kill the IP, it is not up-to-date any more
|
# kill the IP, it is not up-to-date any more
|
||||||
# note: it is used to fill form fields, so set it to empty string
|
# note: it is used to fill form fields, so set it to empty string
|
||||||
s[key] = ''
|
s[key] = ''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user