當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。