コード例 #1
0
 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)
コード例 #2
0
ファイル: middleware.py プロジェクト: Koed00/django-whoshere
 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)
コード例 #3
0
ファイル: whoshere.py プロジェクト: Koed00/django-whoshere
def user_country(context):
    ip = get_ip(context['request'])
    return get_country(ip)
コード例 #4
0
ファイル: whoshere.py プロジェクト: Koed00/django-whoshere
def user_ip(context):
    return get_ip(context['request'])