def process_request(request): """ Checks for authenticated user and adds ip and user-agent to the cache """ if not hasattr(request, 'user') or not request.user: return key = '{}:{}'.format(PREFIX, request.user.pk) # Add ip and user agent to cache if it's not there if not cache.get(key): cache.set(key, {'ip': get_ip(request), 'agent': request.META.get('HTTP_USER_AGENT', '')}, TIMEOUT)
def process_request(request): """ Checks for authenticated user and adds ip and user-agent to the cache """ if not hasattr(request, 'user') or not request.user: return key = '{}:{}'.format(PREFIX, request.user.pk) # Add ip and user agent to cache if it's not there if not cache.get(key): cache.set( key, { 'ip': get_ip(request), 'agent': request.META.get('HTTP_USER_AGENT', ''), 'path': request.path }, TIMEOUT)
def user_country(context): ip = get_ip(context['request']) return get_country(ip)
def user_ip(context): return get_ip(context['request'])