예제 #1
0
 def _delete(self):
     """Remove image scale from database and filesystem.
     """
     try:
         delete_file(self.filesystem_path)
     except OSError as e:
         if e.errno != errno.ENOENT:
             raise
     object_session(self).delete(self)
예제 #2
0
 def delete(self):
     """Delete this image including all scales from the database and disk.
     """
     self._delete_scales()
     try:
         delete_file(self.filesystem_path)
     except OSError as e:
         if e.errno != errno.ENOENT:
             raise
     object_session(self).delete(self)
예제 #3
0
 def _delete_scales(self):
     """Remove all existing image scales.
     """
     session = object_session(self)
     scales = session.query(ImageScale).filter(ImageScale.image_id == self.id)
     for scale in scales:
         try:
             delete_file(scale.filesystem_path)
         except OSError as e:
             if e.errno != errno.ENOENT:
                 raise
     scales.delete()
예제 #4
0
    def replace(self, data, filename=None):
        """Replace the image contents.

        This method should be used to modify images. This method will
        delete old old image scales and switch to a new filename and
        URL.

        :param str data: Raw image data.
        :param str filename: Image filename (optional)

        """
        self._delete_scales()
        try:
            delete_file(self.filesystem_path)
        except OSError as e:
            if e.errno != errno.ENOENT:
                raise
        self._set_content(data, filename)
예제 #5
0
    def delete(self, id):
        """ Delete the object with the given ID.

        :param id: ID of the file object
        :type id: unicode

        :result: Success
        :rtype: bool
        """

        # The kotti.events.ObjectDelete Event fires when the transaction is
        # already committing. It is safe to use os.unlink
        if transaction.get().status == "Committing":
            os.unlink(self.path(id))
            self.remove_base_directory(os.path.split(self.path(id=id))[0])
        else:
            # TODO: call remove_base_directory during transaction
            delete_file(self.path(id))
예제 #6
0
    def delete(self, id):
        """ Delete the object with the given ID.

        :param id: ID of the file object
        :type id: unicode

        :result: Success
        :rtype: bool
        """

        # The kotti.events.ObjectDelete Event fires when the transaction is
        # already committing. It is safe to use os.unlink
        if transaction.get().status == "Committing":
            os.unlink(self.path(id))
            self.remove_base_directory(os.path.split(self.path(id=id))[0])
        else:
            # TODO: call remove_base_directory during transaction
            delete_file(self.path(id))