Ejemplo n.º 1
0
def _save_results(item, user, duration, raw_result):
    """
    Creates or updates the EvaluationResult for the given item and user.
    """
    LOGGER.debug('item: {}, user: {}, duration: {}, raw_result: {}'.format(
        item, user, duration, raw_result.encode('utf-8')))

    _existing_result = EvaluationResult.objects.filter(item=item, user=user)

    if _existing_result:
        _result = _existing_result[0]

    else:
        _result = EvaluationResult(item=item, user=user)

    # Django >1.3 uses django.utils.dateparse.parse_time to prepare TimeField
    # values for database storage.  This would throw a TypeError as duration
    # has type datetime.timedelta which cannot be parsed by parse_time.
    #
    # To solve this, we convert duration to its String representation.
    try:
        from django.utils.dateparse import parse_time
        _result.duration = str(duration)

    # For Django 1.3, we can simply leave duration as is.
    except ImportError:  # because it just doesn't get to TypeError in django 1.3, fails to import before that
        _result.duration = duration
    except TypeError:
        _result.duration = duration

    _result.raw_result = raw_result
    _result.save()
Ejemplo n.º 2
0
def _save_results(item, user, duration, raw_result):
    """
    Creates or updates the EvaluationResult for the given item and user.
    """
    LOGGER.debug('item: {}, user: {}, duration: {}, raw_result: {}'.format(
      item, user, duration, raw_result.encode('utf-8')))
    
    _existing_result = EvaluationResult.objects.filter(item=item, user=user)
    
    if _existing_result:
        _result = _existing_result[0]
    
    else:
        _result = EvaluationResult(item=item, user=user)
    
    # Django >1.3 uses django.utils.dateparse.parse_time to prepare TimeField
    # values for database storage.  This would throw a TypeError as duration
    # has type datetime.timedelta which cannot be parsed by parse_time.
    #
    # To solve this, we convert duration to its String representation.
    try:
        from django.utils.dateparse import parse_time
        _result.duration = str(duration)
    
    # For Django 1.3, we can simply leave duration as is.
    except ImportError:  # because it just doesn't get to TypeError in django 1.3, fails to import before that
        _result.duration = duration
    except TypeError:
        _result.duration = duration
    
    _result.raw_result = raw_result
    _result.save()
Ejemplo n.º 3
0
def _save_results(item, user, duration, raw_result):
    """
    Creates or updates the EvaluationResult for the given item and user.
    """
    LOGGER.debug('item: {}, user: {}, duration: {}, raw_result: {}'.format(
      item, user, duration, raw_result.encode('utf-8')))
    
    _existing_result = EvaluationResult.objects.filter(item=item, user=user)
    
    if _existing_result:
        _result = _existing_result[0]
    
    else:
        _result = EvaluationResult(item=item, user=user)
    
    _result.duration = duration
    _result.raw_result = raw_result
    _result.save()
Ejemplo n.º 4
0
def _save_results(item, user, duration, raw_result):
    """
    Creates or updates the EvaluationResult for the given item and user.
    """
    LOGGER.debug('item: {}, user: {}, duration: {}, raw_result: {}'.format(
      item, user, duration, raw_result.encode('utf-8')))
    
    _existing_result = EvaluationResult.objects.filter(item=item, user=user)
    
    if _existing_result:
        _result = _existing_result[0]
    
    else:
        _result = EvaluationResult(item=item, user=user)
    
    _result.duration = duration
    _result.raw_result = raw_result
    _result.save()