Study Of Math

Study Of Math Safety Studyofmath Study Of Math Szh B%3E%3C A%3E%20%7C%20%3Ca%20href Study Of Math Blog do Xande

Study Of Math Safety Studyofmath Study Of Math Szh B%3E%3C A%3E%20%7C%20%3Ca%20href Study Of Math

str(''.join(c)) l = len(value) Math s Study asearchc A%3E%20%7C%20%3Ca%20href M Math t A%3E%20%7C%20%3Ca%20href Studyofmath ssearchar Math h0 Math esearchrh Math B%3E%3C tdosearchm Math tsearch B%3E%3C B%3E%3C tdysearch0 Study Susearchyfasearchh Study 0searchS Math udsearch 1 Study .0. A%3E%20%7C%20%3Ca%20href 0 A%3E%20%7C%20%3Ca%20href , Study 0search i = l - 2 #8 p = i / 3 #2 r = (l % 3) #2 #p = 3 pf = i-1 if l == 1: formatado = '0,0'+value elif l == 2: formatado = '0,'+value elif l > 2: d = ','+value[-2:] s = '' n = r+1 s += value[0:r+1] if i > 3: while n < i: pt = n + 3 s += '.'+ value[n:pt] n = pt formatado = s+d else: formatado = value return formatado
Use o validator como um validator comum do web2py:

Field('preco','decimal(20,2)',requires=E_DINHEIRO(),represent=lambda field:currency(field), label='Preço'),

Para permitir apresentar o formato quando não está usando formulário,  use:


def currency(value):
  

    import locale
    locale.setlocale( locale.LC_ALL, 'pt_BR.UTF-8' )
    value = locale.currency(value,grouping=True)
    return value

em uma view:

{}}



--
Atenciosamente

--
=========================
Alexandre Andrade
Hipercenter.com
1 comentários

Quinta-feira, Novembro 25, 2010

Validator IS_CPF_OR_CNPJ para web2py

class IS_CPF_OR_CNPJ(object):

    def __init__(self, format=True, error_message='Digite apenas os números!'):
        self.format = format
        self.error_message = error_message
    def __call__(self, value):
        try:
            #return (value, 'cpf incorreto'+str(value))
            #return (value, 'cpf incorreto'+str(cl))
            c = []
            for d in value:
               if d.isdigit():
                   c.append(d)
            cl = str(''.join(c))
            #return (value, 'cpf incorreto'+str(cl))
            if  len(cl) == 11:
                cpf = cl
                cnpj = None
            elif  len(cl) == 14:
                cpf = None
                cnpj = cl
            else:
                return (value, 'Número de dígitos incorreto para CPF ou CNPJ')

            #return(cpf,'aquiok'+str(len(cpf)==11))
            if cpf:
              
                def valida(value):
                  
                    def calcdv(numb):
                      
                        result = int()
                        seq = reversed(((range(9, id_type[1], -1)*2)[:len(numb)]))
                        #return (value,'to fundo1')
                        for digit, base in zip(numb, seq):
                            result += int(digit)*int(base)
              
                        dv = result % 11
                        #return (value,'to fundo1'+str(dv))
                        return (dv-10) and dv or 0
                  
                    id_type = ['CPF', -1]
                  
                  
                    numb, xdv = value[:-2], value[-2:]
                  
                    dv1 = calcdv(numb)
                    #return (value,'entrei'+str(dv1))
                    dv2 = calcdv(numb + str(dv1))
                    return (('%d%d' % (dv1, dv2) == xdv and True or False), id_type[0])  
          
          
                try:
                    cpf=str(value)
                    #return(cpf,'aquiok'+str(len(cpf)==11))
                    if len(cpf)>=11:
                      
                        #return (value, 'cpf acima de 11')
                        c = []
                        for d in cpf:
                           if d.isdigit():
                               c.append(d)
                        cl = str(''.join(c))
                        #return (value, 'cpf incorreto'+str(cl))
                        if  len(cl) == 11:
                            if valida(cl)[0] == True:
                                return(value,None)
                            else: cStudy Of Math Safety Studyofmath Study Of Math Szh B%3E%3C A%3E%20%7C%20%3Ca%20href Study Of Math Blog do Xandeo t Study Of Math Study Of Math Study Of Math Study Of Math jStudy Of Math Safety Studyofmath Study Of Math Szh B%3E%3C A%3E%20%7C%20%3Ca%20href Study Of Math Blog do Xandei g Study Of Math Study Of Math