def __call__(self, value, *args, **kw):
        cpf = value
        cpf = ''.join([c for c in value if c.isdigit()])

        if len(cpf) != 11:
            return _(u"CPF precisa ter 11 dígitos.")
        elif len(cpf)==11:
            vtemp = [int(cpf[:1]) for i in list(cpf)]
            cpf2 = [int(i) for i in list(cpf)]
            if cpf2 == vtemp:
                return _(u"CPF inválido.")

            tmp = cpf[:9]
            ltmp = [int(i) for i in list(tmp)]

            while len(ltmp) < 11:
                R = sum(map(lambda(i, v): (len(ltmp)+1-i)*v,
                                         enumerate(ltmp))) % 11

                if R > 1:
                    f = 11 - R
                else:
                    f = 0
                ltmp.append(f)

            if cpf2 != ltmp:
                return _(u"O dígito verificador do CPF não confere.")
        return True
 def __call__(self, value, *args, **kw):
     digits = [int(c) for c in value if c.isdigit()]
     if len(digits) != 14:
         return _(u"O CNPJ deve ter 14 dígitos.")
     cnpj = digits[:12]
     prod = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
     while len(cnpj) < 14:
         r = sum([x*y for (x, y) in zip(cnpj, prod)]) % 11
         if r > 1:
             f = 11 - r
         else:
             f = 0
         cnpj.append(f)
         prod.insert(0, 6)
     return ((cnpj == digits) and True) or _(u"O CNPJ informado é inválido.")
 def __call__(self, value, *args, **kw):
     digits = [int(c) for c in value if c.isdigit()]
     if len(digits) != 14:
         return _(u"O CNPJ deve ter 14 dígitos.")
     cnpj = digits[:12]
     prod = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
     while len(cnpj) < 14:
         r = sum([x*y for (x, y) in zip(cnpj, prod)])%11
         if r > 1:
             f = 11 - r
         else:
             f = 0
         cnpj.append(f)
         prod.insert(0, 6)
     return ((cnpj == digits) and True) or \
             _(u"O CNPJ informado é inválido.")
    def __call__(self, value, *args, **kw):

        if value.startswith('+'):
            return _(u"Telefone inválido")
        phone = ''.join([c for c in value if c.isdigit()])
        len_phone = len(phone)
        status = False
#        import pdb;pdb.set_trace()
        if phone.startswith('0'):
            if self.validate_cng(phone[:4]) and (len_phone in [10, 11]):
                status = True
        elif self.validate_ddd(phone[:2]) and (len_phone in [9, 10]):
            status = True
        elif (self.validate_ddd(phone[:2])) and (phone[:2] == '11'):
            if (len_phone == 11) and  (phone[2] == '9'):
                # validate new cellphones
                status = True

        return status or _(u"Telefone inválido")
    def __call__(self, value, *args, **kw):
        status = False
        if value.isdigit():
            phone = value
            ddd = phone[:2]
            len_phone = len(phone)

            if phone.startswith('0'):
                if self.validate_cng(phone[:4]) and len_phone in [10, 11]:
                    status = True
            if self.validate_ddd(ddd):
                if len_phone in [9, 10]:
                    status = True
                if len_phone == 11 and ddd in DDD_NINTH_DIGIT:
                    status = True
        return status or _(u"Telefone inválido")
    def __call__(self, value, *args, **kw):
        cep = ''.join([c for c in value if c.isdigit()])

        if not(len(cep)==8):
            return _(u"O cep informado é inválido.")
        return True
                R = sum(map(lambda(i, v): (len(ltmp)+1-i)*v,
                                         enumerate(ltmp))) % 11

                if R > 1:
                    f = 11 - R
                else:
                    f = 0
                ltmp.append(f)

            if cpf2 != ltmp:
                return _(u"O dígito verificador do CPF não confere.")
        return True


listValidators.append(ValidadorCPF('isCPF',
                                   title=_(u'Validator de CPF'),
                                   description=''))


class ValidadorCNPJ:
    """
    Validador para verificar se o CNPJ informado e valido.
    Baseado em http://www.pythonbrasil.com.br/moin.cgi/VerificadorDeCnpj
    """

    if USE_BBB_VALIDATORS:
        __implements__ = (ivalidator, )
    else:
        implements(IValidator)

    def __init__(self, name, title='', description=''):
from AccessControl import ClassSecurityInfo
from Products.Archetypes import atapi

from Products.BrFieldsAndWidgets.content.BrFieldsAndWidgets import CEPField
from Products.BrFieldsAndWidgets.content.BrFieldsAndWidgets import CEPWidget

from Products.BrFieldsAndWidgets import MessageFactory as _


schema = atapi.Schema((
    atapi.StringField(
        name='logradouro',
        widget=atapi.StringWidget(
            size="30",
            visible={'view': 'invisible', 'edit': 'visible'},
            label=_(u'Logradouro'),
            description=_(u'Exemplo: Rua Mourato Coelho'),
        ),
        required=True,
        schemata="Address"
    ),

    atapi.StringField(
        name='numero',
        widget=atapi.StringWidget(
            size="7",
            visible={'view': 'invisible', 'edit': 'visible'},
            label=_(u'Número'),
            description=_(u'Exemplo: 12'),
        ),
        required=True,
Beispiel #9
0
from Products.Archetypes import atapi

from Products.BrFieldsAndWidgets.content.BrFieldsAndWidgets import CEPField
from Products.BrFieldsAndWidgets.content.BrFieldsAndWidgets import CEPWidget

from Products.BrFieldsAndWidgets import MessageFactory as _

schema = atapi.Schema((
    atapi.StringField(name='logradouro',
                      widget=atapi.StringWidget(
                          size="30",
                          visible={
                              'view': 'invisible',
                              'edit': 'visible'
                          },
                          label=_('Logradouro'),
                          description=_('Exemplo: Rua Mourato Coelho'),
                      ),
                      required=True,
                      schemata="Address"),
    atapi.StringField(name='numero',
                      widget=atapi.StringWidget(
                          size="7",
                          visible={
                              'view': 'invisible',
                              'edit': 'visible'
                          },
                          label=_('Número'),
                          description=_('Exemplo: 12'),
                      ),
                      required=True,
            ltmp = [int(i) for i in list(tmp)]

            while len(ltmp) < 11:
                R = sum(map(lambda(i, v): (len(ltmp)+1-i)*v, enumerate(ltmp))) % 11

                if R > 1:
                    f = 11 - R
                else:
                    f = 0
                ltmp.append(f)

            if cpf2 != ltmp:
                return _(u"O dígito verificador do CPF não confere.")
        return True

listValidators.append(ValidadorCPF('isCPF', title=_(u'Validator de CPF'), description=''))


class ValidadorCNPJ:
    """
    Validador para verificar se o CNPJ informado e valido.
    Baseado em http://www.pythonbrasil.com.br/moin.cgi/VerificadorDeCnpj.
    """

    if USE_BBB_VALIDATORS:
        __implements__ = (ivalidator, )
    else:
        implements(IValidator)

    def __init__(self, name, title='', description=''):
        self.name = name