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


Python default_storage.exists方法代码示例

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


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

示例1: download_media_files

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import exists [as 别名]
def download_media_files(self, xml_doc, media_path):
        for media_node in xml_doc.getElementsByTagName('mediaFile'):
            filename_node = media_node.getElementsByTagName('filename')
            url_node = media_node.getElementsByTagName('downloadUrl')
            if filename_node and url_node:
                filename = filename_node[0].childNodes[0].nodeValue
                path = os.path.join(media_path, filename)
                if default_storage.exists(path):
                    continue
                download_url = url_node[0].childNodes[0].nodeValue
                if self._get_media_response(download_url):
                    download_res = self._current_response
                    media_content = ContentFile(download_res.content)
                    default_storage.save(path, media_content)
                    self.logger.debug("Fetched %s." % filename)
                else:
                    self.logger.error("Failed to fetch %s." % filename) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:19,代码来源:briefcase_client.py

示例2: test_create_thumbnails_command

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import exists [as 别名]
def test_create_thumbnails_command(self):
        call_command("create_image_thumbnails")
        for attachment in Attachment.objects.filter(instance=self.instance):
            filename = attachment.media_file.name.replace('.jpg', '')
            for size in ['small', 'medium', 'large']:
                thumbnail = '%s-%s.jpg' % (filename, size)
                self.assertTrue(
                    default_storage.exists(thumbnail))
        check_datetime = datetime.now()
        # replace or regenerate thumbnails if they exist
        call_command("create_image_thumbnails", force=True)
        for attachment in Attachment.objects.filter(instance=self.instance):
            filename = attachment.media_file.name.replace('.jpg', '')
            for size in ['small', 'medium', 'large']:
                thumbnail = '%s-%s.jpg' % (filename, size)
                self.assertTrue(
                    default_storage.exists(thumbnail))
                self.assertTrue(
                    default_storage.modified_time(thumbnail) > check_datetime)
                default_storage.delete(thumbnail) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:22,代码来源:test_attachment.py

示例3: test_warp

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import exists [as 别名]
def test_warp(self):
        srid = 3857
        obj = self.qs[0]
        qs = self.qs.warp(srid, format='img')
        newobj = qs[0]
        r = newobj.raster()
        self.assertEqual(r.driver.ext, 'img')
        self.assertIn('proj=merc', r.sref.proj4)
        self.assertEqual(r.sref.srid, srid)
        source = obj.raster()
        self.assertNotEqual(r.sref.srid, source.sref.srid)
        self.assertIsNone(newobj.pk)
        expected = os.path.join(upload_to.path, newobj.image.name)
        newobj.save()
        self.assertIsNotNone(newobj.pk)
        self.assertEqual(newobj.image.name, expected)
        self.assertTrue(default_storage.exists(newobj.image)) 
开发者ID:bkg,项目名称:django-spillway,代码行数:19,代码来源:test_query.py

示例4: test_model_form

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import exists [as 别名]
def test_model_form(self):
        files = {
            'foo_file': SimpleUploadedFile(
                name='foo.pdf',
                content=b'foo content',
                content_type='application/pdf')}
        form = FooFileModelForm(data={}, files=files)
        self.assertTrue(form.is_valid())
        form.save()
        self.assertTrue(default_storage.exists('foo_uploads/foo.pdf'))

        # check file content was saved
        fh = default_storage.open('foo_uploads/foo.pdf', 'r+b')
        try:
            self.assertEqual(fh.read(), b'foo content')
        finally:
            fh.close() 
开发者ID:jschneier,项目名称:django-storages,代码行数:19,代码来源:test_azure.py

示例5: logo_path

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import exists [as 别名]
def logo_path(instance, filename):
    """
    Delete the file if it already exist and returns the enterprise customer logo image path.

    Arguments:
        instance (:class:`.EnterpriseCustomerBrandingConfiguration`): EnterpriseCustomerBrandingConfiguration object
        filename (str): file to upload

    Returns:
        path: path of image file e.g. enterprise/branding/<model.id>/<model_id>_logo.<ext>.lower()

    """
    extension = os.path.splitext(filename)[1].lower()
    instance_id = str(instance.id)
    fullname = os.path.join("enterprise/branding/", instance_id, instance_id + "_logo" + extension)
    if default_storage.exists(fullname):
        default_storage.delete(fullname)
    return fullname 
开发者ID:edx,项目名称:edx-enterprise,代码行数:20,代码来源:models.py

示例6: create_thumbnail

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import exists [as 别名]
def create_thumbnail(self):
        if not self.picture:
            return False
        picture_path, thumbnail_path = self.get_picture_paths()
        if thumbnail_path and not storage.exists(thumbnail_path):
            try:
                picture_file = storage.open(picture_path, "r")
                image = Image.open(picture_file)
                image = image.crop(get_square_crop_points(image))
                image = image.resize((THUMBNAIL_SIZE,
                                      THUMBNAIL_SIZE),
                                     Image.ANTIALIAS)
                image.save(thumbnail_path)
            except (IOError, KeyError, UnicodeDecodeError):
                return False
        return True 
开发者ID:PacktPublishing,项目名称:Django-2-Web-Development-Cookbook-Third-Edition,代码行数:18,代码来源:models.py


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