Example #1
0
 def update_model(self, model: Model) -> Model:
     with self._session(False) as s:
         m = self._get_sql_object_by_id(self.models, model.id)
         if m is None:
             raise NonExistingModelError(model)
         update_attrs(m, **SModel.get_kwargs(model))
         s.commit()
         return model
Example #2
0
    def update_model(self, model: Model) -> Model:
        with self._session():
            m: SModel = self._get_sql_object_by_id(self.models, model.id)
            if m is None:
                raise NonExistingModelError(model)
            kwargs = SModel.get_kwargs(model)
            update_attrs(m, **kwargs)

            return model
Example #3
0
    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
Example #4
0
    def update_model(self, model: Model) -> Model:
        with self._session():
            m: SModel = self._get_sql_object_by_id(self.models, model.id)
            if m is None:
                raise NonExistingModelError(model)
            kwargs = SModel.get_kwargs(model)
            kwargs.pop('images', None)
            update_attrs(m, **kwargs)

            for i in m.images:
                if i.id in model.images:
                    self.update_image(model.images.get(i.id))
                else:
                    model._images.add(i.to_obj())
            return model
Example #5
0
    def update_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)

        existing_image = self.get_image_by_id(image.id)
        if existing_image is None:
            raise NonExistingImageError(image)

        self.data.remove_image(image.id)
        self.data.add_image(copy.deepcopy(image))
        self.save()
        return image
Example #6
0
    def update_model(self, model: Model) -> Model:
        self._validate_model(model)

        task = self.get_task_by_id(model.task_id)
        if task is None:
            raise NonExistingTaskError(model.task_id)

        existing_model = self.get_model_by_id(model.id)
        if existing_model is None:
            raise NonExistingModelError(model)

        self.data.remove_model(model.id)
        model_copy = copy.deepcopy(model)
        self.data.add_model(model_copy)
        self.save()
        return model
Example #7
0
 def delete_model(self, model: Model):
     if model.id is None:
         raise NonExistingModelError(model)
     self.data.remove_model(model.id)
     self.save()
     model.unbind_meta_repo()