@must_be_valid_project
@must_not_be_registration
@must_have_permission(WRITE)
def project_reorder_components(node, **kwargs):
 NodeRelation = apps.get_model('osf.NodeRelation')
 new_node_guids = [each.split(':') for each in request.get_json().get('new_list', [])]
 new_node_relation_ids = [(NodeRelation.load(id_).id if (type_ == 'pointer') else node.node_relations.get(child__guids___id=id_).id) for (id_, type_) in new_node_guids]
 node_relations = node.node_relations.select_related('child').all()
 valid_node_relation_ids = [each.id for each in node_relations if (not each.child.is_deleted)]
 deleted_node_relation_ids = [each.id for each in node_relations if each.child.is_deleted]
 if ((len(valid_node_relation_ids) == len(new_node_guids)) and (set(valid_node_relation_ids) == set(new_node_relation_ids))):
  node.set_noderelation_order((new_node_relation_ids + deleted_node_relation_ids))
  node.save()
  return {}
 logger.error('Got invalid node list in reorder components')
 raise HTTPError(http.BAD_REQUEST)

@ must_be_valid_project @ must_not_be_registration @ must_have_permission ( WRITE ) def project_reorder_components ( node , ** kwargs ) : NodeRelation = apps . get_model ( 'osf.NodeRelation' ) new_node_guids = [ each . split ( ':' ) for each in request . get_json ( ) . get ( 'new_list' , [ ] ) ] new_node_relation_ids = [ ( NodeRelation . load ( id_ ) . id if ( type_ == 'pointer' ) else node . node_relations . get ( child__guids___id = id_ ) . id ) for ( id_ , type_ ) in new_node_guids ] node_relations = node . node_relations . select_related ( 'child' ) . all ( ) valid_node_relation_ids = [ each . id for each in node_relations if ( not each . child . is_deleted ) ] deleted_node_relation_ids = [ each . id for each in node_relations if each . child . is_deleted ] if ( ( len ( valid_node_relation_ids ) == len ( new_node_guids ) ) and ( set ( valid_node_relation_ids ) == set ( new_node_relation_ids ) ) ) : node . set_noderelation_order ( ( new_node_relation_ids + deleted_node_relation_ids ) ) node . save ( ) return { } logger . error ( 'Got invalid node list in reorder components' ) raise HTTPError ( http . BAD_REQUEST )
reorders the components in a projects component list .