def addCrewToVoyage(self, voyage): '''Adds crew to a voyage''' airplane = LL_API().getAirplanebyInsignia(voyage.getAircraftID()) airplane_type_on_voyage = airplane.get_planeTypeID() crew_on_voyage_list = voyage.getCrewOnVoyage() if 'empty' in crew_on_voyage_list[0:3]: print() CrewUI().showQualifiedCrew(voyage.getDepartureTime(), voyage.getAircraftID()) print('You must add 1 captain and 1 copilot with license for {} and 1 head flight attendant'\ .format(airplane_type_on_voyage)) print(95 * '-') print() while 'empty' in crew_on_voyage_list[0:3]: # Captain, copilot and head flight attendant must be added added at the same time # Voyage must have captain, copilot and head flight attendant crew_member = CrewUI().queryShowNotWorkingCrew() if crew_member: self.checkRank(crew_member, voyage, airplane_type_on_voyage) crew_on_voyage_list = voyage.getCrewOnVoyage() else: break if crew_member: LL_API().change_voyage(voyage) print('~' * 70) print('A captain, pilot and head flight attendant have been added to voyage {}\n'\ .format(voyage.getVoyageID())) print('~' * 70) AddExtraCrewmemberMenu().startAddExtraCrewMenu( voyage, crew_on_voyage_list) else: return elif 'empty' in crew_on_voyage_list: # If captain, copilot and head flight attendant are assigned to voyage the # option to add extra flight attendant is presented print() AddExtraCrewmemberMenu().startAddExtraCrewMenu( voyage, crew_on_voyage_list) else: print('\nVoyage is fully staffed!\n') # If voyage is fully staffed no more crewmembers can be added return
def checkRank(self, crew_member, voyage, airplane_type_on_voyage): '''Checks if rank of a crewmember, exeption raised if crewmember does not have the right rank, role or licence for the voyage posotion''' success = True try: self.addCrewMember(crew_member, voyage, airplane_type_on_voyage) # exception if pilot does not have License for assigned airplane except Exception as e: success = False print(e) input('Press any key to try continue editing voyage ').strip() if success: position = CrewUI().checkRank(crew_member) if position == 'Pilot': position = 'Copilot' print('\n' + '~' * 45) a_str = '{} - {}, {},'.format(crew_member.getName(), crew_member.getRole(), position) b_str = 'was added to voyage {}'.format(voyage.getVoyageID()) print('{:^45}'.format(a_str)) print('{:^45}'.format(b_str)) print('~' * 45 + '\n')
def startDisplayMenuWorkingCrew(self): '''Menu for displaying working/nonworking crew''' while True: print('\nWhat would you like to display?') print('-' * 45) print('1 - Working crew on a specific day') print('2 - Nonworking crew on a specific day') print('m - Back to main menu') print() selection = input('Please choose one of the above: ').strip() print() if selection == '1' or selection == '2': print('Enter the date you want to display') year_str = input('Year: ').strip() month_str = input('Month: ').strip() day_str = input('Day: ').strip() #verifies if the date is correct year_int, month_int, day_int = AirplaneLL().verifyDate( year_str, month_str, day_str) # creates datetime object from input date_datetime = datetime.datetime(year_int, month_int, day_int, 0, 0, 0).isoformat() if selection == '1': # goes to menu to show working crew on specific day return CrewUI().showWorkingCrew(date_datetime) elif selection == '2': # goes to menu to show nonworking crew on specific day return CrewUI().showNotWorkingCrew(date_datetime) elif selection == 'm': # goes back to main menu return else: print('Invalid selection')
def startSubMenuRegister(self): # Header print() print('#' * 45) print('{:^45}'.format('REGISTER')) print('#' * 45) print() while True: print('-' * 45) print('{:^45}'.format('What would you like to do?')) print('-' * 45) print() print('1 - Add new Employee') print('2 - Add new Voyage') print('3 - Add new Airplane with an existing type') print('4 - Add new Airplane Type') print('5 - Add new Destination') print('m - Main menu') print() selection = input('Please choose one of the above: ').strip() if selection == '1': # Add new employee return CrewUI().addCrew() elif selection == '2': # Add new voyage return VoyageUI().addVoyage() elif selection == '3': # Add new Airplane return AirplaneUI().addAirplane() elif selection == '4': return AirplaneUI().addAirplaneType() elif selection == '5': # Add new destination return DestinationUI().addDestination() elif selection == 'm': # Back to main menu return else: print("\nInvalid selection!\n")
def startEditEmployeeLicense(self, employee): '''Changes pilot license.''' old_license = employee.getLicense() new_license = CrewUI().getPilotLicense() print() # list of voyages employee is already assigned to voyage_id_with_pilot = self.isPilotOnFutureVoyage(employee) # if pilot is working on future voyages with old license if len(voyage_id_with_pilot) != 0: print('Pilot is assigned to future voyages') print('You must assign another pilot to voyages:') for voyage_id in voyage_id_with_pilot: print(voyage_id) # if pilot is not working on any voyages in the future else: employee.setLicense(new_license) CrewUI().changeEmployeeInfo(employee) print('License for {} has been changed from {} to {}'\ .format(employee.getName(),old_license,new_license))
def startDisplayPilots(self): '''Main display menu for pilots''' print() print('-'*45) print('{:^45}'.format('DISPLAY - Pilots')) print('-'*45) print() while True: print('What would you like to display?') print('-'*45) print('1 - Pilots with a license for a specific airplane') print('2 - All pilots sorted by license') print('m - Back to main menu') print() selection = input('Please choose one of the above: ').strip() if selection == '1': # Goes to another menu where the user can pick a license to list return DisplayMenuAirplaneType().startDisplayLicensedPilots() elif selection == '2': # List up pilots by license return CrewUI().showSortedByLicense() elif selection == 'm': # Goes back to main menu return # if none of the possible options were chosen else: print('Invalid selection')
def startDisplayLicensedPilots(self): '''Display menu for licensed pilots''' success = False airplane_types = AirplaneUI().getAirplaneTypes() while True: print('\nPlease pick one license of the following:\n') counter = 1 for airplane_type in airplane_types: print('{} - {}'.format(counter, airplane_type)) counter += 1 selection = input('\nPlease choose one of the above: ').strip() for i in range(1, counter + 1): if selection == str(i): license_ID = airplane_types[i - 1].getplaneTypeID() success = True return CrewUI().showByLicense(license_ID) if not success: print('\nInvalid selection!\n')
def startAddExtraCrewMenu(self, voyage, crew_on_voyage_list): '''Menu for adding an extra crew member''' print('\n' + '~' * 45) a_str = 'Voyage {} has enough staff!'.format(voyage.getVoyageID()) print('{:^45}'.format(a_str)) print('~' * 45 + '\n') while True: print('-' * 45) print('{:^45}'.format('Do you want to add an extra crew member?')) print('-' * 45 + '\n') print('Y - Yes') print('N - No (Go back)') selection = input( '\nPlease choose one of the above (Y/N): ').strip().lower() # add extra crew member is chosen if selection == 'y': # show list of crew that is not working on particular day CrewUI().showNotWorkingCrew(voyage.getDepartureTime()) print() if 'empty' in crew_on_voyage_list[-2:]: if 'empty' in crew_on_voyage_list[-2]: crew_member = CrewUI().queryShowNotWorkingCrew() if self.isPilot(crew_member): # pilot can not be assigned as extra crewmember continue if crew_member: if self.checkIfCrewmemberWorking( voyage, crew_member): print( 'Flight attendant is assigned to another voyage on the same date\n\ please chose another flight attendant\n') continue voyage.setFlightAttOne(crew_member) LL_API().change_voyage(voyage) crew_on_voyage_list = voyage.getCrewOnVoyage() print('\n' + '~' * 45) print('{:^45}'.format('Employee successfully added!')) print('\n' + '~' * 45) elif 'empty' in crew_on_voyage_list[-1]: crew_member = CrewUI().queryShowNotWorkingCrew() if crew_member: if self.isPilot(crew_member): continue if self.checkIfCrewmemberWorking( voyage, crew_member): print( 'Flight attendant is assigned to another voyage on the same date\n\ please chose another flight attendant\n') continue voyage.setFlightAttTwo(crew_member) LL_API().change_voyage(voyage) crew_on_voyage_list = voyage.getCrewOnVoyage() print('\n' + '~' * 45) print( '{:^45}'.format('\nEmployee successfully added!')) print( '{:^45}'.format('The voyage is fully staffed!\n')) print('\n' + '~' * 45) return else: print('\n' + '~' * 45) print('The voyage is fully staffed!') print('\n' + '~' * 45) return elif selection == 'n': return else: print('\nInvalid selection!\n')
def startSubMenuEdit(self): '''Main editing menu''' # Header print() print('#' * 45) print('{:^45}'.format('EDIT EXISTING DATA')) print('#' * 45) print() start = True while start: print('-' * 45) print('{:^45}'.format('What would you like to edit? ')) print('-' * 45) print() print('1 - Voyage') print('2 - Destination') print('3 - Employee') print('m - Main menu') print() selection = input('Please choose one of the above: ').strip() if selection == '1': # edit existing voyage EditExistingVoyage().startEditExistingVoyage() elif selection == '2': # Change destination emergency contact print() print('1 - Change emergency contact') print('2 - Change emergency phone number') print() user_selection = input( 'Please choose one of the above: ').strip() while user_selection != '1' and user_selection != '2': print('Invalid selection!') user_selection = input('Please enter 1 or 2:').strip() if user_selection == '1': # name of emergency contact changed DestinationUI().changeEmergencyContactName() elif user_selection == '2': # phone number of emergency contact changed DestinationUI().changeEmergencyContactPhoneNumber() elif selection == '3': while True: print() # Prints out information about an employee with inputted crew id crew_id = CrewUI().getPersonalID() if crew_id: crew_member_found = CrewUI().showOneCrewMember(crew_id) # Check if id is valid if crew_member_found: return EditEmployeeMenu().editSelection(crew_id) else: return elif selection == 'm': # Back to main menu return else: print("Invalid selection")
def startDisplayMenuEmployee(self): '''Main display for employees''' # banner: print() print('-' * 45) print('{:^45}'.format('DISPLAY - Employees')) print('-' * 45) print() while True: print('What would you like to display?') print('-' * 45) print('1 - All employees') print('2 - Single employee') print('3 - Pilots') print('4 - Flight attendants') print('5 - Working status by date') print('6 - Work Schedule for employee by ID') print('m - Back to main menu') selection = input('\nPlease choose one of the above: ').strip() # All employees are displayed if selection == '1': return CrewUI().showCrew() # A single employee is displayed with more percise info elif selection == '2': print() while True: crew_id = input( 'Enter the Crew members ID (SSN): ').strip() # checks if the personal ID is 10 letters and an integer try: int(crew_id) if len(crew_id) == 10: # Prints information about one crew member return CrewUI().showOneCrewMember(crew_id) else: print('\nInvalid SSN!\n') except ValueError: print('\nInvalid SSN!\n') # Goes to pilot display menu elif selection == '3': return DisplayMenuPilots().startDisplayPilots() # Shows all flight attendants elif selection == '4': return CrewUI().showAllFlightAtt() # allows user to choose date and see working status of crew on that date elif selection == '5': return DisplayMenuWorkingCrew().startDisplayMenuWorkingCrew() # allows user to see working schedule for a single crew member elif selection == '6': print() crew_id = CrewUI().getPersonalID() # Prints a work schedule for a crew member if he exists get_schedule = CrewUI().showSchedule(crew_id) if get_schedule == False: print('\nNo employee with this ID\n') else: return # Goes back to main menu elif selection == 'm': return else: print('Invalid selection') print()
def editSelection(self, crew_id): '''Redirects to UI methods based on user selection''' # employee instance found from crew id employee = LL_API().get_crew_member_by_id(crew_id) self.printEditEmployeeMenu(crew_id, employee) selection = input('Please choose one of the above: ').strip() if selection == '1': ''' The software asks for new home adress and assigns it to the owner of given ID''' new_address = CrewUI().getHomeAddress() employee.setAddress(new_address) return CrewUI().changeEmployeeInfo(employee) elif selection == '2': ''' The software asks for new phone number and assigns it to the owner of given ID''' new_phonenumber = CrewUI().getPhoneNumber() employee.setPhonenumber(new_phonenumber) return CrewUI().changeEmployeeInfo(employee) elif selection == '3': ''' The software asks for new email adress and assigns it to the owner of given ID''' new_email_address = CrewUI().getEmail() employee.setEmail(new_email_address) return CrewUI().changeEmployeeInfo(employee) elif selection == '4': ''' The software asks for new rank and assigns it to the owner of given ID''' while True: if type(employee) == Pilot: print() print('Please choose one: ') print('0 - Co-pilot') print('1 - Captain') print('m - Back to main menu') else: print() print('Please choose one: ') print('0 - Flight attendant') print('1 - Head service manager') print('m - Back to main menu') print() new_rank = input('Please choose one of the above: ').strip() if new_rank != '0' and new_rank != '1' and new_rank != 'm': print('\nInvalid rank!\n') elif new_rank == 'm': return else: employee.setRank(new_rank) CrewUI().changeEmployeeInfo(employee) return elif selection == '5': ''' The software asks for new license and assigns it to the owner of given ID''' return EditEmployeeLicense().startEditEmployeeLicense(employee) elif selection == 'm': '''user is redirected to main menu''' return else: print("\nInvalid input!\n")