def updateGrade(self, discipline, studentID, grade): ''' updates a Grade's grade Input: discipline - string, the name of the discipline that the student must be added to studentID - positive integer, the ID of the student to add to a discipline grade - float, 1<= grade <= 10, the grade to be updated Output: if such a Grade exists, it is updated Exceptions: raises DisciplineException if the given discipline's name does not exist in DisciplineRepository raises StudentException if the given student's ID does not exist in StudentRepository raises GradeException if a Grade with the given discipline and studentID does not exist ''' # remove undo indexes self.__operations = self.__operations[0:self.__index] if self.__disRepo.findByName(discipline) == None: raise DisciplineException("There is no Discipline with name " + discipline + "!") if self.__stuRepo.findByID(studentID) == None: raise StudentException("The is no Student with ID " + str(studentID) + "!") # get the grade before update oldGrade = deepcopy( self.__repo.findByDisciplineAndStudentID(discipline, studentID)) self.__repo.updateGrade(discipline, studentID, grade) # if no exceptions were raised => record the operation for undo newGrade = deepcopy( self.__repo.findByDisciplineAndStudentID(discipline, studentID)) self.__operations.append(UpdateOperation(oldGrade, newGrade)) self.__index += 1 self.__undoCtrl.recordUpdatedController([self])
def updateStudent(self, ID, newName): ''' updates a Student from the register, using the given ID Input: ID - positive integer, the ID of the Student be updated newName - the new name of the student Output: if such a Student exists, it is updated Exceptions: raises StudentException if a Student with the given ID does not exist ''' self.__operations = self.__operations[0:self.__index] oldStudent = deepcopy(self.__repo.findBysID(ID)) self.__repo.update(ID, newName) newStudent = deepcopy(self.__repo.findBysID(ID)) self.__operations.append(UpdateOperation(oldStudent, newStudent)) self.__index += 1 self.__undoCtrl.recordUpdatedController([self])
def updateDiscipline(self, ID, newName): ''' updates a Discipline from the register, using the given ID Input: ID - positive integer, the ID of the Discipline to be updated newName - the new name of the discipline Output: if such a Discipline exists, it is updated Exceptions: raises DisciplineException if a Discipline with the given ID does not exists ''' self.__operations = self.__operations[0:self.__index] oldDiscipline = deepcopy(self.__repo.findBydID(ID)) self.__repo.update(ID, newName) newDiscipline = deepcopy(self.__repo.findBydID(ID)) self.__operations.append(UpdateOperation(oldDiscipline, newDiscipline)) self.__index += 1 self.__undoCtrl.recordUpdatedController([self])
def updateStudent(self, ID, newName): ''' updates a Student from the register, using its ID Input: ID - positive integer, the ID of the Student that must be updated newName - the name of the new student Output: if such a Student exists, it is updated Exceptions: raises StudentException if a Student with the given ID does not exist ''' # remove undo indexes self.__operations = self.__operations[0:self.__index] # get the student before update oldStudent = deepcopy(self.__repo.findByID(ID)) self.__repo.update(ID, newName) # if no exceptions were raised => record the operation for undo newStudent = deepcopy(self.__repo.findByID(ID)) self.__operations.append(UpdateOperation(oldStudent, newStudent)) self.__index += 1 self.__undoCtrl.recordUpdatedController([self])
def updateDiscipline(self, name, newTeacherName): ''' updates a Discipline from the register, using its name Input: name - positive integer, the name of the Discipline that must be updated newTeacherName - the name of the new teacher Output: if such a Discipline exists, it is updated Exceptions: raises DisciplineException if a Discipline with the given name does not exist ''' # remove undo indexes self.__operations = self.__operations[0:self.__index] # get the discipline before update oldDiscipline = deepcopy(self.__repo.findByName(name)) self.__repo.update(name, newTeacherName) # if no exceptions were raised => record the operation for undo newDiscipline = deepcopy(self.__repo.findByName(name)) self.__operations.append(UpdateOperation(oldDiscipline, newDiscipline)) self.__index += 1 self.__undoCtrl.recordUpdatedController([self])