本文整理汇总了Python中nnmware.core.imgutil.remove_thumbnails函数的典型用法代码示例。如果您正苦于以下问题:Python remove_thumbnails函数的具体用法?Python remove_thumbnails怎么用?Python remove_thumbnails使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了remove_thumbnails函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _ajax_upload
def _ajax_upload(self, request, **kwargs):
if request.method == "POST":
tmb = None
self._upload_file(request, **kwargs)
fullpath = os.path.join(settings.MEDIA_ROOT, self.extra_context['path'])
try:
i = Image.open(fullpath)
except:
messages.error(request, "File is not image format")
os.remove(fullpath)
self.success = False
self.pic_id = None
if self.success:
ctype = get_object_or_404(ContentType, id=int(kwargs['content_type']))
object_id = int(kwargs['object_id'])
obj = ctype.get_object_for_this_type(pk=object_id)
try:
remove_thumbnails(obj.img.path)
remove_file(obj.img.path)
obj.img.delete()
except:
pass
obj.img = self.extra_context['path']
obj.save()
# let Ajax Upload know whether we saved it or not
addons = {'tmb': make_thumbnail(obj.img.url, width=int(kwargs['width']), height=int(kwargs['height']),
aspect=int(kwargs['aspect']))}
payload = {'success': self.success, 'filename': self.filename}
if self.extra_context is not None:
payload.update(self.extra_context)
if addons:
payload.update(addons)
return AjaxAnswer(payload)
示例2: delete
def delete(self, *args, **kwargs):
try:
remove_thumbnails(self.img.path)
remove_file(self.img.path)
except:
pass
super(AbstractImg, self).delete(*args, **kwargs)
示例3: delete
def delete(self, *args, **kwargs):
try:
remove_thumbnails(self.pic.path)
remove_file(self.pic.path)
except:
pass
super(Pic, self).delete(*args, **kwargs)
示例4: form_valid
def form_valid(self, form):
action = form.cleaned_data.get('editor_action')
if action == 'resize':
top = int(form.cleaned_data.get('top'))
left = int(form.cleaned_data.get('left'))
right = int(form.cleaned_data.get('right'))
bottom = int(form.cleaned_data.get('bottom'))
if not (top - bottom) or not (left - right):
return super(PicEditor, self).form_valid(form)
image = Image.open(self.object.pic.path)
box = [left, top, right, bottom]
image = image.crop(box)
if image.mode not in ('L', 'RGB'):
image = image.convert('RGB')
image.save(self.object.pic.path)
elif action == 'rotate90':
image = Image.open(self.object.pic.path)
image = image.rotate(90)
if image.mode not in ('L', 'RGB'):
image = image.convert('RGB')
image.save(self.object.pic.path)
elif action == 'rotate270':
image = Image.open(self.object.pic.path)
image = image.rotate(270)
if image.mode not in ('L', 'RGB'):
image = image.convert('RGB')
image.save(self.object.pic.path)
remove_thumbnails(self.object.pic.path)
self.object.save()
return super(PicEditor, self).form_valid(form)
示例5: delete
def delete(self, *args, **kwargs):
try:
remove_thumbnails(self.agent_img.path)
remove_file(self.agent_img.path)
except:
pass
super(AbstractEmployee, self).delete(*args, **kwargs)
示例6: form_valid
def form_valid(self, form):
avatar_path = self.object.avatar.url
remove_thumbnails(avatar_path)
remove_file(avatar_path)
self.object = form.save(commit=False)
self.object.avatar_complete = False
self.object.save()
resize_image(self.object.avatar.url)
return super(AvatarEdit, self).form_valid(form)
示例7: avatar_delete
def avatar_delete(request):
try:
u = request.user
remove_thumbnails(u.img.url)
remove_file(u.img.url)
u.img = ''
u.save()
payload = {'success': True}
except:
payload = {'success': False}
return AjaxLazyAnswer(payload)
示例8: avatar_delete
def avatar_delete(request):
try:
profile = request.user.get_profile()
remove_thumbnails(profile.avatar.url)
remove_file(profile.avatar.url)
profile.avatar = ''
profile.save()
payload = {'success': True}
except:
payload = {'success': False}
return AjaxLazyAnswer(payload)
示例9: avatar_delete
def avatar_delete(request):
try:
remove_thumbnails(request.user.img.url)
remove_file(request.user.img.url)
request.user.img = ''
request.user.save()
payload = {'success': True}
try:
addons = dict(html=render_to_string('user/avatar.html', {'object': request.user}))
except:
addons = {}
payload.update(addons)
except:
payload = {'success': False}
return ajax_answer_lazy(payload)
示例10: avatardelete
def avatardelete(request):
if request.is_ajax():
try:
u = request.user
remove_thumbnails(u.img.path)
remove_file(u.img.path)
u.avatar_complete = False
u.img = None
u.save()
payload = {'success': True}
except:
payload = {'success': False}
return ajax_answer_lazy(payload)
else:
raise Http404()
示例11: avatardelete
def avatardelete(request):
if request.is_ajax():
try:
profile = request.user.get_profile()
remove_thumbnails(profile.avatar.path)
remove_file(profile.avatar.path)
profile.avatar_complete = False
profile.avatar = None
profile.save()
payload = {'success': True}
except:
payload = {'success': False}
return AjaxLazyAnswer(payload)
else:
raise Http404()
示例12: save
def save(self, *args, **kwargs):
pics = Pic.objects.for_object(self.content_object)
if self.pk:
pics = pics.exclude(pk=self.pk)
if IMG_MAX_PER_OBJECT > 1:
if self.primary:
pics = pics.filter(primary=True)
pics.update(primary=False)
else:
pics.delete()
try:
remove_thumbnails(self.pic.path)
except:
pass
fullpath = get_path_from_url(self.pic.url)
self.size = os.path.getsize(fullpath)
super(Pic, self).save(*args, **kwargs)
示例13: avatar_set
def avatar_set(request):
uploader = AjaxUploader(filetype='image', upload_dir=setting('AVATAR_UPLOAD_DIR', 'avatars'),
size_limit=setting('AVATAR_UPLOAD_SIZE', 1024000))
result = uploader.handle_upload(request)
if result['success']:
try:
remove_thumbnails(request.user.img.url)
remove_file(request.user.img.url)
except:
pass
request.user.img = result['path']
request.user.save()
try:
addons = dict(html=render_to_string('user/avatar.html', {'object': request.user}))
except:
addons = {}
result.update(addons)
return ajax_answer_lazy(result)
示例14: file_uploader
def file_uploader(request, **kwargs):
uploader = AjaxUploader(filetype='image', upload_dir=setting('IMAGE_UPLOAD_DIR', 'images'),
size_limit=setting('IMAGE_UPLOAD_SIZE', 10485760))
result = uploader.handle_upload(request)
if result['success']:
ctype = get_object_or_404(ContentType, id=int(kwargs['content_type']))
object_id = int(kwargs['object_id'])
obj = ctype.get_object_for_this_type(pk=object_id)
try:
remove_thumbnails(obj.img.path)
remove_file(obj.img.path)
obj.img.delete()
except:
pass
obj.img = result['path']
obj.save()
try:
addons = dict(tmb=make_thumbnail(obj.img.url, width=int(kwargs['width']), height=int(kwargs['height']),
aspect=int(kwargs['aspect'])))
except:
addons = {}
result.update(addons)
return AjaxAnswer(result)