• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python thumbnail.delete函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sorl.thumbnail.delete函数的典型用法代码示例。如果您正苦于以下问题:Python delete函数的具体用法?Python delete怎么用?Python delete使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: delete_old_avatar

def delete_old_avatar(sender, instance, **kwargs):
    if instance.avatar:
        if not str(instance.avatar).startswith('avatars'):
            user = instance.user
            profile = user.get_profile()
            if profile.avatar:
                delete(profile.avatar)
开发者ID:enml,项目名称:lianpeng,代码行数:7,代码来源:models.py


示例2: termination

def termination(request):
    form = TerminationForm()
    if request.method == "POST":
        form = TerminationForm(request.POST)
        if form.is_valid():
            person = Person.objects.get(username=request.user)
            board = Board.objects.filter(user=request.user)
            picture = Picture.objects.filter(board=board)
            for p in picture:
                delete(p.image)
                p.delete()
            for b in board:
                b.delete()
            friend = Friend.objects.friends(person)
            for f in friend:
                Friend.objects.remove_friend(person, f)
            following = Follow.objects.following(request.user)
            for f in following:
                Follow.objects.remove_follower(person, f)
            for f in following:
                Follow.objects.remove_follower(person, f)
            requests = Friend.objects.unread_requests(user=request.user)
            for f in requests:
                f.delete()
            person.is_active = False
            person.email = None
            person.date_of_birth = None
            person.image.delete()
            person.save()
            return HttpResponseRedirect(reverse('world:logout_request'))
    return render(request, 'termination.html', {'form': form})
开发者ID:richard-gh,项目名称:sparkalight,代码行数:31,代码来源:views.py


示例3: _clear_thumbnails

    def _clear_thumbnails(self):
        """ Actual code to clear the thumbnails.  Private.
        """

        delete(self.image, delete_file=False)
        self.thumbs_created = False
        self.save()
开发者ID:ginking,项目名称:fotochest,代码行数:7,代码来源:models.py


示例4: delete

	def delete(self, request, *args, **kwargs):
		self.object = self.get_object()
		user = request.user
		blog_posts = BlogPost.objects.published(for_user=user).select_related().filter(user=user)

		if blog_posts and blog_posts[0]:
			blog_post = blog_posts[0]
			blog_post.num_images = blog_post.num_images - self.object.images.all().count()
			blog_post.save()

		for image in self.object.images.all():
			delete(image.image)
			content_type_id = ContentType.objects.get_for_model(image).pk
			deleteObject(request, content_type_id, image.pk)
			

		media_root = getattr(settings, 'MEDIA_ROOT', '/')
		album_dir = self.object.get_album_path()
		album_abs_dir = os.path.join(media_root, album_dir)
		os.rmdir(album_abs_dir)
		
		content_type_id = ContentType.objects.get_for_model(self.object).pk
		deleteObject(request, content_type_id, self.object.pk)
		
		return HttpResponseRedirect(self.get_success_url())
开发者ID:saumishr,项目名称:imagestore,代码行数:25,代码来源:views.py


示例5: delete_thumbnails

 def delete_thumbnails(self, source):
     from sorl.thumbnail import delete
     from sorl.thumbnail.helpers import ThumbnailError
     try:
         delete(source)
     except ThumbnailError:
         pass
开发者ID:django-oscar,项目名称:django-oscar,代码行数:7,代码来源:thumbnails.py


示例6: _delete_thumbnail

 def _delete_thumbnail(self, sender, instance=None, delete_file=True,
         **kwargs):
     image = getattr(instance, self.attname)
     if hasattr(image, 'path'):
         # Use sorl.thumbnail.delete to delete thumbnail
         # Key Value Store references, cached files and optionally
         # the source image file
         thumbnail.delete(image.path, delete_file)
开发者ID:eyeyunianto,项目名称:satchmo,代码行数:8,代码来源:field.py


示例7: delete

    def delete(self):
        # deleting the associated file
        # trying sorl before file system
        try:
            from sorl.thumbnail import delete

            delete(self.file.file)
        except:
            os.remove(self.file.path)

        super(SFFile, self).delete()
开发者ID:shinyfrog,项目名称:SFDjangoUtils,代码行数:11,代码来源:sfFile.py


示例8: delete_image_files

def delete_image_files(sender, instance, **kwargs):
    """
    Deletes the original image, created thumbnails, and any entries
    in sorl's key-value store.
    """
    image_fields = (models.ImageField, thumbnail.ImageField)
    for field in instance._meta.fields:
        if isinstance(field, image_fields):
            # Make Django return ImageFieldFile instead of ImageField
            fieldfile = getattr(instance, field.name)
            thumbnail.delete(fieldfile)
开发者ID:Dinesh-Ramakrishnan,项目名称:django-oscar,代码行数:11,代码来源:receivers.py


示例9: crop

 def crop(self, x=None, y=None, x2=None, y2=None):
     if not all((x, y, x2, y2)):
         raise ValueError('All points are required')
     file_name = self.raw_image.name
     im = Image.open(self.raw_image.file)
     cropped = im.copy()
     cropped = cropped.crop((x, y, x2, y2))
     new_file = StringIO()
     cropped.save(new_file, 'jpeg')
     file_content = ContentFile(new_file.getvalue())
     self.image.save(file_name, file_content)
     delete(self.image, delete_file=False)
