本文整理汇总了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)
示例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)
示例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))
示例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()
示例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
示例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