Beispiel #1
0
def validate_cpf(value):

    try:

        digits_cpf = [10, 9, 8, 7, 6, 5, 4, 3, 2]
        cpf = re.sub('[.-]', '', value)

        total = 0
        for i in range(9):
            total += (int(cpf[i]) * digits_cpf[i])

        mod = (total % 11)
        first_digit = 0
        if mod >= 2:
            first_digit = (11 - mod)

        digits_cpf.insert(0, 11)

        total = 0
        for i in range(10):
            total += (int(cpf[i]) * digits_cpf[i])

        mod = (total % 11)
        second_digit = 0
        if mod >= 2:
            second_digit = (11 - mod)

        if int(cpf[9]) != first_digit:
            raise ValidationError(messages.get('cpf'))

        if int(cpf[10]) != second_digit:
            raise ValidationError(messages.get('cpf'))

    except:
        raise ValidationError(messages.get('cpf'))
Beispiel #2
0
def validate_cpf(value):

    try:

        digits_cpf = [10, 9, 8, 7, 6, 5, 4, 3, 2]
        cpf = re.sub('[.-]', '', value)

        total = 0
        for i in range(9):
            total += (int(cpf[i]) * digits_cpf[i])

        mod = (total % 11)
        first_digit = 0
        if mod >= 2:
            first_digit = (11 - mod)

        digits_cpf.insert(0, 11)

        total = 0
        for i in range(10):
            total += (int(cpf[i]) * digits_cpf[i])

        mod = (total % 11)
        second_digit = 0
        if mod >= 2:
            second_digit = (11 - mod)

        if int(cpf[9]) != first_digit:
            raise ValidationError(messages.get('cpf'))

        if int(cpf[10]) != second_digit:
            raise ValidationError(messages.get('cpf'))

    except:
        raise ValidationError(messages.get('cpf'))
Beispiel #3
0
def validate_string(value):
    if not isinstance(value, basestring):
        raise ValidationError(messages.get('string'))
Beispiel #4
0
def validate_greater_zero(value):
    if int(value) <= 0:
        raise ValidationError(messages.get('greater_zero'))
Beispiel #5
0
def validate_float_greater_equal_zero(value):
    if float(value) < 0:
        raise ValidationError(messages.get('greater_equal_zero'))
Beispiel #6
0
def validate_integer(value):
    try:
        int(value)
    except (TypeError, ValueError):
        raise ValidationError(messages.get('integer'))
Beispiel #7
0
def validate_float(value):
    try:
        float(value)
    except (TypeError, ValueError):
        raise ValidationError(messages.get('float'))
Beispiel #8
0
def validate_boolean(value):
    if not value in ['0', '1', 'False', 'True', False, True, 'false', 'true']:
        raise ValidationError(messages.get('boolean'))
Beispiel #9
0
def validate_integer(value):
    try:
        int(value)
    except (TypeError, ValueError):
        raise ValidationError(messages.get('integer'))
Beispiel #10
0
def validate_string_minsize(value, minsize):
    if len(value.strip()) < minsize:
        raise ValidationError(
            messages.get('min_length') % {'limit_value': minsize})
Beispiel #11
0
def validate_boolean(value):
    if not value in ['0', '1', 'False', 'True', False, True, 'false', 'true']:
        raise ValidationError(messages.get('boolean'))
Beispiel #12
0
def validate_string(value):
    if not isinstance(value, basestring):
        raise ValidationError(messages.get('string'))
Beispiel #13
0
def validate_string_is_empty(value):
    if '' == value.strip():
        raise ValidationError(messages.get('required'))
Beispiel #14
0
def validate_float_greater_equal_zero(value):
    if float(value) < 0:
        raise ValidationError(messages.get('greater_equal_zero'))
Beispiel #15
0
def validate_greater_zero(value):
    if int(value) <= 0:
        raise ValidationError(messages.get('greater_zero'))
Beispiel #16
0
def validate_float(value):
    try:
        float(value)
    except (TypeError, ValueError):
        raise ValidationError(messages.get('float'))
Beispiel #17
0
def validate_string_is_empty(value):
    if '' == value.strip():
        raise ValidationError(messages.get('required'))
Beispiel #18
0
def __get_body_unhandled_exception(e, traceback=None):
    data = e.__dict__.copy()
    data["stacktrace"] = traceback or exceptions.get_traceback(e)
    msg = ". ".join([messages.get(type(e), ""), str(e)])
    body = create_error_body(msg, "Unhandled", data)
    return body
Beispiel #19
0
def validate_string_minsize(value, minsize):
    if len(value.strip()) < minsize:
        raise ValidationError(messages.get('min_length') % {'limit_value': minsize})
Beispiel #20
0
def validate_required(value):
    if value is None or value == '':
        raise ValidationError(messages.get('required'))
Beispiel #21
0
def __get_body_main_error(e):
    data = e.__dict__
    msg = messages.get(type(e))
    body = create_error_body(msg, type(e).__name__, data)
    return body
Beispiel #22
0
def validate_required(value):
    if value is None or value == '':
        raise ValidationError(messages.get('required'))