开发者ID:Bjwebb,项目名称:electionleaflets,代码行数:12,代码来源:models.py


示例10: delete_images

def delete_images(sender, **kwargs):
    u"""Удаление изображений при удалении объявления."""
    instance   = kwargs['instance']
    all_images = [instance.image_1, instance.image_2,instance.image_3,
                  instance.image_4]
    
    for image in all_images:
        if image:
            try:
                thumbnail.delete(image)
            except IOError as e:
                logger.error(u'Не удалось удалить изображение: {0}'.format(e))
开发者ID:relique,项目名称:izba,代码行数:12,代码来源:signals.py


示例11: clean_thumbnails

    def clean_thumbnails(self):
        Thumbnail.objects.filter(media=self).delete()
        try:
            delete(self.original_file.file, delete_file=False)
        except (IOError, ValueError):
            pass

        try:
            if self.custom_file:
                delete(self.custom_file.file, delete_file=False)
        except (IOError, ValueError):
            pass
开发者ID:divadrei,项目名称:gallery,代码行数:12,代码来源:media.py


示例12: save

 def save(self, *args, **kwargs):
     if not self.id:
         # Have to save the image (and imagefield) first
         super(BaseImage, self).save(*args, **kwargs)
         # obj is being created for the first time - resize
         quality = getattr(settings, 'IMAGESTORE_IMAGE_QUALITY', 95)
         resized = get_thumbnail(self.image, "1000x1000", quality=quality)
         # Delete the original image and reassign the resized image to the image field
         self.image.delete()
         self.image.save(resized.name, ContentFile(resized.read()), True)
         delete(resized)
     super(BaseImage, self).save(*args, **kwargs)
开发者ID:saumishr,项目名称:imagestore,代码行数:12,代码来源:image.py


示例13: save

    def save(self, *args, **kwargs):
        """
        Override default save operation.

        Username will be swapped with email.
        """
        self.username = self.email

        if self.previous_avatar and self.avatar != self.previous_avatar:
            delete(self.previous_avatar)
            self.previous_avatar = None

        super(User, self).save(*args, **kwargs)
开发者ID:jzvelc,项目名称:djangotest,代码行数:13,代码来源:models.py


示例14: cat_album_thumb

def cat_album_thumb(request, album_id, thumb_size=250):
    a = CatAlbum.objects.filter(pk=album_id).first()
    random_image = a.photos.order_by('?').first()
    thumb_str = str(thumb_size) + 'x' + str(thumb_size)
    im = get_thumbnail(random_image.image, thumb_str, upscale=False)
    try:
        content = im.read()
    except IOError:
        delete(im)
        im = get_thumbnail(random_image.image, thumb_str, upscale=False)
        content = im.read()
    response = HttpResponse(content, content_type='image/jpg')
    response['Content-Length'] = len(content)

    return response
开发者ID:Ajapaik,项目名称:sift-pics-web,代码行数:15,代码来源:views.py


示例15: cat_photo

def cat_photo(request, photo_id=None, thumb_size=600, slug=None):
    p = get_object_or_404(CatPhoto, id=photo_id)
    thumb_str = str(thumb_size) + 'x' + str(thumb_size)
    im = get_thumbnail(p.image, thumb_str, upscale=False)
    try:
        content = im.read()
    except IOError:
        delete(im)
        im = get_thumbnail(p.image, thumb_str, upscale=False)
        content = im.read()

    response = HttpResponse(content, content_type='image/jpg')
    response['Content-Length'] = len(content)

    return response
开发者ID:Ajapaik,项目名称:sift-pics-web,代码行数:15,代码来源:views.py


示例16: upload_photo

def upload_photo(request, eb_id=None, id=None):
    if id:
        attendee = get_object_or_404(Attendee, id=id)
    elif eb_id:
        attendee = get_object_or_404(Attendee, eb_id=eb_id)
    else:
        raise Exception("missing parameter")
    photo = request.FILES['photo']
    if not photo:
        return HttpResponseBadRequest("missing photo")
    if attendee.photo:
        thumbnail.delete(attendee.photo.name, delete_file=False)
    attendee.photo.save(photo.name, photo)
    photo_url = attendee.photo.url
    return HttpResponse(json.dumps({
        'eb_id': attendee.eb_id,
        'id': attendee.id,
        'first_name': attendee.first_name,
        'last_name': attendee.last_name,
        'photo': photo_url}), mimetype='application/json')
开发者ID:vonkow,项目名称:bcb_attendees,代码行数:20,代码来源:views.py


