Exemple #1
0
def saveLRStats(resource, action, request=None):
    """
    Saves the actions on a resource.
    
    Takes into account the session to avoid to increment more than one time the
    stats counter. Returns whether the stats counter was incremented or not.
    """
    result = False
    LOGGER.debug("saveLRStats action=%s lrid=%s", action,
                 resource.storage_object.identifier)
    if not hasattr(resource,
                   'storage_object') or resource.storage_object is None:
        return result

    # Manage statistics according with the resource status
    lrid = resource.storage_object.identifier
    ignored = False
    if action == INGEST_STAT:
        ignored = True
        LRStats.objects.filter(lrid=lrid).update(ignored=ignored)
        UsageStats.objects.filter(lrid=lrid).delete()
    if action == DELETE_STAT:
        UsageStats.objects.filter(lrid=lrid).delete()
        LRStats.objects.filter(lrid=lrid).delete()
        return result
    if (resource.storage_object.publication_status != PUBLISHED):
        return result

    userid = _get_userid(request)
    sessid = _get_sessionid(request)
    lrset = LRStats.objects.filter(userid=userid,
                                   lrid=lrid,
                                   sessid=sessid,
                                   action=action)
    if (lrset.count() > 0):
        record = lrset[0]
        record.ignored = ignored
        record.save(force_update=True)
        #LOGGER.debug('UPDATESTATS: Saved LR {0}, {1} action={2} ({3}).'.format(lrid, sessid, action, record.lasttime))
    else:
        record = LRStats()
        record.userid = userid
        record.lrid = lrid
        record.action = action
        record.sessid = sessid
        record.geoinfo = getcountry_code(_get_ipaddress(request))
        record.ignored = ignored
        record.save(force_insert=True)
        #LOGGER.debug('SAVESTATS: Saved LR {0}, {1} action={2}.'.format(lrid, sessid, action))
        result = True
    if action == UPDATE_STAT:
        if (resource.storage_object.published):
            UsageStats.objects.filter(lrid=lrid).delete()
            update_usage_stats(lrid, resource.export_to_elementtree())
            #LOGGER.debug('STATS: Updating usage statistics: resource {0} updated'.format(lrid))
    return result
Exemple #2
0
def saveLRStats(resource, action, request=None): 
    """
    Saves the actions on a resource.
    
    Takes into account the session to avoid to increment more than one time the
    stats counter. Returns whether the stats counter was incremented or not.
    """
    result = False
    LOGGER.debug("saveLRStats %s %s", action,
                 resource.storage_object.identifier)
    if not hasattr(resource, 'storage_object') or resource.storage_object is None:
        return result
        
    # Manage statistics according with the resource status
    lrid = resource.storage_object.identifier
    ignored = False
    if action == INGEST_STAT:
        ignored = True
        LRStats.objects.filter(lrid=lrid).update(ignored=ignored)
        UsageStats.objects.filter(lrid=lrid).delete()
    if action == DELETE_STAT:
        UsageStats.objects.filter(lrid=lrid).delete()
        LRStats.objects.filter(lrid=lrid).delete()
        return
    if (resource.storage_object.publication_status != PUBLISHED):
        return False
    
    userid = _get_userid(request)
    sessid = _get_sessionid(request)
    lrset = LRStats.objects.filter(userid=userid, lrid=lrid, sessid=sessid, action=action)
    if (lrset.count() > 0):
        record = lrset[0]
        record.lasttime = datetime.now()
        record.ignored = ignored
        record.save(force_update=True)
        LOGGER.debug('UPDATESTATS: Saved LR {0}, {1} action={2} ({3}).'.format(lrid, sessid, action, record.lasttime))
    else:       
        record = LRStats()
        record.userid = userid
        record.lrid = lrid
        record.action = action
        record.sessid = sessid
        record.geoinfo = getcountry_code(_get_ipaddress(request))
        record.ignored = ignored
        record.save(force_insert=True)
        LOGGER.debug('SAVESTATS: Saved LR {0}, {1} action={2}.'.format(lrid, sessid, action))
        result = True
    if action == UPDATE_STAT:
        if (resource.storage_object.published):
            UsageStats.objects.filter(lrid=lrid).delete()
            _update_usage_stats(lrid, resource.export_to_elementtree())
            LOGGER.debug('STATS: Updating usage statistics: resource {0} updated'.format(lrid))
    return result
Exemple #3
0
def saveLRStats(resource, userid, sessid, action): 
    """
    this function saves the actions on a resource (it takes into account the session to avoid to increment more than one time the stats counter)
    """
    if not sessid:
        sessid = ""   
    lrset = LRStats.objects.filter(userid=userid, lrid=resource.storage_object.identifier, sessid=sessid, action=action)
    if (lrset.count() > 0):
        record = lrset[0]
        #record.count = record.count+1
        record.sessid = sessid
        record.lasttime = datetime.now()
        record.save(force_update=True)
        LOGGER.debug('UPDATESTATS: Saved LR {0}, {1} action={2} ({3}).'.format(resource.storage_object.identifier, sessid, action, record.lasttime))
    else:       
        record = LRStats()
        record.userid = userid
        record.lrid = resource.storage_object.identifier
        record.action = action
        record.sessid = sessid 
        record.save(force_insert=True)
        LOGGER.debug('SAVESTATS: Saved LR {0}, {1} action={2}.'.format(resource.storage_object.identifier, sessid, action))
    if action == UPDATE_STAT or action == PUBLISH_STAT:
        if (resource.storage_object.published):
            UsageStats.objects.filter(lrid=resource.id).delete()
            _update_usage_stats(resource.id, resource.export_to_elementtree())
            LOGGER.debug('STATS: Updating usage statistics: resource {0} updated'.format(resource.storage_object.identifier))
Exemple #4
0
def saveLRStats(userid, lrid, sessid, action): 
    """
    this function saves the actions on a resource (it takes into account the session to avoid to increment more than one time the stats counter)
    """
    if not sessid:
        sessid = ""
    
    lrset = LRStats.objects.filter(userid=userid, lrid=lrid, sessid=sessid, action=action)
    if (lrset.count() > 0):
        record = lrset[0]
        #record.count = record.count+1
        record.sessid = sessid
        record.lasttime = datetime.now()
        record.save(force_update=True)
        LOGGER.debug('UPDATESTATS: Saved LR {0}, {1} action={2} ({3}).'.format(lrid, sessid, action, record.lasttime))
    else:       
        record = LRStats()
        record.userid = userid
        record.lrid = lrid
        record.action = action
        record.sessid = sessid
    
        record.save(force_insert=True)
        LOGGER.debug('SAVESTATS: Saved LR {0}, {1} action={2}.'.format(lrid, sessid, action))