Ejemplo n.º 1
0
    def __update_student(self):
        target_id = MenuUI.get_input_of_type(int, 'ID of student to update: ')
        new_name = MenuUI.get_input_of_type(str, 'New name: ')

        old_name = self._student_handler.update_attribute(
            target_id, 'name', new_name)

        UndoManager.add_undo_operation(self._student_handler,
                                       UndoHandler.UPDATE_STUDENT, target_id,
                                       'name', old_name, new_name)
        UndoManager.flush_operations()
Ejemplo n.º 2
0
    def __update_discipline(self):
        target_id = MenuUI.get_input_of_type(int,
                                             'ID of discipline to update: ')
        new_name = MenuUI.get_input_of_type(str, 'New name: ')

        old_name = self._discipline_handler.update_attribute(
            target_id, 'name', new_name)

        UndoManager.add_undo_operation(self._discipline_handler,
                                       UndoHandler.UPDATE_DISCIPLINE,
                                       target_id, 'name', old_name, new_name)
        UndoManager.flush_operations()
Ejemplo n.º 3
0
    def __add_discipline(self):
        """
        Function that gets called when the user chose to add a discipline.
        An ID and a name will be requested, processed by the handler, and then added to the repository
        """
        id = MenuUI.get_input_of_type(int, 'ID: ')
        name = MenuUI.get_input_of_type(str, 'Discipline name: ')

        discipline = self._discipline_handler.add(id, name)

        UndoManager.add_undo_operation(self._discipline_handler,
                                       UndoHandler.ADD_DISCIPLNE, discipline)
        UndoManager.flush_operations()
Ejemplo n.º 4
0
    def __add_student(self):
        """
        Function that gets called when the user chose to add a student.
        An ID and a name will be requested, processed by the handler, and then added to the repository
        """
        id = MenuUI.get_input_of_type(int, 'ID: ')
        name = MenuUI.get_input_of_type(str, 'Student name: ')

        student = self._student_handler.add(id, name)

        UndoManager.add_undo_operation(self._student_handler,
                                       UndoHandler.ADD_STUDENT, student)
        UndoManager.flush_operations()
Ejemplo n.º 5
0
    def __add_grade(self):
        """
        Function that gets called when the user chose to add a grade.
        A student ID, a discipline ID and a name will be requested, then
        processed by the handler, and then added to the repository
        """
        discipline_id = MenuUI.get_input_of_type(int, 'Discipline ID: ')
        student_id = MenuUI.get_input_of_type(int, 'Student ID: ')
        value = MenuUI.get_input_of_type(int, 'Grade value: ')

        if not self._student_handler.id_exists(
                student_id):  # check if the student actually exists
            raise Exception('Student ID does not exist')
        if not self._discipline_handler.id_exists(
                discipline_id):  # check if the discipline actually exists
            raise Exception('Discipline ID does not exist')

        grade = self._grade_handler.add(discipline_id, student_id, value)

        UndoManager.add_undo_operation(self._grade_handler,
                                       UndoHandler.ADD_GRADE, grade)
        UndoManager.flush_operations()
Ejemplo n.º 6
0
    def __remove_discipline(self):
        # remove discipline
        discipline_id = MenuUI.get_input_of_type(int,
                                                 'Discipline ID to remove: ')
        discipline = self._discipline_handler.remove(discipline_id)

        # remove all grades at the given discipline
        grades = self._grade_handler.remove_from_discipline(discipline_id)

        UndoManager.add_undo_operation(self._discipline_handler,
                                       UndoHandler.REMOVE_DISCIPLINE,
                                       discipline)

        for grade in grades:
            UndoManager.add_undo_operation(self._grade_handler,
                                           UndoHandler.REMOVE_GRADE, grade)

        UndoManager.flush_operations()
Ejemplo n.º 7
0
    def __remove_student(self):
        # remove student
        student_id = MenuUI.get_input_of_type(int, 'Student ID to remove: ')
        student = self._student_handler.remove(student_id)

        # remove his grades
        grades = self._grade_handler.remove_from_student(student_id)

        UndoManager.add_undo_operation(
            self._student_handler,
            UndoHandler.REMOVE_STUDENT,
            # student.id, student.name
            student)

        for grade in grades:
            UndoManager.add_undo_operation(self._grade_handler,
                                           UndoHandler.REMOVE_GRADE, grade)

        UndoManager.flush_operations()