예제 #1
0
 def find(self, student_ID, assignment_ID):
     '''
     Returns the grade a student received for an assignment.
     '''
     for grade in self._data:
         if grade.assignment_ID == assignment_ID and grade.student_ID == student_ID:
             return grade
     raise RepositoryError("Assignment not given to this student!")
예제 #2
0
 def find_one(self, ID):
     '''
     Returns the student having a certain ID.
     '''
     for student in self._data:
         if student.ID == ID:
             return student
     raise RepositoryError("Student does not exist!")
예제 #3
0
 def add(self, student):
     '''
     Adds a student to the repository
     student - instance of Student class to be added
     '''
     if student in self._data:
         raise RepositoryError("Student already exists!")
     self._data.append(student)
 def find_one(self, ID):
     '''
     Returns the assignment having a certain ID.
     '''
     for assignment in self._data:
         if assignment.ID == ID:
             return assignment
     raise RepositoryError("Assignment does not exist!")
 def add(self, assignment):
     '''
     Adds an assignment to the repository
     student - instance of Assignment class to be added
     '''
     if assignment in self._data:
         raise RepositoryError("Assignment already exists!")
     self._data.append(assignment)
예제 #6
0
 def add(self, grade):
     '''
     Adds a new grade to the repository.
     :param grade - instance of Grade class
     '''
     if grade in self._data:
         raise RepositoryError(
             "This assignment already given to this student!")
     self._data.append(grade)
 def __load_from_file(self):
     file = open(self.__file_name, "rb")
     try:
         self._data = pickle.load(file)
     except EOFError:
         self._data = []
     except Exception as exception:
         raise RepositoryError(str(exception))
     finally:
         file.close()
예제 #8
0
 def find_group(self, group):
     '''
     Returns the students belonging to the same group
     '''
     same_group = []
     for student in self._data:
         if student.group == group:
             same_group.append(student)
     if len(same_group) == 0:
         raise RepositoryError("Group does not exit!")
     else:
         return same_group
 def __load_from_file(self):
     try:
         file = open(self.__file_name, "r")
         line = file.readline().strip()
         while line != "":
             attributes = line.split(";")
             student = Student(int(attributes[0]), attributes[1],
                               int(attributes[2]))
             Student_repository.add(self, student)
             line = file.readline().strip()
     except IOError as ioerror:
         raise RepositoryError(str(ioerror))
     finally:
         file.close()
 def __load_from_file(self):
     try:
         file = open(self.__file_name, "r")
         line = file.readline().strip()
         while line != "":
             attributes = line.split(";")
             if attributes[2] != "None":
                 grade = Grade(int(attributes[0]), int(attributes[1]),
                               int(attributes[2]))
             else:
                 grade = Grade(int(attributes[0]), int(attributes[1]))
             Grade_repository.add(self, grade)
             line = file.readline().strip()
     except IOError as ioerror:
         raise RepositoryError(str(ioerror))
     finally:
         file.close()