Exemplo n.º 1
0
 def __init__(self):
     """
     Creates application object.
     """
     self.is_running = True
     self.menu = None
     self.user_input = UserInput()
     self.view = View()
     self.malopolska_data_file_path = "application/data/malopolska.csv"
     self.obszar_controller = Obszar_administracyjnyController(
         self.user_input, self.view)
Exemplo n.º 2
0
 def __init__(self):
     """
     Creates application obj.
     """
     self.is_running = True
     self.session = {"logged_user": None}
     self.menu = None
     self.view = View()
     self.user_input = UserInput(self.view)
     self.codecooler_data_file_path = "application/data/codecoolers_data.csv"
     self.attendances_data_file_path = "application/data/attendance.csv"
     self.assignments_data_file_path = "application/data/assignments.csv"
     self.submissions_data_file_path = "application/data/submissions.csv"
Exemplo n.º 3
0
def get_courier(courier_id):
    """
    Returns information of the courier with ID from input.
    :param courier_id: ID of the existing courier.
    Information about the courier with this ID will be included to the response.
    :return: The result of the operation (code 200, 400, or 404) with
    information about the courier with ID from input.
    """
    try:
        courier_data = model.get_courier_full_data(courier_id)
        return View.send_courier_full_info(courier_data)
    except WrongCourierData as e:
        return View.send_couriers_bad_request(e.args[0])
    except DataNotFound as e:
        return View.send_couriers_bad_request(e.args[0], code=404)
def post_couriers():
    """
    Inserts couriers from request to the database.
    :return: The result of operation (code 201 or 400).
    """
    try:
        json = validate_and_return_json()
        if "data" not in json:
            return View.send_incorrect_json_bad_request()

        ids = model.create_couriers(json["data"])
        return View.send_couriers_created(ids)
    except WrongCourierData as e:
        return View.send_couriers_bad_request(e.args[0])
    except MissingID as e:
        return View.send_error_missing_id(e.args[0], "courier")
    except WrongJSONRequest:
        return View.send_incorrect_json_bad_request()
Exemplo n.º 5
0
def post_orders_complete():
    """
    Makes the order completed.
    :return: The result of the operation (code 200 or 400).
    """
    try:
        json = validate_and_return_json()
        if ("courier_id" or "order_id" or "complete_time") not in json:
            return View.send_incorrect_json_bad_request()

        model.complete_order(json)
        return View.send_order_complete(json["order_id"])
    except (DataNotFound, WrongOrderData) as e:
        return View.send_orders_bad_request(e.args[0])
    except WrongCourierData as e:
        return View.send_couriers_bad_request(e.args[0])
    except WrongJSONRequest:
        return View.send_incorrect_json_bad_request()
Exemplo n.º 6
0
def post_orders_assign():
    """
    Assigns orders that match the courier's data.
    :return: The result of the operation (code 200 or 400)
    with order IDs corresponding to the courier data.
    """
    try:
        json = validate_and_return_json()
        if "courier_id" not in json:
            return View.send_error_missing_id("No parameter \"courier_id\"",
                                              "order")

        order_ids, assign_time = model.assign_order(
            model.get_courier(courier_id=json['courier_id']))
        return View.send_orders_assign(order_ids, assign_time)
    except (WrongCourierData, DataNotFound) as e:
        return View.send_couriers_bad_request(e.args[0])
    except WrongOrderData as e:
        return View.send_orders_bad_request(e.args[0])
    except WrongJSONRequest:
        return View.send_incorrect_json_bad_request()
Exemplo n.º 7
0
class Application:
    """
    Creates Application object.

    Class attributes:
        options: list

    Omstamce attributes:
        is running: bool
        menu: None/Menu obj
        user_input: UserInput obj
        view: View obj
        malopolska_data_file_path: str
    """
    options = [
        'List statistics', 'Display 3 cities with the longest names',
        'Display county\'s name with the largest number of communities',
        'Display locations, that belong to more than one category',
        'Advanced search', 'Exit program'
    ]

    def __init__(self):
        """
        Creates application object.
        """
        self.is_running = True
        self.menu = None
        self.user_input = UserInput()
        self.view = View()
        self.malopolska_data_file_path = "application/data/malopolska.csv"
        self.obszar_controller = Obszar_administracyjnyController(
            self.user_input, self.view)

    def handle_menu(self):
        """
        Shows menu.
        """
        self.view.show_menu_option(self.options)
        user_option = self.user_input.get_option(self.options)
        if user_option == 'List statistics':
            self.view.list_statistics()
            self.user_input.get_anykey()
        elif user_option == 'Display 3 cities with the longest names':
            self.view.cities_longest_names()
            self.user_input.get_anykey()
        elif user_option == 'Display county\'s name with the largest number of communities':
            self.view.special_message()
            self.user_input.get_anykey()
        elif user_option == 'Display locations, that belong to more than one category':
            self.view.locations_repeated()
            self.user_input.get_anykey()
        elif user_option == 'Advanced search':
            self.view.special_message()
            self.user_input.get_anykey()
        elif user_option == 'Exit program':
            self.is_running = False
            return

    def run(self):
        """
        Entry method for the main module which read csv file at the beginning.
        """
        Program.read_obszary_administracyjne_from_csv(
            self.malopolska_data_file_path)

        while self.is_running:
            self.handle_menu()
