Exemplo n.º 1
0
 def validate_student(self, student):
     if student.get_student_id() < 0:
         raise ControllerException("Id should be positive")
     if student.get_group() < 0:
         raise ControllerException("Group number should be positive")
     if student.get_name() == "":
         raise ControllerException("Name can not be empty")
Exemplo n.º 2
0
 def validate_assignment(self, assignment):
     if assignment.get_assignment_id() < 0:
         raise ControllerException("Id should be positive")
     if assignment.get_grade() < 0 or assignment.get_grade() > 10:
         raise ControllerException(
             "Grade should be positive and not greater than 10")
     if assignment.get_student_id() < 0:
         raise ControllerException("Id should be positive")
Exemplo n.º 3
0
 def validate_grade(self, grade):
     """
     validate the grade by grade between 0 and 10, id > 0
     :param grade:
     :return:
     """
     if grade.get_id() < 0:
         raise ControllerException("Id should be positive")
     if grade.get_grade() < 0 or grade.get_grade() > 10:
         raise ControllerException("Grade is a number between 0 and 10")
Exemplo n.º 4
0
 def validate_student(self, student):
     """
     validate the student by id > 0 , group > 0, name non void
     :param student:
     :return:
     """
     if student.get_id() < 0:
         raise ControllerException("Id should be positive")
     if student.get_group() < 0:
         raise ControllerException("Group number should be positive")
     if student.get_name() == "":
         raise ControllerException("Name can not be empty")
Exemplo n.º 5
0
    def validate_assignment(self, assignment):
        """
        validate the assignment by positive id

        :param assignment:
        :return:
        """
        if assignment.get_id() < 0:
            raise ControllerException("Id should be positive")
Exemplo n.º 6
0
 def reading(self):
     file = open("/Users/ecaterinacarazan/PycharmProjects/files/student.txt", "r")
     lines = file.read().splitlines()
     for line in lines:
         list = line.split(", ")
         stud = Student(int(list[0]), list[1], int(list[2]))
         for s in Repository.get_all(self):
             if s.get_id() == int(list[0]):
                 raise ControllerException("Can not add student with same id")
         Repository.add_item(self, stud)
     file.close()
Exemplo n.º 7
0
 def reading(self):
     file = open("/Users/AndiD//Documents/Eclipse/lab57/assignment.txt", "r")
     lines = file.read().splitlines()
     for line in lines:
         list = line.split(", ")
         assign = Assignment(int(list[0]), list[1], list[2])
         for asgn in Repository.get_all(self):
             if asgn.get_id() == int(list[0]):
                 raise ControllerException("Can not add assignment with same id")
         Repository.add_item(self, assign)
     file.close()
Exemplo n.º 8
0
 def reading(self):
     file = open("/Users/AndiD//Documents/Eclipse/lab57/student.txt", "r")
     lines = file.read().splitlines()
     for line in lines:
         list = line.split(", ")
         stud = Student(int(list[0]), list[1], int(list[2]))
         for s in Repository.get_all(self):
             if s.get_id() == int(list[0]):
                 raise ControllerException(
                     "Can not add student with same id")
         Repository.add_item(self, stud)
     file.close()
Exemplo n.º 9
0
 def reading(self):
     file = open("/Users/AndiD//Documents/Eclipse/lab57/grade.txt", "r")
     lines = file.read().splitlines()
     for line in lines:
         list = line.split(", ")
         student = self.repo_stud.get_by_id(int(list[1]))
         assign = self.repo_assign.get_by_id(int(list[2]))
         grade = Grade(int(list[0]), student, assign, int(list[3]))
         for g in Repository.get_all(self):
             if grade.get_id() == g.get_id():
                 raise ControllerException("Can not add grade with same id")
             Repository.add_item(self, grade)
     file.close()
