#NEWLINE# @ require_POST #NEWLINE# @ xframe_options_sameorigin #NEWLINE# def del_image_async( request , image_id ) : #NEWLINE# #INDENT# 'Delete an image given its object id.' #NEWLINE# user = request . user #NEWLINE# if ( not user . is_authenticated ( ) ) : #NEWLINE# #INDENT# message = _ ( 'You are not logged in.' ) #NEWLINE# return HttpResponseForbidden ( json . dumps ( { #NEWLINE# #INDENT# 'status' : 'error' , #NEWLINE# 'message' : message , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# image = ImageAttachment . objects . get ( pk = image_id ) #NEWLINE# #UNINDENT# except ImageAttachment . DoesNotExist : #NEWLINE# #INDENT# message = _ ( 'The requested image could not be found.' ) #NEWLINE# return HttpResponseNotFound ( json . dumps ( { #NEWLINE# #INDENT# 'status' : 'error' , #NEWLINE# 'message' : message , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# #UNINDENT# if ( not ( ( user == image . creator ) or user . has_perm ( 'upload.delete_imageattachment' ) ) ) : #NEWLINE# #INDENT# message = _ ( 'You do not have permission to do that.' ) #NEWLINE# return HttpResponseForbidden ( json . dumps ( { #NEWLINE# #INDENT# 'status' : 'error' , #NEWLINE# 'message' : message , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# #UNINDENT# image . file . delete ( ) #NEWLINE# if image . thumbnail : #NEWLINE# #INDENT# image . thumbnail . delete ( ) #NEWLINE# #UNINDENT# image . delete ( ) #NEWLINE# return HttpResponse ( json . dumps ( { #NEWLINE# #INDENT# 'status' : 'success' , #NEWLINE# #UNINDENT# } ) )