Ejemplo n.º 1
0
def is_omocode(root: T.Any, info: T.Any, **args: T.Dict[T.Text, T.Any]) -> bool:
    cf = args.get("cf")
    if cf:
        try:
            return codicefiscale.is_omocode(cf)
        except ValueError:
            return False
    raise ValueError("Missing argument.")
Ejemplo n.º 2
0
    def test_is_omocode(self):

        self.assertFalse(codicefiscale.is_omocode('CCCFBA85D03L219P'))
        self.assertTrue(codicefiscale.is_omocode('CCCFBA85D03L21VE'))
        self.assertTrue(codicefiscale.is_omocode('CCCFBA85D03L2MVP'))
        self.assertTrue(codicefiscale.is_omocode('CCCFBA85D03LNMVE'))
        self.assertTrue(codicefiscale.is_omocode('CCCFBA85D0PLNMVA'))
        self.assertTrue(codicefiscale.is_omocode('CCCFBA85DLPLNMVL'))
        self.assertTrue(codicefiscale.is_omocode('CCCFBA8RDLPLNMVX'))
        self.assertTrue(codicefiscale.is_omocode('CCCFBAURDLPLNMVU'))
Ejemplo n.º 3
0
def decode_fiscal_number(request):
    """
    Estrae i dati a partire dal codice fiscale
    :return: JsonResponse con statusCode e dati (in caso di successo)
    """
    cf = request.GET.get('CF').upper()
    try:
        isvalid = codicefiscale.is_valid(cf) or codicefiscale.is_omocode(cf)
        decode_cf = codicefiscale.decode(cf)
        if isvalid:
            am = AddressMunicipality.objects.filter(
                code__iexact=decode_cf['birthplace']['code']).first()
            if am:
                nation_code = 'Z000'
            else:
                nation_code = decode_cf['birthplace']['code']
                return JsonResponse({
                    'statusCode':
                    StatusCode.OK.value,
                    'codeOfNation':
                    nation_code,
                    'placeOfBirth':
                    '',
                    'countyOfBirth':
                    '',
                    'dateOfBirth':
                    decode_cf['birthdate'].strftime('%d/%m/%Y'),
                    'gender':
                    decode_cf['sex']
                })

            StatusCode_city, city = get_city_id(
                decode_cf['birthplace']['code'],
                decode_cf['birthdate'].strftime('%Y-%m-%d'))

            if StatusCode_city == 200:

                return JsonResponse({
                    'statusCode':
                    StatusCode.OK.value,
                    'codeOfNation':
                    nation_code,
                    'placeOfBirth':
                    decode_cf['birthplace']['code'],
                    'countyOfBirth':
                    city,
                    'dateOfBirth':
                    decode_cf['birthdate'].strftime('%d/%m/%Y'),
                    'gender':
                    decode_cf['sex']
                })

    except Exception as e:
        LOG.warning("Exception: {}".format(str(e)),
                    extra=set_client_ip(request))
        return JsonResponse({'statusCode': StatusCode.EXC.value})

    return JsonResponse({'statusCode': StatusCode.ERROR.value})
Ejemplo n.º 4
0
    def clean_fiscalNumber(self):
        fiscalNumber = self.cleaned_data.get('fiscalNumber').upper()
        try:
            isvalid = codicefiscale.is_valid(fiscalNumber) or codicefiscale.is_omocode(fiscalNumber)
        except Exception as e:
            LOG.warning("Warning: {}".format(str(e)), extra=set_client_ip())
            isvalid = False

        if not isvalid:
            raise ValidationError("Il codice fiscale inserito non è valido")
        return
Ejemplo n.º 5
0
    def clean_fiscalNumber(self):
        fiscalNumber = self.cleaned_data.get('fiscalNumber').upper()
        message = "Il codice fiscale inserito non è valido"
        try:
            isvalid = codicefiscale.is_valid(fiscalNumber) or codicefiscale.is_omocode(fiscalNumber)
            birth_date = codicefiscale.decode(fiscalNumber)['birthdate']
            if isvalid and calculate_age(birth_date) < 18:
                isvalid = False
                message = "Il codice fiscale inserito deve appartenere ad una persona maggiorenne"

            if isvalid and fiscalNumber in get_all_operator_cf():
                isvalid = False
                message = "Il codice fiscale inserito non deve appartenere ad un operatore/admin"

        except Exception as e:
            LOG.warning("Warning: {}".format(str(e)), extra=set_client_ip())
            isvalid = False

        if not isvalid:
            raise ValidationError(message)
        return