Esempio n. 1
0
 def remove(self, objectID):
     '''
         Removes an object from repo list
         Input: -objID- positive integer
         Output: True - if removing succeded
                 raises RepoException
     '''
     if type(objectID) != int or objectID <= 0:
         raise RepoException("ObjectID must be a positive integer!")
     pos = self.find(objectID)
     if pos != -1:
         del self._objects[pos]
         return True
     raise RepoException("An object with this ID does not exit!")
Esempio n. 2
0
 def removeGrade(self, grade):
     '''
         Removes a grade from repo list
         Input: -grade- Grade object
         Output: True - if removing succeded
                 raises RepoException
     '''
     for gr in self._objects:
         if type(gr) != Grade or type(grade) != Grade:
             raise RepoException("This method can only be used with Grade objects!")
     for i in range(len(self._objects)):
         if self._objects[i] == grade:
             del self._objects[i]
             return True
     raise RepoException("In this repository does not exit such a grade!")
Esempio n. 3
0
 def __findGr(self, obj):
     if type(obj) != Grade:
         raise RepoException("Object must be a grade!")
     for i in range(len(self._objects)):
         if self._objects[i].assignID == obj.assignID and self._objects[i].studentID == obj.studentID:
             return i
     return -1
Esempio n. 4
0
 def add(self, obj):
     '''
         Adds a new object into repo list
         Input: -obj- object
         Output: True - if adding succeded
                 raises RepoException
     '''
     if self.find(obj.id) == -1 or (type(obj) == Grade and self.__findGr(obj) == -1):
         self._objects.append(obj)
         return True
     raise RepoException("An object with this ID already exists!")
Esempio n. 5
0
 def find(self, objectID):
     '''
         Finds an object from repo list
         Input: -objID- positive integer
         Output: - i - int which is position of element with given id
                 - -1 - if there is no object with given id
     '''
     if type(objectID) != int or objectID <= 0:
         raise RepoException("ObjectID must be a positive integer!")
     for i in range(len(self._objects)):
         if self._objects[i].id == objectID:
             return i
     return -1
Esempio n. 6
0
 def update(self, obj):
     '''
         Updates an object from repo list
         Input: -obj- object
         Output: True - if update succeded
                 False - otherwise
     '''
     if type(obj) == Grade:
         for i in range(len(self._objects)):
             if self._objects[i].assignID == obj.assignID and self._objects[i].studentID == obj.studentID:
                 self._objects[i] = deepcopy(obj)
                 return True
     else:
         pos = self.find(obj.id)
         if pos != -1 and type(obj) != Grade:
                 self._objects[pos] = deepcopy(obj)
                 return True
         raise RepoException("There is no object with such id in the database!")
Esempio n. 7
0
 def testRepoEx(self):
     x = RepoException("Test")
     self.assertEqual(x.messages, "Test")
     self.assertEqual(str(x), "Test")
     self.r.add(self.g)
     self.assertEqual(type(str(self.r)), str)