def __init__(self, departing_flight_num="", return_flight_num="", departing_flight_departing_from="Reykjavik", departing_flight_departure_date="", departing_flight_arrival_date="", return_flight_departing_from="", return_flight_departure_date="", return_flight_arrival_date="", airplane_insignia="", captain_ssn="", copilot_ssn="", fsm_ssn="", fa_ssns=[], status="", staffed=""): self.__models_validation = Validator() self.__departing_flight_num = departing_flight_num self.__return_flight_num = return_flight_num self.__departing_flight_departing_from = departing_flight_departing_from self.__departing_flight_departure_date = departing_flight_departure_date self.__departing_flight_arrival_date = departing_flight_arrival_date self.__return_flight_departing_from = return_flight_departing_from self.__return_flight_departure_date = return_flight_departure_date self.__return_flight_arrival_date = return_flight_arrival_date self.__airplane_insignia = airplane_insignia self.__captain_ssn = captain_ssn self.__copilot_ssn = copilot_ssn self.__fsm_ssn = fsm_ssn self.__fa_ssns = fa_ssns self.__status = status self.__staffed = staffed self.__header_format_dict = { "default": self.get_model_header_default_format } self.__list_info_dict = {"default": self.get_model_list_default_info} self.__validation_dict = { self.get_destination: self.set_return_flight_departing_from, self.get_departing_flight_departure_date: self.set_departing_flight_departure_date } self.__voyage_employee_ssn_dict = { "Captain": self.get_captain_ssn, "Copilot": self.get_copilot_ssn, "Flight Service Manager": self.get_fsm_ssn, "Flight Attendant": self.get_fa_ssns }
def __init__(self, plane_type_id="", make="", model="", capacity=""): self.__model_validation = Validator() self.__plane_type_id = plane_type_id self.__make = make self.__model = model self.__capacity = capacity # Dictionary keeping all the different header formats for the destination model self.__header_format_dict = { "default": self.get_model_header_default_format } # Dictionary keeping all the different list formats for the destination model self.__list_info_dict = {"default": self.get_model_list_default_info}
def __init__(self, insignia='', make='', model='', capacity=0): self.__models_validation = Validator() self.__insignia = insignia self.__make = make self.__model = model self.__capacity = capacity # A dictionary that is used in the validate model process self.__validation_dict = {self.get_insignia: self.set_insignia} self.__status = "Not in use" self.__current_destination = "N/A" self.__flight_number = "N/A" self.__date_available = "N/A"
def __init__(self, destination_id = 0, country = '', airport = '', flight_time = '', distance = '', contact_name = '', contact_number = ''): self.__models_validation = Validator() self.__country = country self.__airport = airport self.__flight_time = flight_time self.__distance = distance self.__contact_name = contact_name self.__contact_number = contact_number self.__destination_id = destination_id # Dictionary keeping all the different header formats for the destination model self.__header_format_dict = {"default": self.get_model_header_default_format} # Dictionary keeping all the different list formats for the destination model self.__list_info_dict = {"default": self.get_model_list_default_info} # Dictionary that is used in the validate model process self.__validation_dict = {self.get_country: self.set_country, self.get_airport: self.set_airport, self.get_flight_time: self.set_flight_time, self.get_distance: self.set_distance, self.get_contact_name: self.set_contact_name, self.get_contact_number: self.set_contact_number} # List keeping the order for the creation process of the destination model self.__create_order_list = [ "country", "airport", "flight time (hours)", "distance (kilometers)", "contact name (first and last)", "contact number"] # A dictionary where the keys match the order list in order to call the correct set function self.__creation_dict = {"country": self.set_country, "airport": self.set_airport, "flight time (hours)": self.set_flight_time, "distance (kilometers)": self.set_distance, "contact name (first and last)": self.set_contact_name, "contact number": self.set_contact_number }
class Voyage(): def __init__(self, departing_flight_num="", return_flight_num="", departing_flight_departing_from="Reykjavik", departing_flight_departure_date="", departing_flight_arrival_date="", return_flight_departing_from="", return_flight_departure_date="", return_flight_arrival_date="", airplane_insignia="", captain_ssn="", copilot_ssn="", fsm_ssn="", fa_ssns=[], status="", staffed=""): self.__models_validation = Validator() self.__departing_flight_num = departing_flight_num self.__return_flight_num = return_flight_num self.__departing_flight_departing_from = departing_flight_departing_from self.__departing_flight_departure_date = departing_flight_departure_date self.__departing_flight_arrival_date = departing_flight_arrival_date self.__return_flight_departing_from = return_flight_departing_from self.__return_flight_departure_date = return_flight_departure_date self.__return_flight_arrival_date = return_flight_arrival_date self.__airplane_insignia = airplane_insignia self.__captain_ssn = captain_ssn self.__copilot_ssn = copilot_ssn self.__fsm_ssn = fsm_ssn self.__fa_ssns = fa_ssns self.__status = status self.__staffed = staffed self.__header_format_dict = { "default": self.get_model_header_default_format } self.__list_info_dict = {"default": self.get_model_list_default_info} self.__validation_dict = { self.get_destination: self.set_return_flight_departing_from, self.get_departing_flight_departure_date: self.set_departing_flight_departure_date } self.__voyage_employee_ssn_dict = { "Captain": self.get_captain_ssn, "Copilot": self.get_copilot_ssn, "Flight Service Manager": self.get_fsm_ssn, "Flight Attendant": self.get_fa_ssns } def __str__(self): return "Departing flight no: {}\nReturning flight no: {}\nDeparting from: {}\nDeparting date/time: {}\nReturning date/time: {}\nDestination: {}\nDeparting date/time: {}\nReturning date/time: {}\nAirplane insignia: {}\nCaptain SSN: {}\nCopilot SSN: {}\nFlight service manager SSN: {}\nCabin crew SSN: {}".format( self.__departing_flight_num, self.__return_flight_num, self.__departing_flight_departing_from, self.change_date_time_format( self.__departing_flight_departure_date), self.change_date_time_format(self.__departing_flight_arrival_date), self.__return_flight_departing_from, self.change_date_time_format(self.__return_flight_departure_date), self.change_date_time_format(self.__return_flight_arrival_date), self.__airplane_insignia, self.__captain_ssn, self.__copilot_ssn, self.__fsm_ssn, ", ".join(self.__fa_ssns)) def raw_info(self): true_employees = ":".join(self.__fa_ssns) return self.__departing_flight_num + "," + self.__return_flight_num + "," + self.__departing_flight_departing_from + "," + self.__departing_flight_departure_date + "," + self.__departing_flight_arrival_date + "," + self.__return_flight_departing_from + "," + self.__return_flight_departure_date + "," + self.__return_flight_arrival_date + "," + self.__airplane_insignia + "," + self.__captain_ssn + "," + self.__copilot_ssn + "," + self.__fsm_ssn + "," + true_employees + "\n" def get_validation_dict(self): return self.__validation_dict def get_departing_flight_num(self): return self.__departing_flight_num def set_departing_flight_num(self, flight_number): if self.__models_validation.validate_flight_number(flight_number): self.__departing_flight_num = flight_number return True return False def get_return_flight_num(self): return self.__return_flight_num def set_return_flight_num(self, flight_number): if self.__models_validation.validate_flight_number(flight_number): self.__return_flight_num = flight_number return True return False def set_flight_numbers(self, departing_flight_num, return_flight_num): dep_success = self.set_departing_flight_num(departing_flight_num) ret_success = self.set_return_flight_num(return_flight_num) if dep_success and ret_success: return True return False def get_departing_flight_departing_from(self): return self.__departing_flight_departing_from def set_departing_flight_departing_from(self, airport): if self.__models_validation.validate_airport(airport): self.__departing_flight_departing_from = airport return True return False def get_return_flight_departing_from(self): return self.__return_flight_departing_from def set_return_flight_departing_from(self, airport): if self.__models_validation.validate_airport(airport): self.__return_flight_departing_from = airport return True return False def get_destination(self): return self.__return_flight_departing_from def get_departing_flight_departure_date(self): return self.__departing_flight_departure_date def set_departing_flight_departure_date(self, new_departure_date): if self.__models_validation.validate_date_time(new_departure_date): self.__departing_flight_departure_date = new_departure_date return True return False def get_departing_flight_arrival_date(self): return self.__departing_flight_arrival_date def set_departing_flight_arrival_date(self, new_arrival_date): if self.__models_validation.validate_date_time(new_arrival_date): self.__departing_flight_arrival_date = new_arrival_date return True return False def get_return_flight_departure_date(self): return self.__return_flight_departure_date def set_return_flight_departure_date(self, new_departure_date): if self.__models_validation.validate_date_time(new_departure_date): self.__return_flight_departure_date = new_departure_date return True return False def get_return_flight_arrival_date(self): return self.__return_flight_arrival_date def set_return_flight_arrival_date(self, new_arrival_date): if self.__models_validation.validate_date_time(new_arrival_date): self.__return_flight_arrival_date = new_arrival_date return True return False def get_status(self): return self.__status def set_status(self, status): self.__status = status def get_staffed(self): return self.__staffed def set_staffed(self, staffed): self.__staffed = staffed def handle_key_value(self, key, value): return value(key()) def set_flight_times(self, departing_flight_arrival_date, return_flight_departure_date, return_flight_arrival_date): self.set_departing_flight_arrival_date(departing_flight_arrival_date) self.set_return_flight_departure_date(return_flight_departure_date) self.set_return_flight_arrival_date(return_flight_arrival_date) pass def get_airplane_insignia(self): return self.__airplane_insignia def set_airplane_insignia(self, new_insignia): if new_insignia != ".": if self.__models_validation.validate_airplane_insignia( new_insignia): self.__airplane_insignia = new_insignia return True return False else: self.__airplane_insignia = new_insignia return True def get_captain_ssn(self): return self.__captain_ssn def set_captain_ssn(self, new_ssn): if new_ssn != ".": if self.__models_validation.validate_employee_ssn(new_ssn): self.__captain_ssn = new_ssn return True return False else: self.__captain_ssn = new_ssn return True def get_copilot_ssn(self): return self.__copilot_ssn def set_copilot_ssn(self, new_ssn): if new_ssn != ".": if self.__models_validation.validate_employee_ssn(new_ssn): self.__copilot_ssn = new_ssn return True return False else: self.__copilot_ssn = new_ssn return True def get_fsm_ssn(self): return self.__fsm_ssn def set_fsm_ssn(self, new_ssn): if new_ssn != ".": if self.__models_validation.validate_employee_ssn(new_ssn): self.__fsm_ssn = new_ssn return True return False else: self.__fsm_ssn = new_ssn return True def get_fa_ssns(self): return self.__fa_ssns def set_fa_ssns(self, new_ssn): if type(new_ssn).__name__ == "list": for ssn in new_ssn: if ssn != ".": if not self.__models_validation.validate_employee_ssn(ssn): return False self.__fa_ssns = new_ssn return True if not self.__models_validation.validate_employee_ssn(new_ssn): return False if self.__fa_ssns[0] == '.': self.__fa_ssns[0] = new_ssn elif self.__fa_ssns[1] == '.': self.__fa_ssns[1] = new_ssn else: self.__fa_ssns.append(new_ssn) return True def get_all_required_crew_ssn(self): return [ self.get_captain_ssn(), self.get_copilot_ssn(), self.get_fsm_ssn() ] def get_voyage_employee_ssn(self, rank): return self.__voyage_employee_ssn_dict[rank]() def get_model_header_format(self, header_flag): return self.__header_format_dict[header_flag]() def get_model_list_info(self, header_flag): return self.__list_info_dict[header_flag]() def get_model_header_default_format(self): return "{:7}{:14}{:10}{:22}{:16}{:22}{:16}{:14}{:17}".format( "Index:", "Destination:", "Airplane:", "Departing date/time:", "Flight number: ", "Returning date/time:", "Flight number:", "Staffed:", "Status:") def get_model_list_default_info(self): return " {:14}{:10}{:22}{:16}{:22}{:16}{:14}{:17}|\n".format( self.get_return_flight_departing_from(), self.get_airplane_insignia( ), # we should change this to airplane type self.change_date_time_format( self.get_departing_flight_departure_date()), self.get_departing_flight_num(), self.change_date_time_format( self.get_return_flight_arrival_date()), self.get_return_flight_num(), self.get_staffed(), self.get_status()) def change_date_time_format(self, date_string): date_string = date_string[:-3].replace("T", " ") return date_string
class Destination(): def __init__(self, destination_id = 0, country = '', airport = '', flight_time = '', distance = '', contact_name = '', contact_number = ''): self.__models_validation = Validator() self.__country = country self.__airport = airport self.__flight_time = flight_time self.__distance = distance self.__contact_name = contact_name self.__contact_number = contact_number self.__destination_id = destination_id # Dictionary keeping all the different header formats for the destination model self.__header_format_dict = {"default": self.get_model_header_default_format} # Dictionary keeping all the different list formats for the destination model self.__list_info_dict = {"default": self.get_model_list_default_info} # Dictionary that is used in the validate model process self.__validation_dict = {self.get_country: self.set_country, self.get_airport: self.set_airport, self.get_flight_time: self.set_flight_time, self.get_distance: self.set_distance, self.get_contact_name: self.set_contact_name, self.get_contact_number: self.set_contact_number} # List keeping the order for the creation process of the destination model self.__create_order_list = [ "country", "airport", "flight time (hours)", "distance (kilometers)", "contact name (first and last)", "contact number"] # A dictionary where the keys match the order list in order to call the correct set function self.__creation_dict = {"country": self.set_country, "airport": self.set_airport, "flight time (hours)": self.set_flight_time, "distance (kilometers)": self.set_distance, "contact name (first and last)": self.set_contact_name, "contact number": self.set_contact_number } def __str__(self): return "Country: {:>2}\nAirport: {:>2}\nFlight time (hours): {:>2}\nDistance (kilometers): {:>2}\nContact name: {:>2}\nContact number: {:>2}".format(self.__country, self.__airport, self.__flight_time, self.__distance, self.__contact_name, self.__contact_number) def get_creation_process(self): return self.__create_order_list, self.__creation_dict def get_model_header_format(self, header_flag): '''Takes a header flag as an argument and uses the dictionary to return the correct format back''' return self.__header_format_dict[header_flag]() def get_model_list_info(self, header_flag): '''Takes a header flag as an argument and uses the dictionary to return the correct format back''' return self.__list_info_dict[header_flag]() def get_model_header_default_format(self): '''Default format for displaying the destination model header''' return "{:10}{:20}{:17}{:20}{:15}{:22}{:34}".format("Index:", "Country:", "Airport:", "Flight time:", "Distance:", "Contact name:", "Contact number:") def get_model_list_default_info(self): '''Default format for displaying the destination model in a list''' returnObject = (" {:20}{:17}{:20}{:15}{:22}{:34}|\n".format( self.get_country(), self.get_airport(), self.get_flight_time(), self.get_distance(), self.get_contact_name(), self.get_contact_number())) return returnObject def raw_info(self): '''A function that returns a string in the format that the CSV document needs before writing''' return self.__country + "," + self.__airport + "," + self.__flight_time + "," + self.__distance + \ "," + self.__contact_name + "," + self.__contact_number + "," + self.__destination_id + "\n" def get_validation_dict(self): return self.__validation_dict def get_create_order_list(self): return self.__create_order_list def handle_key_value(self, key, value): '''A special function to handle the validate model function in the ModelAPI for validating the model''' return value(key()) def get_country(self): '''test ''' return self.__country def set_country(self, new_country): if self.__models_validation.validate_country(new_country): self.__country = new_country return True return False def get_airport(self): return self.__airport def set_airport(self, new_airport): if self.__models_validation.validate_airport(new_airport): self.__airport = new_airport return True return False def get_flight_time(self): return self.__flight_time def set_flight_time(self, new_flight_time): if self.__models_validation.validate_flight_time(new_flight_time): self.__flight_time = new_flight_time return True else: return False def get_distance(self): return self.__distance def set_distance(self, new_distance): if self.__models_validation.validate_distance(new_distance): self.__distance = new_distance return True else: return False def get_contact_name(self): return self.__contact_name def set_contact_name(self, new_contact_name): if self.__models_validation.validate_contact_name(new_contact_name): self.__contact_name = new_contact_name return True else: return False def get_contact_number(self): return self.__contact_number def set_contact_number(self, new_contact_number): if self.__models_validation.validate_contact_number(new_contact_number): self.__contact_number = new_contact_number return True else: return False def get_destination_id(self): return self.__destination_id def set_destination_id(self, new_id): if self.__models_validation.validate_id(new_id): self.__destination_id = new_id return True return False
def __init__(self, name='', ssn='', address='', home_num=0, mobile_num=0, email='', title='', rank='', licence=''): self.__models_validation = Validator() self.__name = name self.__ssn = ssn self.__address = address self.__home_num = home_num self.__mobile_num = mobile_num self.__email = email self.__title = title self.__rank = rank self.__licence = "N/A" self.__availability = "" self.__current_voyage = "" self.__current_destination = "" self.__current_flight_number = "" # Dictionary keeping all the different header formats for the employee model self.__header_format_dict = { "default": self.get_model_header_default_format, "date": self.get_model_header_date_format, "aircraft": self.get_model_header_aircraft_format } # Dictionary keeping all the different list formats for the employee model self.__list_info_dict = { "default": self.get_model_list_default_info, "date": self.get_model_list_date_info, "aircraft": self.get_model_list_aircraft_info } # Dictionary that is used in the validate model process self.__validation_dict = { self.get_name: self.set_name, self.get_ssn: self.set_ssn, self.get_address: self.set_address, self.get_home_num: self.set_home_num, self.get_mobile_num: self.set_mobile_num, self.get_title: self.set_title, self.get_rank: self.set_rank } # List keeping the order for the creation process of the pilot employee model self.__create_pilot_order_list = [ 'employee name (first and last)', 'ssn', 'home address', 'phone number', 'mobile number', 'rank (Captain or Copilot)' ] # A dictionary where the keys match the order list in order to call the correct set function self.__creation_pilot_dict = { "employee name (first and last)": self.set_name, "ssn": self.set_ssn, "home address": self.set_address, "phone number": self.set_home_num, "mobile number": self.set_mobile_num, "rank (Captain or Copilot)": self.set_rank_creation_process } # List keeping the order for the creation process of the cabincrew employee model self.__create_cabincrew_order_list = [ 'employee name (first and last)', 'ssn', 'home address', 'phone number', 'mobile number', 'rank (Flight Service Manager or Flight Attendant)' ] # A dictionary where the keys match the order list in order to call the correct set function self.__creation_cabincrew_dict = { "employee name (first and last)": self.set_name, "ssn": self.set_ssn, "home address": self.set_address, "phone number": self.set_home_num, "mobile number": self.set_mobile_num, "rank (Flight Service Manager or Flight Attendant)": self.set_rank_creation_process } # A list keeping the order for editing the model it matches the edit_dict self.__edit_order_list = [ 'home address', 'phone number', 'mobile number', "title", "rank" ] # A dict that the key would be a user input to call the correct set function matching the edit order list self.__edit_dict = { 1: self.set_address, 2: self.set_home_num, 3: self.set_mobile_num, 4: self.set_title, 5: self.set_rank, 6: self.set_licence }
class Employee(): def __init__(self, name='', ssn='', address='', home_num=0, mobile_num=0, email='', title='', rank='', licence=''): self.__models_validation = Validator() self.__name = name self.__ssn = ssn self.__address = address self.__home_num = home_num self.__mobile_num = mobile_num self.__email = email self.__title = title self.__rank = rank self.__licence = "N/A" self.__availability = "" self.__current_voyage = "" self.__current_destination = "" self.__current_flight_number = "" # Dictionary keeping all the different header formats for the employee model self.__header_format_dict = { "default": self.get_model_header_default_format, "date": self.get_model_header_date_format, "aircraft": self.get_model_header_aircraft_format } # Dictionary keeping all the different list formats for the employee model self.__list_info_dict = { "default": self.get_model_list_default_info, "date": self.get_model_list_date_info, "aircraft": self.get_model_list_aircraft_info } # Dictionary that is used in the validate model process self.__validation_dict = { self.get_name: self.set_name, self.get_ssn: self.set_ssn, self.get_address: self.set_address, self.get_home_num: self.set_home_num, self.get_mobile_num: self.set_mobile_num, self.get_title: self.set_title, self.get_rank: self.set_rank } # List keeping the order for the creation process of the pilot employee model self.__create_pilot_order_list = [ 'employee name (first and last)', 'ssn', 'home address', 'phone number', 'mobile number', 'rank (Captain or Copilot)' ] # A dictionary where the keys match the order list in order to call the correct set function self.__creation_pilot_dict = { "employee name (first and last)": self.set_name, "ssn": self.set_ssn, "home address": self.set_address, "phone number": self.set_home_num, "mobile number": self.set_mobile_num, "rank (Captain or Copilot)": self.set_rank_creation_process } # List keeping the order for the creation process of the cabincrew employee model self.__create_cabincrew_order_list = [ 'employee name (first and last)', 'ssn', 'home address', 'phone number', 'mobile number', 'rank (Flight Service Manager or Flight Attendant)' ] # A dictionary where the keys match the order list in order to call the correct set function self.__creation_cabincrew_dict = { "employee name (first and last)": self.set_name, "ssn": self.set_ssn, "home address": self.set_address, "phone number": self.set_home_num, "mobile number": self.set_mobile_num, "rank (Flight Service Manager or Flight Attendant)": self.set_rank_creation_process } # A list keeping the order for editing the model it matches the edit_dict self.__edit_order_list = [ 'home address', 'phone number', 'mobile number', "title", "rank" ] # A dict that the key would be a user input to call the correct set function matching the edit order list self.__edit_dict = { 1: self.set_address, 2: self.set_home_num, 3: self.set_mobile_num, 4: self.set_title, 5: self.set_rank, 6: self.set_licence } def raw_info(self): '''A function that returns a string in the format that the CSV document needs before writing''' return self.__ssn + "," + self.__name + "," + str(self.__address) + "," + str(self.__home_num) + "," + \ str(self.__mobile_num) + "," + self.__email + "," + \ self.__title + "," + self.__rank + "," + self.__licence + "\n" def __str__(self): return_str = "Name: {:>2} \nSSN: {:>2} \nAddress: {:>2} \nPhone number: {:>2} \nMobile number: {:>2} \nEmail: {:>2} \nTitle: {:>2} \nRank: {:>2}"\ .format(self.__name, self.__ssn, self.__address, self.__home_num, self.__mobile_num, self.__email, self.__title, self.__rank) if self.__title == "Pilot": return_str += "\nLicence: {}".format(self.__licence) return return_str def get_current_flight_number(self): return self.__current_flight_number def set_current_flight_number(self, new): self.__current_flight_number = new def get_current_voyage(self): return self.__current_voyage def set_current_voyage(self, new_voyage): self.__current_voyage = new_voyage def set_current_destination(self, new): self.__current_destination = new def get_current_destination(self): return self.__current_destination def set_rank_creation_process(self, new_rank): title = self.get_title() if title == "Pilot": if self.__models_validation.validate_pilot_rank(new_rank): self.__rank = new_rank return True elif title == "Cabincrew": if self.__models_validation.validate_cabincrew_rank(new_rank): self.__rank = new_rank return True return False def set_availability(self, new): self.__availability = new def get_availability(self): return self.__availability def get_creation_process(self): title = self.get_title() if title == "Pilot": return self.__create_pilot_order_list, self.__creation_pilot_dict elif title == "Cabincrew": return self.__create_cabincrew_order_list, self.__creation_cabincrew_dict def get_edit_dict(self): return self.__edit_dict def get_validation_dict(self): return self.__validation_dict def get_edit_order_list(self): return self.__edit_order_list def get_name(self): return self.__name def set_name(self, new_name): if self.__models_validation.validate_employee_name(new_name): self.__name = new_name return True return False def get_ssn(self): return self.__ssn def set_ssn(self, new_ssn): if self.__models_validation.validate_employee_ssn(new_ssn): self.__ssn = new_ssn return True return False def get_address(self): return self.__address def set_address(self, new_address): if self.__models_validation.validate_employee_address(new_address): self.__address = new_address return True return False def get_home_num(self): return self.__home_num def set_home_num(self, new_home_num): if self.__models_validation.validate_home_number(new_home_num): self.__home_num = new_home_num return True return False def get_mobile_num(self): return self.__mobile_num def set_mobile_num(self, new_mobile_num): if self.__models_validation.validate_mobile_number(new_mobile_num): self.__mobile_num = new_mobile_num return True return False def get_email(self): return self.__email def set_email(self, new_email): if self.__models_validation.validate_email(new_email): self.__email = new_email return True return False def get_title(self): return self.__title def set_title(self, new_title): self.__title = new_title return True def get_rank(self): return self.__rank def set_rank(self, new_rank): self.__rank = new_rank return True def get_licence(self): return self.__licence def set_licence(self, new_licence): self.__licence = new_licence return True def handle_key_value(self, key, value): '''A special function to handle the validate model function in the ModelAPI for validating the model''' return value(key()) def get_model_header_format(self, header_flag): '''Takes a header flag as an argument and uses the dictionary to return the correct format back''' return self.__header_format_dict[header_flag]() def get_model_header_default_format(self): '''Default format for displaying the employee model header''' return "{:8}{:24}{:14}{:18}{:15}{:15}{:34}{:10}".format\ ("Index: ", "Name:", "SSN:", "Address:", "Phone number:", "Mobile number:", "Email:", "Title:") def get_model_header_date_format(self): '''Date format for displaying the employee model header''' return "{:8}{:22}{:18}{:15}{:25}{:35}{:15}".format\ ("Index:", "Name:", "Mobile number:", "Title:", "Current status:","Voyage info:", "Flight number:") def get_model_header_aircraft_format(self): '''Aircraft format for displaying the employee model header''' return "{:10}{:22}{:17}{:19}{:20}{:14}{:36}".format\ ("Index:", "Name:", "SSN:", "Address:", "Mobile number:", "Title:", "Licence:") def get_model_list_info(self, header_flag): '''Takes a header flag as an argument and uses the dictionary to return the correct format back''' return self.__list_info_dict[header_flag]() def get_model_list_date_info(self): '''Date format for displaying the employee model in a list''' returnObject = (" {:22}{:18}{:15}{:25}{:35}{:15}|\n".format( self.get_name(), self.get_mobile_num(), self.get_title(), self.get_current_destination(), self.get_current_voyage(), self.get_current_flight_number())) return returnObject def get_model_list_default_info(self): '''Default format for displaying the employee model in a list''' returnObject = (" {:24}{:14}{:18}{:15}{:15}{:34}{:10}|\n".format( self.get_name(), self.get_ssn(), self.get_address(), self.get_home_num(), self.get_mobile_num(), self.get_email(), self.get_title())) return returnObject def get_model_list_aircraft_info(self): '''Aircraft format for displaying the employee model in a list''' returnObject = (" {:22}{:17}{:19}{:20}{:14}{:36}|\n".format( self.get_name(), self.get_ssn(), self.get_address(), self.get_mobile_num(), self.get_title(), self.get_licence())) return returnObject
class AirplaneType(): def __init__(self, plane_type_id="", make="", model="", capacity=""): self.__model_validation = Validator() self.__plane_type_id = plane_type_id self.__make = make self.__model = model self.__capacity = capacity # Dictionary keeping all the different header formats for the destination model self.__header_format_dict = { "default": self.get_model_header_default_format } # Dictionary keeping all the different list formats for the destination model self.__list_info_dict = {"default": self.get_model_list_default_info} def get_model_header_format(self, header_flag): '''Takes a header flag as an argument and uses the dictionary to return the correct format back''' return self.__header_format_dict[header_flag]() def get_model_list_info(self, header_flag): '''Takes a header flag as an argument and uses the dictionary to return the correct format back''' return self.__list_info_dict[header_flag]() def get_model_header_default_format(self): '''Default format for displaying the destination model header''' return "{:10}{:20}{:17}{:20}{:71}".format("Index:", "Airplane type:", "Make:", "Model:", "Capacity:") def get_model_list_default_info(self): '''Default format for displaying the destination model in a list''' returnObject = (" {:20}{:17}{:20}{:71}|\n".format( self.get_plane_type_id(), self.get_make(), self.get_model(), self.get_capacity())) return returnObject def raw_info(self): '''A function that returns a string in the format that the CSV document needs before writing''' return str(self.__plane_type_id) + "," + str(self.__make) + "," + str( self.__model) + "," + str(self.__capacity) def __str__(self): return "Airplane type {:>2} \nMake: {:>2} \nModel: {:>2} \nCapacity: {:>2}".format( self.__plane_type_id, self.__make, self.__model, self.__capacity) def get_plane_type_id(self): return self.__plane_type_id def set_plane_type_id(self, plane_type_id): if self.__model_validation.validate_airplane_typeid(plane_type_id): self.__plane_type_id = plane_type_id return True else: return False def get_make(self): return self.__make def set_make(self, make): if self.__model_validation.validate_airplane_make(make): self.__make = make return True else: return False def get_model(self): return self.__model def set_model(self, model): if self.__model_validation.validate_airplane_model(model): self.__model = model return True else: return False def get_capacity(self): return self.__capacity def set_capacity(self, capacity): if self.__model_validation.validate_airplane_capacity(str(capacity)): self.__capacity = capacity return True else: return False
class Airplane(): def __init__(self, insignia='', make='', model='', capacity=0): self.__models_validation = Validator() self.__insignia = insignia self.__make = make self.__model = model self.__capacity = capacity # A dictionary that is used in the validate model process self.__validation_dict = {self.get_insignia: self.set_insignia} self.__status = "Not in use" self.__current_destination = "N/A" self.__flight_number = "N/A" self.__date_available = "N/A" def __str__(self): return "Insignia: {:>2}\nMake: {:>2}\nModel: {:>2}\nMaximum seats: {:>2}".format( self.__insignia, self.__make, self.__model, self.__capacity) def raw_info(self): '''A function that returns a string in the format that the CSV document needs before writing''' return "NA" + self.__make + self.__model + "," + self.__insignia + "\n" def get_validation_dict(self): return self.__validation_dict def set_status(self, status): self.__status = status def get_status(self): return self.__status def set_current_destination(self, destination): self.__current_destination = destination def get_current_destination(self): return self.__current_destination def set_flight_number(self, flight_number): self.__flight_number = flight_number def get_flight_number(self): return self.__flight_number def set_date_available(self, date): self.__date_available = date def get_date_available(self): return self.__date_available def handle_key_value(self, key, value): '''A special function to handle the validate model function in the ModelAPI for validating the model''' return value(key()) def get_insignia(self): return self.__insignia def set_insignia(self, new_insignia): if self.__models_validation.validate_airplane_insignia(new_insignia): self.__insignia = new_insignia return True else: return False def get_make(self): return self.__make def set_make(self, new_make): if self.__models_validation.validate_airplane_make(new_make): self.__make = new_make return True else: return False def get_model(self): return self.__model def set_model(self, new_model): if self.__models_validation.validate_airplane_model(new_model): self.__model = new_model return True else: return False def get_capacity(self): return self.__capacity def set_capacity(self, new_capacity): if self.__models_validation.validate_airplane_capacity(new_capacity): self.__capacity = new_capacity return True else: return False def change_date_time_format(self, date_string): if date_string != "N/A": date_string = date_string[:-3].replace("T", " ") return date_string def get_model_header_format(self, header_flag): '''The default header format for displaying airplanes in a list''' return "{:10}{:14}{:12}{:12}{:14}{:19}{:17}{:17}{:23}".format( "Index: ", "Insignia:", "Make:", "Model:", "Capacity:", "Status:", "Destination:", "Flight number:", "Date/time available:") def get_model_list_info(self, header_flag): '''The default format for displaying a list of airplanes''' returnObject = " {:14}{:12}{:12}{:14}{:19}{:17}{:17}{:23}|\n".format( self.get_insignia(), self.get_make(), self.get_model(), self.get_capacity(), self.get_status(), self.get_current_destination(), self.get_flight_number(), self.change_date_time_format(self.get_date_available())) return returnObject