Exemplo n.º 8
0
class Application:
    """
    Creates application obj.
    Class attributes:
    roles: dict
    options: list

    Instance attributes:
    is_running: bool
    session: dict
    menu: None/Menu obj
    user_input: UserInput obj
    view: View obj
    codecooler_data_file_path: str
    attendances_data_file_path: str
    assignments_data_file_path: str
    submissions_data_file_path: str
    """

    roles = {
        "Manager": ManagerMenu,
        "Staff": StaffMenu,
        "Mentor": MentorMenu,
        "Student": StudentMenu
    }

    options = ["log in", "exit"]

    def __init__(self):
        """
        Creates application obj.
        """
        self.is_running = True
        self.session = {"logged_user": None}
        self.menu = None
        self.view = View()
        self.user_input = UserInput(self.view)
        self.codecooler_data_file_path = "application/data/codecoolers_data.csv"
        self.attendances_data_file_path = "application/data/attendance.csv"
        self.assignments_data_file_path = "application/data/assignments.csv"
        self.submissions_data_file_path = "application/data/submissions.csv"

    def handle_login(self):
        """
        Enables to log in or exit program.
        """
        os.system("clear")
        while not self.session["logged_user"]:
            self.view.show_menu_option(self.options)
            user_option = self.user_input.get_option(self.options)
            if user_option == "log in":
                self.session["logged_user"] = self.log_in()
            elif user_option == "exit":
                self.is_running = False
                return

    def handle_menu(self):
        """
        Directs the user to the proper menu, depending on the user role.
        """
        os.system("clear")
        if self.session["logged_user"]:
            role = self.session["logged_user"].__class__.__name__
            self.menu = self.roles[role](self.session, self.view,
                                         self.user_input)
            self.menu.display_menu()
            user_choice = self.menu.get_user_input()
            self.menu.handle_menu(user_choice)

    def run(self):
        """
        Entry method for the main module which read csv file at the beginning
        and write to csv file at the end.
        """
        try:
            CsvHandling.read_students_from_csv(self.codecooler_data_file_path)
            CsvHandling.read_attendances_from_csv(
                self.attendances_data_file_path)
            CsvHandling.read_assignments_from_csv(
                self.assignments_data_file_path)
            CsvHandling.read_submissions_from_csv(
                self.submissions_data_file_path)

        except FileNotFoundError:
            CsvHandling.csv_create_if_non_exist()
            self.view.first_program_usage_message()
            self.user_input.get_anykey()

        finally:

            while self.is_running:
                self.handle_login()
                self.handle_menu()

            CsvHandling.write_codecoolers_to_csv(
                self.codecooler_data_file_path)
            CsvHandling.write_attendance_to_csv(
                self.attendances_data_file_path)
            CsvHandling.write_assignments_to_csv(
                self.assignments_data_file_path)
            CsvHandling.write_submissions_to_csv(
                self.submissions_data_file_path)

    def log_in(self):
        """
        Compares user email and password input to objects email and
        password attributes, and if they are ok, returns user object, otherwise
        returns None.

        Returns:
        codecooler: obj
        None
        """
        login_data = self.user_input.get_login_input()
        if login_data is None:
            return
        email = login_data[0]
        password = login_data[1]
        codecoolers = Manager.get_managers() + Staff.get_staff(
        ) + Mentor.get_mentors() + Student.get_students()
        for codecooler in codecoolers:
            if email == codecooler.get_email(
            ) and password == codecooler.get_password():
                return codecooler
        self.view.show_message("\nWrong login or password!\n")
        return None