def create_image(self, image: Image) -> Image: self._validate_image(image) existing_model = self.get_model_by_id(image.model_id) if existing_model is None: raise NonExistingModelError(image.model_id) if self.get_image_by_name(image.name, existing_model) is not None: raise ExistingImageError(image) image._id = self.data.get_and_increment('next_image_id') self.data.add_image(copy.deepcopy(image)) self.save() return image
def create_image(self, image: Image) -> Image: self._validate_image(image) task = self.get_task_by_id(image.task_id) if task is None: raise NonExistingTaskError(image.task_id) if self.get_image_by_name(image.name, task) is not None: raise ExistingImageError(image) image._id = self.data.get_and_increment('next_image_id') self.data.add_image(copy.deepcopy(image)) self.save() return image