@login_required
@ajax_only
def gallery_image_delete(request, project_image_id):
    project_image = get_object_or_404(ProjectImage, id=project_image_id)
    try:
        project_step = project_image.projectstep_set.all()[0]
    except __HOLE__:
        # If the image doesn't belong to a project step, no need to check for
        # permission (and it isn't possible)
        pass
    else:
        if not project_step.is_editable(request):
            return HttpResponseForbidden('You are not the owner of this image.')
    # Remove the actual file, then the database record and return True
    project_image.file.delete()
    project_image.delete()
    return AjaxResponse(request, True)
dataset/ETHPy150Open python/raspberryio/raspberryio/project/views.py/gallery_image_delete