NES-Collaborate / oncologia

Aplicação requisitada para o Workshop de Soluções Matemáticas - FGV
Apache License 2.0
2 stars 1 forks source link

Validation of cpf field #4

Open Luandersonsouza opened 5 months ago

Luandersonsouza commented 5 months ago

I've made a few change this lines bellow:

cpf = StringField("CPF", validators=[DataRequired(message="O CPF é obrigatório"), self.cpf_validator])


def __verify_cpf(self):
        cpf = ''.join(filter(str.isdigit, cpf)) #Elimina caracteres não numéricos
        if len(cpf) != 11:
            return False

        def calcular_digito(cpf, peso):
        soma = sum(int(digit) * peso for digit, weight in zip(cpf, peso))
        digito = 11 - soma % 11
        return '0' if digito > 9 else str(digito)

    #dígitos verificadores
    peso1 = range(10, 1, -1)
    peso2 = range(11, 2, -1)

    dv1 = calcular_digito(cpf[:9], peso1)
    dv2 = calcular_digito(cpf[:9] + dv1, peso2)

    return cpf[-2:] == dv1 + dv2

    def __cpf_validator(self, form, field):
        if not forms.__verify_cpf(field.data):
            raise ValidationError('CPF inválido')

And i created a group of functions to verify the cpf field, tests are needed to check conflict.

felipeadeildo commented 5 months ago

Thanks for the issue, can you create a fork with the modifications and create a pull request?

This way you will appear as a collaborator into this repo...

Otherwise, i can apply the modification written by you and commit for myself.

Luandersonsouza commented 5 months ago

Certo, vou abrir o fork e vou subir o código, mas tipo chegou a testar a mudança que informei?

Em sáb., 18 de mai. de 2024 às 12:28, Felipe Adeildo < @.***> escreveu:

Thanks for the issue, can you create a fork with the modifications and create a pull request?

This way you will appear as a collaborator into this repo...

Otherwise, i can apply the modification written by you and commit for myself.

— Reply to this email directly, view it on GitHub https://github.com/NES-Collaborate/oncologia/issues/4#issuecomment-2118857925, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQ3AZQP7GU4ZHRXWTMRUQFDZC5XSPAVCNFSM6AAAAABH5AIU66VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJYHA2TOOJSGU . You are receiving this because you authored the thread.Message ID: @.***>