def process_request(self, request): if request.user.is_authenticated(): ip = request.META['REMOTE_ADDR'] int_ip = util.ip_to_int(ip) request.user.redis.ip_history.bump(int_ip) IP(int_ip).user_history.bump(request.user.id)
def _record(timestamp_key): if request: RedisSet(timestamp_key + ":unique_ips").sadd( util.ip_to_int(request.META.get('REMOTE_ADDR'))) if user: RedisSet(timestamp_key + ":uniques").sadd(user.id) RedisKey(timestamp_key + ":count").incr(1)
def ip_user_history(request, ip): ip_int = ip_to_int(ip) history = IP(ip_int).user_history.with_scores[:] users = User.objects.in_bulk_list([user for (user, ts) in history]) history = zip(users, [ts for (user, ts) in history]) ctx = { 'history': history, } return r2r_jinja('staff/user_history.html', ctx, request)
def staff_ip_user_history(request, ip): ip_int = ip_to_int(ip) history = IP(ip_int).user_history.with_scores[:] users = User.objects.in_bulk_list([user for (user, ts) in history]) history = zip(users, [ts for (user, ts) in history]) return r2r('staff/user_history.django.html', locals())
def test_known_ip_to_int(self): for (ip, integer) in self.ip_int_pairs: self.assertEqual(util.ip_to_int(ip), integer, "util.ip_to_int(%r) != %r" % (ip, integer))
def test_malformed_input_ip_to_int(self): self.assertEqual(util.ip_to_int("2001:0db8:85a3:0000:0000:8a2e:0370:7334"), 0) self.assertEqual(util.ip_to_int("unknown"), 0) self.assertEqual(util.ip_to_int(None), 0)
def _record(timestamp_key): if request: RedisSet(timestamp_key + ":unique_ips").sadd(util.ip_to_int(request.META.get('REMOTE_ADDR'))) if user: RedisSet(timestamp_key + ":uniques").sadd(user.id) RedisKey(timestamp_key + ":count").incr(1)
def test_malformed_input_ip_to_int(self): self.assertEqual( util.ip_to_int("2001:0db8:85a3:0000:0000:8a2e:0370:7334"), 0) self.assertEqual(util.ip_to_int("unknown"), 0) self.assertEqual(util.ip_to_int(None), 0)