Example #1
0
    def show_available_staff(form_data):
        """ Returns list of staff not flying on departure date."""

        dep_str = form_data["instance"].get_attributes()["departure"][0:10]
        departure_list = Read.departures_on_date(dep_str)

        flightID_list = []
        for departure in departure_list:
            flightID_list.append(departure.get_attributes()["flightID"])

        busy_ssn_list = []
        for flightID in flightID_list:
            crew_list = Read.flight_crew(flightID)

            for crew_row in crew_list:
                busy_ssn_list.append(crew_row.get_attributes()["ssn"])

        all_staff = Read.read_staff("valid", "True")
        data = []
        for employee in all_staff:
            if employee.get_attributes()["ssn"] not in busy_ssn_list:
                data.append(employee)

        form_data["data"] = data
        form_data["page_size"] = 7
        form_data["rtrip"] = False
        return form_data
Example #2
0
    def filter_busy_staff(display_data, busy=False):

        # If no date set, use today as starting point
        if display_data["datetime"] == "":
            today = dt.datetime.today()
            display_data["datetime"] = dt.datetime(today.year, today.month,
                                                   today.day)

        else:
            if display_data["action"] == "next_date":
                display_data["datetime"] = display_data[
                    "datetime"] + dt.timedelta(days=1)
                display_data["action"] = ""

            elif display_data["action"] == "prev_date":
                display_data["datetime"] = display_data[
                    "datetime"] - dt.timedelta(days=1)
                display_data["action"] = ""

        if busy:
            display_data["destinations"] = {}

        departure_list = Read.departures_on_date(
            display_data["datetime"].isoformat()[0:10])
        ssn_list = []
        for departure in departure_list:
            crew_list = Read.flight_crew(
                departure.get_attributes()["flightID"])

            for crew in crew_list:
                ssn_list.append(crew.get_attributes()["ssn"])

                if busy:
                    key = crew.get_attributes()["ssn"]
                    display_data["destinations"][key] = departure

        read_data = Read.read_staff("valid", "True")
        data = []
        if not busy:

            for employee in read_data:

                if employee.get_attributes()["ssn"] not in ssn_list:
                    data.append(employee)

        else:
            for employee in read_data:

                if employee.get_attributes()["ssn"] in ssn_list:
                    data.append(employee)

        return display_data, data
Example #3
0
    def paging_system(state, display_data={}, aircraft_name=""):
        """
		Creates a key,value pair in display_Data dict, key: "data", value: list of object instances.
		"""

        if state == "dest_list":
            data = Read.read_dest("valid", "True")

        elif state == "staff_list":
            data = Read.read_staff("valid", "True")

            # If only showing staff allowed to fly a certain airplane
            if aircraft_name != "":
                qualified_staff = []
                airplane_type = DBLayer.generic_search("Airplanes.csv",
                                                       "name",
                                                       aircraft_name,
                                                       result_column="type")[0]

                for employee in data:
                    aircraft_license = employee.get_attributes()["license"]

                    if aircraft_license == airplane_type:
                        qualified_staff.append(employee)

                # Only show qualified staff for given airplane type
                data = qualified_staff

        elif state == "airplane_list":
            data = Read.read_airplane("valid", "True")

        elif state == "employee_list":
            data = Read.read_staff("valid", "True")

        elif state == "non_busy_staff":
            display_data, data = BLLayer.filter_busy_staff(display_data)

        elif state == "busy_staff":
            display_data, data = BLLayer.filter_busy_staff(display_data,
                                                           busy=True)

        elif state == "rtrip_list":
            attribute_dict_list = Read.read_rtrip("valid", "True")
            data = BLLayer.create_rtrip_list(attribute_dict_list)

        elif state == "employee_schedule":
            display_data = BLLayer.create_schedule(display_data)
            display_data["page_size"] = len(display_data["data"])
            display_data["end"] = len(display_data["data"])
            return display_data

        display_data["data"] = data

        # If showing dates in pager show in weeks
        if state == "date_list":
            display_data["page_size"] = 7
            display_data["rtrip"] = False

        # Show only 4 round trips in pager
        elif state == "rtrip_list":
            display_data["page_size"] = 4
            display_data["rtrip"] = True

        # Default number of entries in pager is 5
        else:
            display_data["page_size"] = 5
            display_data["rtrip"] = False

        display_data["end"] = len(display_data["data"])

        return display_data