Beispiel #1
0
def search_callback(sender, **kwargs):
    request = kwargs.get('request')
    query = kwargs.get('query')
    no_results = kwargs.get('no_results')
    type = kwargs.get('type', SearchTracker.SEARCH)
    page = kwargs.get('page', 1)

    if is_search_crawler(request.META.get('HTTP_USER_AGENT', 'unknown')):
        return

    if query is None or query == '':
        return

    extra_data = {
        'page': page
    }
    tracker = SearchTracker()
    if not request.user.is_anonymous():
        tracker.user = request.user
    tracker.query = query
    tracker.no_results = no_results
    tracker.ip = request.META.get('REMOTE_ADDR', '0.0.0.0')
    tracker.user_agent = request.META.get('HTTP_USER_AGENT', 'unknown')
    tracker.type = type
    tracker.extra_data = json.dumps(extra_data)
    tracker.save()
    return
def resource_file_viewed_callback(sender, **kwargs):
    """Tracks each occurance that a resource file is downloaded"""
    request = kwargs.pop('request')
    resource_file = kwargs.pop('resource_file')
    _ = kwargs.pop('signal')

    if is_search_crawler(request.META.get('HTTP_USER_AGENT', 'unknown')):
        return

    ResourceTracker.objects.create(
        user=None if request.user.is_anonymous() else request.user,
        resource_file=resource_file,
        resource=resource_file.resource,
        ip=request.META.get('REMOTE_ADDR', '0.0.0.0'),
        user_agent=request.META.get('HTTP_USER_AGENT', 'unknown'),
        type=ResourceTracker.VIEW,
        **kwargs)
    return
def resource_viewed_callback(sender, **kwargs):
    request = kwargs.get('request')
    resource = kwargs.get('resource')
    type = kwargs.get('type')
    if is_search_crawler(request.META.get('HTTP_USER_AGENT', 'unknown')):
        return

    if type is None:
        type = ResourceTracker.VIEW

    tracker = ResourceTracker()
    if not request.user.is_anonymous():
        tracker.user = request.user
    tracker.resource = resource
    tracker.ip = request.META.get('REMOTE_ADDR', '0.0.0.0')
    tracker.user_agent = request.META.get('HTTP_USER_AGENT', 'unknown')
    tracker.type = type
    tracker.save()
    return
def tag_viewed_callback(sender, **kwargs):
    request = kwargs.get('request')
    tag = kwargs.get('tag')
    type = kwargs.get('type', TagTracker.VIEW)
    data = kwargs.get('data', '')

    if is_search_crawler(request.META.get('HTTP_USER_AGENT', 'unknown')):
        return

    tracker = TagTracker()
    if not request.user.is_anonymous():
        tracker.user = request.user
    tracker.tag = tag
    tracker.ip = request.META.get('REMOTE_ADDR', '0.0.0.0')
    tracker.user_agent = request.META.get('HTTP_USER_AGENT', 'unknown')
    tracker.type = type
    tracker.extra_data = data
    tracker.save()
    return
Beispiel #5
0
def resource_viewed_callback(sender, **kwargs):
    request = kwargs.get('request')
    resource = kwargs.get('resource')
    type = kwargs.get('type')
    if is_search_crawler(request.META.get('HTTP_USER_AGENT', 'unknown')):
        return

    if type is None:
        type = ResourceTracker.VIEW

    tracker = ResourceTracker()
    if not request.user.is_anonymous():
        tracker.user = request.user
    tracker.resource = resource
    tracker.ip = request.META.get('REMOTE_ADDR', '0.0.0.0')
    tracker.user_agent = request.META.get('HTTP_USER_AGENT', 'unknown')
    tracker.type = type
    tracker.save()
    return
Beispiel #6
0
def tag_viewed_callback(sender, **kwargs):
    request = kwargs.get('request')
    tag = kwargs.get('tag')
    type = kwargs.get('type', TagTracker.VIEW)
    data = kwargs.get('data', '')

    if is_search_crawler(request.META.get('HTTP_USER_AGENT', 'unknown')):
        return

    tracker = TagTracker()
    if not request.user.is_anonymous():
        tracker.user = request.user
    tracker.tag = tag
    tracker.ip = request.META.get('REMOTE_ADDR', '0.0.0.0')
    tracker.user_agent = request.META.get('HTTP_USER_AGENT', 'unknown')
    tracker.type = type
    tracker.extra_data = data
    tracker.save()
    return
Beispiel #7
0
def resource_file_viewed_callback(sender, **kwargs):
    """Tracks each occurance that a resource file is downloaded"""
    request = kwargs.pop('request')
    resource_file = kwargs.pop('resource_file')
    _ = kwargs.pop('signal')

    if is_search_crawler(request.META.get('HTTP_USER_AGENT', 'unknown')):
        return

    ResourceTracker.objects.create(
        user=None if request.user.is_anonymous() else request.user,
        resource_file=resource_file,
        resource = resource_file.resource,
        ip=request.META.get('REMOTE_ADDR', '0.0.0.0'),
        user_agent=request.META.get('HTTP_USER_AGENT', 'unknown'),
        type=ResourceTracker.VIEW,
        **kwargs
    )
    return