示例17: test_delete

    def test_delete(self):
        im1 = Item.objects.get(image='100x100.jpg').image
        im2 = Item.objects.get(image='500x500.jpg').image
        default.kvstore.get_or_set(ImageFile(im1))
        # exists in kvstore and in storage 
        self.assertTrue(bool(default.kvstore.get(ImageFile(im1))))
        self.assertTrue(ImageFile(im1).exists())
        # delete
        delete(im1)
        self.assertFalse(bool(default.kvstore.get(ImageFile(im1))))
        self.assertFalse(ImageFile(im1).exists())

        default.kvstore.get_or_set(ImageFile(im2))
        # exists in kvstore and in storage 
        self.assertTrue(bool(default.kvstore.get(ImageFile(im2))))
        self.assertTrue(ImageFile(im2).exists())
        # delete
        delete(im2, delete_file=False)
        self.assertFalse(bool(default.kvstore.get(ImageFile(im2))))
        self.assertTrue(ImageFile(im2).exists())
开发者ID:dokterbob,项目名称:sorl-thumbnail,代码行数:20,代码来源:tests.py


示例18: rotate

 def rotate(self, rotate_angle):
     """
     Make sure we rotate both images.
     """
     if not self.raw_image:
         self.raw_image = self.image
         self.raw_image.save()
     for image_field in (
         # self.raw_image,
         self.image,
         ):
         file_name = image_field.name
         im = Image.open(image_field.file)
         rotated = im.copy()
         rotated = rotated.rotate(rotate_angle)
         new_file = StringIO()
         rotated.save(new_file, 'jpeg')
         file_content = ContentFile(new_file.getvalue())
         image_field.save(file_name, file_content)
         delete(self.image, delete_file=False)
开发者ID:Bjwebb,项目名称:electionleaflets,代码行数:20,代码来源:models.py


示例19: validate_resizable

def validate_resizable(image):
    """Check if image can't be resized with solr-thumbnail.
    Some resizing backend fail to resize specific images so check is needed

    """
    try:
        # if file is just uploaded then it's not saved. Save it to temp location
        data = image.file
        path = default_storage.save(
            'tmp/' + uuid1().hex, ContentFile(data.read()))
        temp_file = default_storage.open(path)
        get_thumbnail(temp_file, "100x100")
        temp_file.close()
        delete(temp_file)
    except Exception, msg:
        if settings.DEBUG:
            traceback.print_exc()
            raise ValidationError(u"Image is corrupted: %s" % msg)
        else:
            raise ValidationError(
                u"Image is corrupted and can't be resized by server.")
开发者ID:42,项目名称:42-bootstrap,代码行数:21,代码来源:validators.py


示例20: add_watermark

def add_watermark(main_folder, image_file, path_watermark, all_size={'x':0,'x2':100,'y':0,'y2':100},opacity=0.5):
    if all_size['x']=="" or all_size['x2']=="" or all_size['y']=="" \
        or all_size['y2']=="" or all_size['w_view']=="" or all_size['h_view']=="":
        return False

    path_to_folder = MEDIA_ROOT + main_folder
    result_file = WATERMARK_PREFIX + image_file
    path_watermark = MEDIA_ROOT + path_watermark

    if os.path.isfile(path_to_folder+image_file):
        shutil.copyfile(path_to_folder+image_file, path_to_folder+result_file)

        if os.path.isfile(path_to_folder+result_file):
            os.chmod(path_to_folder+result_file, 0755)
            result_file_path = path_to_folder+result_file

            # Открываем текущее изобразение изображение
            image = Image.open(result_file_path, 'r')

            w_orig = image.size[0]
            h_orig = image.size[1]
            w_koef = float(w_orig)/int(all_size['w_view'])
            h_koef = float(h_orig)/int(all_size['h_view'])

            x = int(int(all_size['x'])*w_koef)
            x2 = int(int(all_size['x2'])*w_koef)
            y = int(int(all_size['y'])*h_koef)
            y2 = int(int(all_size['y2'])*h_koef)
            w_watermark = x2 - x
            h_watermark = y2 - y

            if w_watermark!=0 and h_watermark!=0:
                watermark_size = str(w_watermark)+'x'+str(h_watermark)
                path_watermark = MEDIA_ROOT.replace('/media/','')+get_thumbnail(path_watermark, watermark_size,
                                                           crop='center', quality=99).url
                # Открываем водяной знак
                if os.path.isfile(path_watermark):
                    watermark = Image.open(path_watermark, 'r')
                    assert opacity >= 0 and opacity <= 1
                    if opacity < 1:
                        if watermark.mode != 'RGBA':
                            watermark = watermark.convert('RGBA')
                        else:
                            watermark = watermark.copy()
                        alpha = watermark.split()[3]
                        alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
                        watermark.putalpha(alpha)

                    layer = Image.new('RGBA', image.size, (0,0,0,0))
                    layer.paste(watermark, (x, y))

                    Image.composite(layer,  image,  layer).save(result_file_path)
                    Image.composite(layer,  image,  layer).save(result_file_path)



                    # Delete the Key Value Store reference but **not** the file.
                    # Use this if you have changed the source
                    delete(main_folder + result_file, delete_file=False)

                    return result_file
    return False
开发者ID:Megajoe17,项目名称:DJANGO-PYTHON-USEFULL-UTILS,代码行数:62,代码来源:other_utils_func.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python thumbnail.get_thumbnail函数代码示例发布时间:2022-05-27
下一篇:
Python web.quote函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap