

@classmethod
def hit_count(self, request, hitcount):
    "\n        Called with a HttpRequest and HitCount object it will return a\n        namedtuple:\n\n        UpdateHitCountResponse(hit_counted=Boolean, hit_message='Message').\n\n        `hit_counted` will be True if the hit was counted and False if it was\n        not.  `'hit_message` will indicate by what means the Hit was either\n        counted or ignored.\n        "
    UpdateHitCountResponse = namedtuple('UpdateHitCountResponse', 'hit_counted hit_message')
    if (request.session.session_key is None):
        request.session.save()
    user = request.user
    session_key = request.session.session_key
    ip = get_ip(request)
    user_agent = request.META.get('HTTP_USER_AGENT', '')[:255]
    hits_per_ip_limit = getattr(settings, 'HITCOUNT_HITS_PER_IP_LIMIT', 0)
    exclude_user_group = getattr(settings, 'HITCOUNT_EXCLUDE_USER_GROUP', None)
    if BlacklistIP.objects.filter(ip__exact=ip):
        return UpdateHitCountResponse(False, 'Not counted: user IP has been blacklisted')
    if BlacklistUserAgent.objects.filter(user_agent__exact=user_agent):
        return UpdateHitCountResponse(False, 'Not counted: user agent has been blacklisted')
    if (exclude_user_group and user.is_authenticated()):
        if user.groups.filter(name__in=exclude_user_group):
            return UpdateHitCountResponse(False, 'Not counted: user excluded by group')
    qs = Hit.objects.filter_active()
    if hits_per_ip_limit:
        if (qs.filter(ip__exact=ip).count() >= hits_per_ip_limit):
            return UpdateHitCountResponse(False, 'Not counted: hits per IP address limit reached')
    hit = Hit(session=session_key, hitcount=hitcount, ip=get_ip(request), user_agent=request.META.get('HTTP_USER_AGENT', '')[:255])
    if user.is_authenticated():
        if (not qs.filter(user=user, hitcount=hitcount)):
            hit.user = user
            hit.save()
            response = response(True, 'Hit counted: user authentication')
        else:
            response = UpdateHitCountResponse(False, 'Not counted: authenticated user has active hit')
    elif (not qs.filter(session=session_key, hitcount=hitcount)):
        hit.save()
        response = UpdateHitCountResponse(True, 'Hit counted: session key')
    else:
        response = UpdateHitCountResponse(False, 'Not counted: session key has active hit')
    return response

dataset/ETHPy150Open thornomad/django-hitcount/hitcount/views.py HitCountMixin.hit_count/VarMisuse@317/668 `UpdateHitCountResponse`->`response`