Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def delete(request, media_id):
Media = get_media_model()
media = get_object_or_404(Media, id=media_id)
if not permission_policy.user_has_permission_for_instance(request.user, 'delete', media):
return permission_denied(request)
if request.POST:
media.delete()
messages.success(request, _("Media file '{0}' deleted.").format(media.title))
return redirect('wagtailmedia:index')
return render(request, "wagtailmedia/media/confirm_delete.html", {
'media': media,
})
except OSError:
# File doesn't exist
pass
if not filesize:
messages.error(
request,
_("The file could not be found. Please change the source or delete the media file"),
buttons=[messages.button(reverse('wagtailmedia:delete', args=(media.id,)), _('Delete'))]
)
return render(request, "wagtailmedia/media/edit.html", {
'media': media,
'filesize': filesize,
'form': form,
'user_can_delete': permission_policy.user_has_permission_for_instance(
request.user, 'delete', media
),