Example #1
0
def CPF(text):
    """
    Format to display CPF fields
    :param text:
    :return:
    """
    if not isinstance(text, str):
        text = str(text)
    text = fill_with(text, '0', 11)
    return '{}.{}.{}-{}'.format(text[0:3], text[3:6], text[6:9], text[9:])
Example #2
0
def CEP(text):
    """
    Format to display CEP fields
    :param text:
    :return:
    """
    if not isinstance(text, str):
        text = str(text)
    text = fill_with(text, '0', 8)
    return '{}.{}-{}'.format(text[0:2], text[2:5], text[5:])
Example #3
0
def CNPJ(text):
    """
    Format to display CNPJ fields
    :param text:
    :return:
    """
    if not isinstance(text, str):
        text = str(text)
    text = fill_with(text, '0', 14)
    return '{}.{}.{}/{}-{}'.format(text[0:2], text[2:5], text[5:8], text[8:12],
                                   text[12:])
Example #4
0
def PHONE(text):
    """
    Format to display phone fields
    :param text:
    :return:
    """
    if not isinstance(text, str):
        text = str(text)
    if len(text) in (8, 9):
        return '(  ) {}-{}'.format(text[0:5], text[5:])
    elif len(text) in (10, 11):
        return '({}) {}-{}'.format(text[0:2], text[2:7], text[7:])
    else:
        text = fill_with(text, '0', 8)
        return '(  ) {}-{}'.format(text[0:5], text[5:8])
Example #5
0
def CURRENCY(text):
    """
    Format to display currency fields
    :param text:
    :return:
    """
    if not isinstance(text, str):
        text = str(text)
    digits = text.split('.')
    to_return = ''
    counter = 0
    integer = digits[0]
    decimal = '00' if len(digits) == 1 else fill_with(digits[1], '0', 2, True)
    for i in integer[::-1]:
        if counter > 0 and counter % 3 == 0:
            to_return = '.' + to_return
        to_return = i + to_return
        counter += 1
    return 'R$ {},{}'.format(to_return, decimal)