def removeObject(self, entityID): found = False for entity in self.__objects: if entity.getID() == entityID: found = True if not found: raise RepoError("Entity not in list") self.__objects[:] = [entity for entity in self.__objects if entity.getID() != entityID]
def removeGradeByDisciplineID(self, entityID): found = False for entity in self.__objects: if entity.getDisciplineID() == entityID: found = True if not found: raise RepoError("Entity not in list") self.__deletedObjects = [entity for entity in self.__objects if entity.getDisciplineID() == entityID] self.__objects = [entity for entity in self.__objects if entity.getDisciplineID() != entityID]
def get_all_items(self): if len(self._items) == 0: raise RepoError("The list is empty!") return self._items[:]
def remove(self, item): item = self.search(item) if item not in self._items: raise RepoError("The item you are trying to delete doesn't exist!") self._items.remove(item)
def search(self, item): if item not in self._items: raise RepoError("The item you are searching doesn't exist!") for item_required in self._items: if item_required == item: return item_required
def add(self, item): if item in self._items: raise RepoError("The item you are trying to add already exists!") self._items.append(item)
def searchEntityByName(self, entityName): foundEntities = [entity for entity in self.__objects if entityName.lower() in entity.getName().lower()] if len(foundEntities) == 0: raise RepoError("No matches found") return foundEntities
def searchEntityByID(self, entityID): for entity in self.__objects: if entity.getID() == entityID: return entity raise RepoError("Entity not in list")
def addUniqueObject(self, entity): if entity in self.__objects: raise RepoError("Entity already in list") self.__objects.append(entity)