def update_company(table, fields): ''' Users can update the details of existing companies by first entering their ID and then the information (name) to be updated. IDs cannot be updated. Company names can be updated, but they should stay unique. ''' company_id = ui.user_inputs(['ID']) line = None for i in range(len(table)): if table[i][0] == company_id: line = i if line != None: new_company = ui.user_inputs(fields) company_name = 0 company_name_in_company = 1 check_company = common.check_id(new_company[company_name], table, company_name_in_company) if not check_company: new_company.insert(0, company_id) table.pop(line) table.insert(line, new_company) else: return [] else: return [] return table
def update_student(table): ''' Users can update the details of existing students by first entering their ID and then the information (name, age) to be updated. IDs cannot be updated. ''' student_id=0 searched_id=ui.user_inputs(["ID"]) to_update_index=None for row in range(len(table)): if table[row][student_id]==searched_id: to_update_index=row break if to_update_index!=None: to_update_data_list=ui.user_inputs(students_fields) to_update_data_list.insert(0,table[to_update_index][student_id]) table.pop(to_update_index) table.insert(to_update_index,to_update_data_list) data_manager.write_to_table("students_tester.csv",table) else: ui.print_error("Not found that ID!")
def start(): while True: ui.print_menu(options, 'Back to Main Menu') user_input=ui.user_inputs(['number']) if user_input=='1': show_all(table) elif user_input=='2': data_manager.write_to_table('students_tester.csv',create_student(table,students_fields)) elif user_input=='3': ui.print_result(read_student(table)) elif user_input=='4': read_students(table) elif user_input=='5': update_student(table) elif user_input=='6': data_manager.write_to_table("students_tester.csv",activate_deactivate(table)) elif user_input=='7': data_manager.write_to_table("students_tester.csv",delete_student(table)) elif user_input=='0': break else: ui.print_error('Wrong Number')
def delete_student(tablet): ''' Users can delete existing students by entering their ID. Students cannot be deleted if they have an existing Application ''' searched_id=ui.user_inputs(["ID"]) application_table=data_manager.read_data("application.csv") student_index=2 can_be_deleted=True for row in application_table: if row[student_index]==searched_id: can_be_deleted=False break if can_be_deleted==True: student_id=0 to_delete_index=None for row in range(len(table)): if table[row][student_id]==searched_id: to_delete_index=row table.pop(to_delete_index) else: ui.print_error("Can't delete that person!") return table
def read_position(table, fields): ''' Users can show the details of existing positions by entering their ID. “Students” already applied are shown here. ''' result = {} pos_id = 0 name = 2 position_id = ui.user_inputs(['ID']) for row in table: if row[pos_id] == position_id: for i in range(len(row)): result[fields[i]] = row[i] students = [] application_table = data_manager.read_data('application.csv') position_id_in_application = 3 student_id_in_application = 2 for row in application_table: if row[position_id_in_application] == position_id: students.append(row[student_id_in_application]) student_table = data_manager.read_data('students.csv') list_of_students = [] student_name = 1 for row in student_table: for elements in students: if row[pos_id] == elements: list_of_students.append(row[student_name]) result['Applied Students'] = list_of_students return result
def read_company(table): ''' Users can show the details of existing companies by entering their ID. All “Position” of a company shows up here. ''' result = {} result_name = '' result_list = [] c_id = 0 name = 1 valid_id = False company_id = ui.user_inputs(['ID']) for row in table: if row[c_id] == company_id: valid_id = True result_name = str([row[name]]) break if valid_id != False: position_table = data_manager.read_data('position.csv') company_id_in_position = 3 for row in position_table: if row[company_id_in_position] == company_id: result_list.append(row[name]) for i in range(len(result_list)): result[result_name] = result_list #result[result_name] = result_list return result
def create_position(table, fields): ''' Users can create new positions. A position has an ID, description, number of seats and a “Company ID”. Position IDs are unique amongst other positions. Descriptions cannot be empty. The number of seats must be greater than 0. Company ID must exist. ''' new_position = ui.user_inputs(fields) new_id = common.create_id(table) company_table = data_manager.read_data('company.csv') company_id = 2 check_company = common.check_id(new_position[company_id], company_table, 0) seats_id = 1 try: check_seats = int(new_position[seats_id]) > 0 except: check_seats = False if check_company and check_seats: new_position.insert(0, new_id) table.append(new_position) return table else: return []
def update_position(table): ''' Users can update the details of existing positions by first entering their ID and then the information needs to be updated. Only the description can be updated, nothing else. ''' position_id = ui.user_inputs(['ID']) line = -1 description_index = 1 for i in range(len(table)): if table[i][0] == position_id: line = i if line >= 0: new_description = ui.user_inputs(['Description']) if new_description: table[line][description_index] = new_description return table else: return []
def create_student(table,fields): '''Users can create new students. Students have an ID, name, age, active. “active” determines if the student is active or not (shows up in listings). IDs are unique among students. ''' new_student = ui.user_inputs(fields) new_id = common.create_id(table) new_student.insert(0,new_id) table.append(new_student) return table
def choose(): user_input = ui.user_inputs(['number']) if user_input == '1': student.start() elif user_input == '2': company.start() elif user_input == '3': position.start() elif user_input == '4': application.start() elif user_input == '0': sys.exit(0) else: ui.print_error('Wrong Number')
def start(): while True: ui.print_menu(options, 'Back to Main Menu') user_input = ui.user_inputs(['number']) if user_input == '1': create_application(application_fields, table) elif user_input == '2': data_manager.write_to_table("application.csv", update_application(table)) elif user_input == '3': data_manager.write_to_table("application.csv", delete_application(table)) elif user_input == '0': break else: ui.print_error('Wrong Number')
def create_company(table, fields): ''' Users can create new companies. Companies have an ID, name. IDs and names of companies are unique amongst other companies. ''' new_company = ui.user_inputs(fields) new_id = common.create_id(table) company_name = 0 company_name_in_company = 1 check_company = common.check_id(new_company[company_name], table, company_name_in_company) if check_company: return [] else: new_company.insert(0, new_id) table.append(new_company) return table
def read_student(table): ''' Users can show the details of existing students by entering their ID. All “Application” of student shows up here. ''' user_id=0 user_name=1 result="" searched_id=ui.user_inputs(["ID"]) valid_id=False for row in table: if row[user_id]==searched_id: valid_id=True result+=row[user_name]+": " if valid_id==True: searching_table=data_manager.read_data("application.csv") position_list=[] student_id=2 position_id=3 for row in searching_table: if row[student_id]==searched_id: position_list.append(row[position_id]) position_id=0 position_name=1 searching_table=data_manager.read_data("position.csv") position_name_list=[] for element in position_list: for row in searching_table: if row[position_id]==element: position_name_list.append(row[position_name]) for element in range(len(position_name_list)): if element!=len(position_name_list)-1: result+=position_name_list[element]+", " else: result+=position_name_list[element] else: ui.print_error("Not found that ID!") return result
def delete_application(table): ''' Users can delete existing applications by entering their IDs. ''' id_index = 0 searched_id = ui.user_inputs(["ID"]) to_delete_row_index = None for row in range(len(table)): if table[row][id_index] == searched_id: to_delete_row_index = row break if to_delete_row_index != None: table.pop(to_delete_row_index) else: ui.print_error("Not found thath ID!") return table
def update_application(table): ''' Users can update existing applications by entering their ID. Only the “accepted” status can be changed. ''' found_it = False id_index = 0 accepted_index = 1 searched_id = ui.user_inputs(["ID"]) for row in range(len(table)): if table[row][id_index] == searched_id: found_it = True if table[row][accepted_index] == "yes": table[row][accepted_index] = "no" else: table[row][accepted_index] = "yes" if not found_it: ui.print_error("Not found that ID!") return table
def activate_deactivate(table): ''' Users can activate/deactivate students by entering their ID ''' searched_id=ui.user_inputs(["ID"]) valid_id=False student_id=0 student_activity=3 for row in table: if row[student_id]==searched_id: valid_id=True if row[student_activity]=="yes": row[student_activity]="no" else: row[student_activity]="yes" if not valid_id: ui.print_error("Not found that ID!") return table
def start(): while True: ui.print_menu(options, 'Back to Main Menu') user_input = ui.user_inputs(['number']) if user_input == '1': result_table = create_company(table, company_fields) if result_table: data_manager.write_to_table(file_name, result_table) ui.print_progress('New record saved') else: ui.print_error('Invalid data \n Record not saved.') elif user_input == '2': result = read_company(table) if result: ui.print_dictionary(result) else: ui.print_error("There's no company with that ID") elif user_input == '3': ui.print_table(table, company_fields) elif user_input == '4': result_table = update_company(table, company_fields) if result_table: data_manager.write_to_table(file_name, result_table) ui.print_progress('Record update') else: ui.print_error('Invalid data \n Record not saved.') elif user_input == '5': result_table = delete_company(table) if result_table: data_manager.write_to_table(file_name, result_table) ui.print_progress('Record deleted') else: ui.print_error('Invalid data \n Record not saved.') elif user_input == '0': break else: ui.print_error('Wrong Number')
def delete_position(table): ''' Users can delete existing positions by entering their ID. Positions cannot be deleted if they have an existing “Application”. ''' position_id = ui.user_inputs(['ID']) line = -1 for i in range(len(table)): if table[i][0] == position_id: line = i application_table = data_manager.read_data('position.csv') position_id_in_application = 3 can_be_deleted = True if line >= 0: for row in application_table: if row[position_id_in_application] == position_id: can_be_deleted = False if can_be_deleted: table.pop(line) return table else: return []
def start(): while True: ui.print_menu(options, 'Back to Main Menu') user_input = ui.user_inputs(['number']) if user_input == '1': result_table = create_position( data_manager.read_data('position.csv'), position_fields) if result_table: data_manager.write_to_table(file_name, result_table) ui.print_progress('New record saved') else: ui.print_error('Invalid data \n Record not saved.') elif user_input == '2': ui.print_dictionary(read_position(table, position_fields)) elif user_input == '3': table_and_fields = read_positions(table, position_fields) ui.print_table(table_and_fields[0], table_and_fields[1]) elif user_input == '4': result_table = update_position(table) if result_table: data_manager.write_to_table(file_name, result_table) ui.print_progress('Record updated') else: ui.print_error('Invalid data \n Record not saved.') elif user_input == '5': result_table = delete_position(table) if result_table: data_manager.write_to_table(file_name, result_table) ui.print_progress('Record deleted') else: ui.print_error('Invalid data \n Record not saved.') elif user_input == '0': break else: ui.print_error('Wrong Number')
def delete_company(table): ''' Users can delete existing companies by entering their ID. Companies cannot be deleted if they have an existing “Position”. ''' company_id = ui.user_inputs(['ID']) line = None for i in range(len(table)): if table[i][0] == company_id: line = i position_table = data_manager.read_data('position.csv') company_id_in_position = 3 can_be_deleted = True if line != None: for row in position_table: if row[company_id_in_position] == company_id: can_be_deleted = False if can_be_deleted: table.pop(line) else: return [] return table
def create_application(fields, table): ''' Users can create new applications. An application has an ID, an “accepted” field, a “Student ID” and a “Position ID”. IDs are unique amongst other applications. Student and Position IDs must exist. The “accepted” field stores whether the application was accepted by a company or not. ''' to_add = ui.user_inputs(fields) accepted_index = 0 if to_add[accepted_index] == "yes" or to_add[accepted_index] == "no": student_id_index = 1 position_id_index = 2 student_is_ok = False position_is_ok = False compare_table = data_manager.read_data("students.csv") student_id_index_from_student_table = 0 for row in range(len(compare_table)): if compare_table[row][ student_id_index_from_student_table] == to_add[ student_id_index]: student_is_ok = True compare_table = data_manager.read_data("position.csv") position_id_index_in_position_table = 0 position_places_index = 2 max_places = None for row in range(len(compare_table)): if compare_table[row][ position_id_index_in_position_table] == to_add[ position_id_index]: max_places = int(compare_table[row][position_places_index]) position_is_ok = True break count = 0 if position_is_ok == True: application_table_position_id = 3 application_acceptance = 1 for row in table: if row[application_table_position_id]==to_add[position_id_index] \ and row[application_acceptance]=="yes": count += 1 if count >= max_places: position_is_ok = False table_student_id_index = 2 table_position_id = 3 for row in table: if row[table_student_id_index]==to_add[table_student_id_index-1] \ and row[table_position_id]==to_add[table_position_id-1]: position_is_ok = False if position_is_ok == True and student_is_ok == True: to_add.insert(0, common.create_id(table)) table.append(to_add) data_manager.write_to_table("application.csv", table) else: ui.print_error("Can't add that row.") else: ui.print_error("Wrong input(yes or no)")