Example #1
0
    def parse(klass, row, carrier, areacode, phone_type):
        row = list(row)                                 # Make row mutable

        person = Person()
        person.name = normalize_text(row[2])

        address = Address()
        address.location = normalize_text(row[3])
        address.neighborhood = normalize_text(row[4])
        address.city = normalize_text(row[5])
        address.state = normalize_text(row[6])

        phone = Phone()
        phone.carrier = carrier
        phone.areacode = areacode
        phone.type = phone_type

        try:

            # document - try CPF
            person.document = validate_cpf(row[8][-11:])
            person.nature = Person.NATURE_CHOICES_PHYSICAL[0]

        except CPFValidationError:

            # document - try CNPJ
            person.document = validate_cnpj(row[8][-14:])
            person.nature = Person.NATURE_CHOICES_LEGAL[0]

        address.zipcode = validate_zipcode(row[7])

        phone.number = validate_phone_number(row[1])

        return klass(row, person, address, phone)