(request)
return ajax_error("Invalid action")
Delete an object.
Delete an object.
Delete an object .
def toggle_delete(request):
    """
    Delete an object.
    """

    type_map = dict(job=Job, data=Data, recipe=Analysis)
    uid = request.POST.get('uid', "")
    obj_type = request.POST.get('type', '')

    obj_model = type_map.get(obj_type)

    if not obj_model:
        return ajax_error(f"Invalid data type:{obj_type}")

    obj = obj_model.objects.filter(uid=uid).first()

    if not obj:
        return ajax_error("Object does not exists.")

    access = auth.is_writable(user=request.user, project=obj.project)

    # Toggle the delete state if the user has write access
    if access:
        auth.delete_object(obj=obj, request=request)
        # Re-set project counts
        obj.project.set_counts(save=True)
        counts = obj_model.objects.filter(project=obj.project, deleted=False).count()
        return ajax_success(msg='Toggled delete', counts=counts)

    return ajax_error("Invalid action")
def toggle_delete ( request ) : type_map = dict ( job = Job , data = Data , recipe = Analysis ) uid = request . POST . get ( 'uid' , "" ) obj_type = request . POST . get ( 'type' , '' ) obj_model = type_map . get ( obj_type ) if not obj_model : return ajax_error ( f"Invalid data type:{obj_type}" ) obj = obj_model . objects . filter ( uid = uid ) . first ( ) if not obj : return ajax_error ( "Object does not exists." ) access = auth . is_writable ( user = request . user , project = obj . project ) # Toggle the delete state if the user has write access if access : auth . delete_object ( obj = obj , request = request ) # Re-set project counts obj . project . set_counts ( save = True ) counts = obj_model . objects . filter ( project = obj . project , deleted = False ) . count ( ) return ajax_success ( msg = 'Toggled delete' , counts = counts ) return ajax_error ( "Invalid action" )