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


Python default_storage.delete方法代码示例

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


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

示例1: save

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import delete [as 别名]
def save(self):
        photo = super(OrganizationForm, self).save()
        x = self.cleaned_data.get('x')
        y = self.cleaned_data.get('y')
        w = self.cleaned_data.get('width')
        h = self.cleaned_data.get('height')

        if x is not None and y is not None:
            image = Image.open(photo.logo)
            cropped_image = image.crop((x, y, w+x, h+y))
            resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS)
            # resized_image.save(photo.logo.path)
            resized_image_file = StringIO.StringIO()
            mime = mimetypes.guess_type(photo.logo.name)[0]
            plain_ext = mime.split('/')[1]
            resized_image.save(resized_image_file, plain_ext)
            default_storage.delete(photo.logo.name)
            default_storage.save(photo.logo.name, ContentFile(resized_image_file.getvalue()))
            resized_image_file.close()
        return photo 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:22,代码来源:forms.py

示例2: test_create_thumbnails_command

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import delete [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: logo_path

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import delete [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

示例4: save

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import delete [as 别名]
def save(self, commit=True):
        instance = super().save(commit=False)
        picture_path = self.cleaned_data["picture_path"]
        if picture_path:
            temporary_image_path = os.path.join("temporary-uploads", picture_path)
            file_obj = default_storage.open(temporary_image_path)
            instance.picture.save(picture_path, file_obj, save=False)
            default_storage.delete(temporary_image_path)
        latitude = self.cleaned_data["latitude"]
        longitude = self.cleaned_data["longitude"]
        if latitude is not None and longitude is not None:
            instance.set_geoposition(longitude=longitude, latitude=latitude)
        if commit:
            instance.save()
            self.save_m2m()
        return instance 
开发者ID:PacktPublishing,项目名称:Django-3-Web-Development-Cookbook-Fourth-Edition,代码行数:18,代码来源:forms.py

示例5: storage

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import delete [as 别名]
def storage(settings):
    settings.DEFAULT_FILE_STORAGE = "normandy.base.storage.NormandyInMemoryStorage"

    from django.core.files.storage import default_storage

    yield default_storage

    dirs_to_delete = ["/"]
    while len(dirs_to_delete) > 0:
        dir_path = dirs_to_delete.pop()
        paths, new_dirs = default_storage.listdir(dir_path)
        dirs_to_delete.extend(new_dirs)
        for path in paths:
            default_storage.delete(path) 
开发者ID:mozilla,项目名称:normandy,代码行数:16,代码来源:conftest.py

示例6: generate_new

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import delete [as 别名]
def generate_new(self):
        data = serialize('full_detail_geojson',
               Site.objects.filter(project_id = self.project.id, is_survey=False, is_active=True),
               geometry_field='location',
               fields=('name', 'location', 'id', 'identifier'))

        with tempfile.NamedTemporaryFile() as temp:
            temp.write(data)
            temp.seek(0)
            if default_storage.exists('geojsonFiles/' + str(self.project.id) + '/site-geojson/sites.geojson'):
                default_storage.delete('geojsonFiles/' + str(self.project.id) + '/site-geojson/sites.geojson')
            
            geojson_url = default_storage.save('geojsonFiles/' + str(self.project.id) + '/site-geojson/sites.geojson', temp)
            self.geoJSON.name = geojson_url
            self.save() 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:17,代码来源:models.py

示例7: test_thumbnails

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import delete [as 别名]
def test_thumbnails(self):
        for attachment in Attachment.objects.filter(instance=self.instance):
            url = image_url(attachment, 'small')
            filename = attachment.media_file.name.replace('.jpg', '')
            thumbnail = '%s-small.jpg' % filename
            self.assertNotEqual(
                url.find(thumbnail), -1)
            for size in ['small', 'medium', 'large']:
                thumbnail = '%s-%s.jpg' % (filename, size)
                self.assertTrue(
                    default_storage.exists(thumbnail))
                default_storage.delete(thumbnail) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:14,代码来源:test_attachment.py

示例8: add_arguments

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import delete [as 别名]
def add_arguments(self, parser):
        parser.add_argument("org_as2name", type=str)
        parser.add_argument("partner_as2name", type=str)
        parser.add_argument("path_to_payload", type=str)

        parser.add_argument(
            "--delete",
            action="store_true",
            dest="delete",
            default=False,
            help="Delete source file after processing",
        ) 
开发者ID:abhishek-ram,项目名称:django-pyas2,代码行数:14,代码来源:sendas2message.py

示例9: open

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import delete [as 别名]
def open(self, mode='r'):
        if self.name:
            return open(self.get_full_path(), mode)
        else:
            tmp_file = tempfile.NamedTemporaryFile(delete=False)
            self.name = tmp_file.name
            return tmp_file 
开发者ID:wagtail,项目名称:wagtail,代码行数:9,代码来源:tmp_storages.py

示例10: remove

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import delete [as 别名]
def remove(self):
        cache.delete(self.name) 
开发者ID:wagtail,项目名称:wagtail,代码行数:4,代码来源:tmp_storages.py

示例11: _check_cache

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import delete [as 别名]
def _check_cache(cache_name):
    key = 'django-watchman-{}'.format(uuid.uuid4())
    value = 'django-watchman-{}'.format(uuid.uuid4())

    cache = utils.get_cache(cache_name)

    cache.set(key, value)
    cache.get(key)
    cache.delete(key)
    return {cache_name: {"ok": True}} 
开发者ID:mwarkentin,项目名称:django-watchman,代码行数:12,代码来源:checks.py

示例12: _check_storage

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import delete [as 别名]
def _check_storage():
    filename = joinpath(watchman_settings.WATCHMAN_STORAGE_PATH, 'django-watchman-{}.txt'.format(uuid.uuid4()))
    content = b'django-watchman test file'
    path = default_storage.save(filename, ContentFile(content))
    default_storage.size(path)
    default_storage.open(path).read()
    default_storage.delete(path)
    return {"ok": True} 
开发者ID:mwarkentin,项目名称:django-watchman,代码行数:10,代码来源:checks.py

示例13: clear_pending_registration

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import delete [as 别名]
def clear_pending_registration(self, email, *course_ids):
        """
        Clear pending enrollments for the user in the given courses.

        Args:
            email: The email address which may have previously been used.
            course_ids: An iterable containing any number of course IDs.
        """
        try:
            pending_ecu = PendingEnterpriseCustomerUser.objects.get(user_email=email, enterprise_customer=self)
        except PendingEnterpriseCustomerUser.DoesNotExist:
            pass
        else:
            PendingEnrollment.objects.filter(user=pending_ecu, course_id__in=course_ids).delete() 
开发者ID:edx,项目名称:edx-enterprise,代码行数:16,代码来源:models.py

示例14: unenroll

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import delete [as 别名]
def unenroll(self, course_run_id):
        """
        Unenroll a user from a course track.
        """
        enrollment_api_client = EnrollmentApiClient()
        if enrollment_api_client.unenroll_user_from_course(self.username, course_run_id):
            EnterpriseCourseEnrollment.objects.filter(enterprise_customer_user=self, course_id=course_run_id).delete()
            return True
        return False 
开发者ID:edx,项目名称:edx-enterprise,代码行数:11,代码来源:models.py

示例15: save_file

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import delete [as 别名]
def save_file(self, name="test.txt", content=b"test", storage=default_storage):
        logging.info("name: %s", name)
        logging.debug("content: %s", content)
        name = storage.save(name, ContentFile(content,name))
        try:
            yield name
        finally:
            storage.delete(name)
            pass 
开发者ID:aliyun,项目名称:django-oss-storage,代码行数:11,代码来源:tests.py


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