Exemple #1
0
def upload_csv(filename):
    """
        Adds data for customer from csv file
    """
    with open(filename, newline="", encoding="ISO-8859-1") as csvfile:
        all_customers = csv.reader(csvfile)
        header = next(all_customer, None)

        with Customer.DATABASE.atomic():  # Populates the databse with info
            Customer.insert_many(all_customers, headers).execute
Exemple #2
0
def _insert_customer_list(customer_list, database):
    '''
    Internal function to add customer list with error checking

    :param customer_list: sequence of customer dictionaries to insert
    :param database: database object for the atomic transaction
    '''
    with database.atomic():
        try:
            Customer.insert_many(customer_list).execute()
        except pw.IntegrityError as error:
            logging.error(f"Customer already exists: {str(error)}")
            raise
        else:
            LOGGER.info(f"Inserted {len(customer_list)} customer(s)")