当前位置: 首页>>代码示例>>Python>>正文


Python storage.Storage方法代码示例

本文整理汇总了Python中django.core.files.storage.Storage方法的典型用法代码示例。如果您正苦于以下问题:Python storage.Storage方法的具体用法?Python storage.Storage怎么用?Python storage.Storage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.core.files.storage的用法示例。


在下文中一共展示了storage.Storage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_logo_path

# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import Storage [as 别名]
def test_logo_path(self, file_exists, delete_called):
        """
        Test that the path of image file should beenterprise/branding/<model.id>/<model_id>_logo.<ext>.lower().

        Additionally, test that the correct backend actions are taken in regards to deleting existing data.
        """
        file_mock = self._make_file_mock()
        branding_config = EnterpriseCustomerBrandingConfiguration(
            id=1,
            enterprise_customer=factories.EnterpriseCustomerFactory(),
            logo=file_mock
        )

        storage_mock = mock.MagicMock(spec=Storage, name="StorageMock")
        storage_mock.exists.return_value = file_exists
        with mock.patch("django.core.files.storage.default_storage._wrapped", storage_mock):
            path = logo_path(branding_config, branding_config.logo.name)
            self.assertEqual(path, "enterprise/branding/1/1_logo.png")
            assert storage_mock.delete.call_count == (1 if delete_called else 0)
            if delete_called:
                storage_mock.delete.assert_called_once_with('enterprise/branding/1/1_logo.png') 
开发者ID:edx,项目名称:edx-enterprise,代码行数:23,代码来源:test_models.py

示例2: test_branding_configuration_saving_successfully

# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import Storage [as 别名]
def test_branding_configuration_saving_successfully(self):
        """
        Test enterprise customer branding configuration saving successfully.
        """
        storage_mock = mock.MagicMock(spec=Storage, name="StorageMock")
        branding_config_1 = EnterpriseCustomerBrandingConfiguration(
            enterprise_customer=factories.EnterpriseCustomerFactory(),
            logo="test1.png"
        )

        storage_mock.exists.return_value = True
        with mock.patch("django.core.files.storage.default_storage._wrapped", storage_mock):
            branding_config_1.save()
            self.assertEqual(EnterpriseCustomerBrandingConfiguration.objects.count(), 1)

        branding_config_2 = EnterpriseCustomerBrandingConfiguration(
            enterprise_customer=factories.EnterpriseCustomerFactory(),
            logo="test2.png"
        )

        storage_mock.exists.return_value = False
        with mock.patch("django.core.files.storage.default_storage._wrapped", storage_mock):
            branding_config_2.save()
            self.assertEqual(EnterpriseCustomerBrandingConfiguration.objects.count(), 2) 
开发者ID:edx,项目名称:edx-enterprise,代码行数:26,代码来源:test_models.py

示例3: path

# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import Storage [as 别名]
def path(self, name):
        """
        Return a local filesystem path where the file can be retrieved using
        Python's built-in open() function. Storage systems that can't be
        accessed using open() should *not* implement this method.
        """
        # FIXME: this would be useful with self.location != ''
        # in this case use this notation:
        # 1. define self.location in __init__
        # 2. rewrite path() method to be like
        # return os.oath.join(self.location, name)
        # 3. everywhere in other sel.methods use self.path(name) instead of name attr
        return name 
开发者ID:LexPredict,项目名称:lexpredict-contraxsuite,代码行数:15,代码来源:filebrowser_webdav_file_storage.py

示例4: path

# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import Storage [as 别名]
def path(self, name):
        # Overridden to give it the behaviour of the base Storage class
        # This is what an external storage backend would have
        raise NotImplementedError("This backend doesn't support absolute paths.") 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:dummy_external_storage.py

示例5: _save

# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import Storage [as 别名]
def _save(self, name, content):
        """保存文件时调用"""
        # name: 上传文件的名称 a.txt
        # content: File类的对象,包含了上传文件的内容

        # 上传文件到FDFS文件存储系统
        # client = Fdfs_client('客户配置文件路径')
        # client = Fdfs_client(os.path.join(settings.BASE_DIR, 'utils/fdfs/client.conf'))
        client = Fdfs_client(self.client_conf)


        # 获取上传文件内容
        file_content = content.read()

        # 上传文件
        # {
        #     'Group name': group_name,
        #     'Remote file_id': remote_file_id, # 保存的文件id
        #     'Status': 'Upload successed.', # 上传是否成功
        #     'Local file name': '',
        #     'Uploaded size': upload_size,
        #     'Storage IP': storage_ip
        # } if success else None

        response = client.upload_by_buffer(file_content)

        if response is None or response.get('Status') != 'Upload successed.':
            # 上传失败
            raise Exception('上传文件到fast dfs系统失败')

        # 获取保存文件id
        file_id = response.get('Remote file_id')

        # 返回file_id
        return file_id 
开发者ID:ScrappyZhang,项目名称:ecommerce_website_development,代码行数:37,代码来源:storage.py


注:本文中的django.core.files.storage.Storage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。