def add_new_donor_menu(): if file_handler.file_accessible(DONOR_PATH, "a"): #new donor registration actual_donor = donor_class.Donor() actual_donor.get_data_from_input() if file_handler.check_if_id_not_in_file(DONOR_PATH, actual_donor.identifier) and actual_donor.is_suitable(): file_handler.data_to_file(DONOR_PATH, actual_donor) elif not file_handler.check_if_id_not_in_file(DONOR_PATH, actual_donor.identifier): input("The donor's data is already present in the file.") else: print("Creating new data file...") donor_header = ",".join(donor_input.DonorInput.DONOR_HEADER) file_handler.create_csv_file_if_not_present(DONOR_PATH, donor_header) time.sleep(3) MainMenu().main_menu()
def file_changer_donor(Index_to_change,Row_index_to_change,Donor_file_path): lines = file_handler.read_file_content(Donor_file_path) try: if int(Index_to_change) <= 12 and int(Index_to_change) >= 1: index = int(Index_to_change) - 1 line = int(Row_index_to_change) else: return False except: return False print("Old line: {}".format(lines[line])) change = DonorInput.get_donor_data(DonorInput.DONOR_HEADER[index],'') if index == 6: if not file_handler.check_if_id_not_in_file(Donor_file_path,change): input("Id already in file.") return False split_line = lines[line].split(",") split_line[index] = change new_line = ",".join(split_line) lines[Row_index_to_change] = new_line file_handler.rewrite_file_with_data(Donor_file_path,lines) return True