Пример #1
0
 def save(self, *args, **kwargs):
     """
     Check what storage backend which are being used.
     If backend is any of the provided database backends,
     emit the `write_binary` signal to write the file to
     the blob field.
     """
     if self.backend in ["PostgreSQLStorage", "MySQLStorage", "SQLiteStorage", "OracleStorage"]:
         # If using one of the included database backends,
         # save the instance and emit the `write_binary` signal
         # to write the binary data into the blob field.
         try:
             content = self.attachment.file
             super(Attachment, self).save(*args, **kwargs)
             write_binary.send(sender=Attachment, instance=self, content=content)
         except Exception, e:
             raise e
Пример #2
0
 def save(self, *args, **kwargs):
     """
     Check what storage backend which are being used.
     If backend is any of the provided database backends,
     emit the `write_binary` signal to write the file to
     the blob field.
     """
     if self.backend in [
             "PostgreSQLStorage", "MySQLStorage", "SQLiteStorage",
             "OracleStorage"
     ]:
         # If using one of the included database backends,
         # save the instance and emit the `write_binary` signal
         # to write the binary data into the blob field.
         try:
             content = self.attachment.file
             super(Attachment, self).save(*args, **kwargs)
             write_binary.send(sender=Attachment,
                               instance=self,
                               content=content)
         except Exception, e:
             raise e
Пример #3
0
    def save(self, *args, **kwargs):
        """
        Check what storage backend which are being used.
        If backend is any of the provided database backends,
        emit the `write_binary` signal to write the file to
        the blob field.
        """
        # self.backend = 'PostgreSQLStorage'
        self.slug = slugify(self.pre_slug)

        if self.backend in ["PostgreSQLStorage", "MySQLStorage", "SQLiteStorage", "OracleStorage"]:
            # If using one of the included database backends,
            # save the instance and emit the `write_binary` signal
            # to write the binary data into the blob field.
            try:
                content = self.attachment.file
                super(Attachment, self).save(*args, **kwargs)
                write_binary.send(sender=Attachment, instance=self, content=content)
            except Exception as e:
                raise e
        elif self.backend == "FileSystemStorage":
            # If using the default FileSystemStorage,
            # save some extra attributes as well.
            if not self.pk:
                super(Attachment, self).save(*args, **kwargs)
            self.slug = slugify(self.pre_slug)
            self.checksum = md5buffer(self.attachment.file)
            super(Attachment, self).save(force_update=True)
        else:
            raise UnsupportedBackend("Unsupported storage backend.")

        #          Send the post_write signal after save even if backend does not
        #          use the write_binary method (such as the FileStorageBackend), to
        #          keep consistancy between all backends.

        post_write.send(sender=Attachment, instance=self)