Exemplo n.º 10
0
 def reading(self):
     file = open(
         "/Users/ecaterinacarazan/PycharmProjects/files/assignment.txt",
         "r")
     lines = file.read().splitlines()
     for line in lines:
         list = line.split(", ")
         assign = Assignment(int(list[0]), list[1], list[2])
         for asgn in Repository.get_all(self):
             if asgn.get_id() == int(list[0]):
                 raise ControllerException(
                     "Can not add assignment with same id")
         Repository.add_item(self, assign)
     file.close()
Exemplo n.º 11
0
    def add_student(self, student_id, name, group):
        """
        Adds a student to the list of students

        :param student_id: positive integer
        :param name: string
        :param group: positive integer
        :return:
        """
        student = Student(student_id, name, group)
        self._validator.validate_student(student)
        for stud in self._repository.get_list_of_students():
            if stud.get_student_id() == student_id:
                raise ControllerException("Can not add student with same id")
        self._repository.add_student(student)
Exemplo n.º 12
0
    def undo_last_mod_assign(self):
        """
        Undoes the last modification made on list of assignments

        backup_list is a list of all states of the list of assignments
        when undo, takes the last state from backup list and assigns the list of assignments to it.
        also delete the last state from backup list.
        :return:
        """
        if len(self._repository.get_backup_list_assign()) == 0:
            raise ControllerException("You can't undo the first operation")
        self._repository.add_to_redo_assign_list(
            self._repository.get_list_of_assignments())
        back = self._repository.get_backup_list_assign()
        self._repository.set_list_of_assignments(back[-1])
        del back[-1]
        self._repository.set_backup_list_assign(back)
Exemplo n.º 13
0
    def add_assignment(self, id_assign, description, deadline):
        """
        Adds an assignment to the list of assignments

        :param id_assign: positive integer
        :param description: string
        :param deadline: string
        :return:
        """
        assign = Assignment(id_assign, description, deadline)
        self._validator.validate_assignment(assign)
        for asgn in self._repository.get_all():
            if asgn.get_id() == id_assign:
                raise ControllerException("Can not add assignment with same id")
        self._repository.add_item(assign)
        self._operations.append(AddOperation(assign))
        self._index += 1
        self.controller_undo_redo.add([self])
Exemplo n.º 14
0
    def add_student(self, student_id, name, group):
        """
        Adds a student to the list of students

        :param student_id: positive integer
        :param name: string
        :param group: positive integer
        :return:
        """
        student = Student(student_id, name, group)
        self._validator.validate_student(student)
        for stud in self._repository.get_all():
            if stud.get_id() == student_id:
                raise ControllerException("Can not add student with same id")
        self._repository.add_item(student)
        self._operations.append(AddOperation(student))
        self._index += 1
        self.controller_undo_redo.add([self])
Exemplo n.º 15
0
    def redo_last_mod_assign(self):
        """
        redo the last modification made by undo (on list of assignments

        redo list is a list of all the states which were undone
        when redo, take the last state and assign it to list of assignments,
        extend the backup list again
        :return:
        """
        print(len(self._repository.get_redo_assign_list()))
        if len(self._repository.get_redo_assign_list()) == 0:
            raise ControllerException("You can't redo the first operation")
        red_list = self._repository.get_backup_list_assign() + [
            self._repository.get_list_of_assignments()
        ]
        self._repository.set_backup_list_assign(red_list)
        self._repository.set_list_of_assignments(
            self._repository.get_redo_assign_list()[-1])
        self._repository.remove_from_redo_assign_list()
Exemplo n.º 16
0
 def add_grade(self, student_id, assign_id, grade_id, grade):
     """
     adds a grade
     :param student_id: > 0
     :param assign_id: > 0
     :param grade_id: > 0
     :param grade: between 0 and 10
     :return:
     """
     student = self.__repo_stud.get_by_id(student_id)
     assign = self.__repo_assign.get_by_id(assign_id)
     grade = Grade(grade_id, student, assign, grade)
     self.__validator.validate_grade(grade)
     for g in self.__repository.get_all():
         if g.get_id() == grade_id:
             raise ControllerException("Can not add grade with same id")
     self.__repository.add_item(grade)
     self._operations.append(AddOperation(grade))
     self._index += 1
     self.controller_undo_redo.add([self])