本文整理汇总了Python中sorl.thumbnail.delete函数的典型用法代码示例。如果您正苦于以下问题:Python delete函数的具体用法?Python delete怎么用?Python delete使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了delete函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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})
示例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()
示例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())
示例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
示例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)
示例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()
示例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)
示例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)
示例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))
示例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
示例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)
示例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)
示例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
示例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