Ejemplo n.º 1
0
def import_process(file_name):
    cars = {}
    departments = {}
    department_names = []
    registration_numbers = []
    errors = []

    file = default_storage.open(file_name)
    decoded_file = file.read().decode("utf-8").splitlines()
    reader = csv.DictReader(decoded_file)

    for row in reader:
        car = Car(
            registration_no=row["registration_no"],
            brand=row["brand"],
            model=row["model"],
            weight=row["weight"],
            production_date=row["production_date"],
            passengers_no=row["passengers_no"],
        )
        car.department_name = row["department"]
        department_names.append(row["department"])
        registration_numbers.append(row["registration_no"])
        cars[row["registration_no"]] = car
        departments[row["registration_no"]] = row["department"]

    if departments_errors := check_departments(department_names):
        errors.append(departments_errors)