#NEWLINE# @ detail_route ( methods = [ 'DELETE' , 'GET' , 'POST' , 'PUT' ] ) #NEWLINE# def members( self , request , * args , **kwargs ) : #NEWLINE# #INDENT# organization = self . get_object ( ) #NEWLINE# status_code = status . HTTP_200_OK #NEWLINE# data = [ ] #NEWLINE# username = ( request . data . get ( 'username' ) or request . query_params . get ( 'username' ) ) #NEWLINE# if ( ( request . method in [ 'DELETE' , 'POST' , 'PUT' ] ) and ( not username ) ) : #NEWLINE# #INDENT# status_code = status . HTTP_400_BAD_REQUEST #NEWLINE# data = { #NEWLINE# #INDENT# 'username' : [ _ ( 'This field is required.' ) ] , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# ( data , status_code ) = _add_username_to_organization ( organization , username ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( request . method == 'PUT' ) : #NEWLINE# #INDENT# role = request . data . get ( 'role' ) #NEWLINE# role_cls = ROLES . get ( role ) #NEWLINE# if ( ( not role ) or ( not role_cls ) ) : #NEWLINE# #INDENT# status_code = status . HTTP_400_BAD_REQUEST #NEWLINE# message = ( _ ( ( "'%s' is not a valid role." % role ) ) if role else _ ( 'This field is required.' ) ) #NEWLINE# data = { #NEWLINE# #INDENT# 'role' : [ message ] , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# _update_username_role ( organization , username , role_cls ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( request . method == 'DELETE' ) : #NEWLINE# #INDENT# ( data , status_code ) = _remove_username_to_organization ( organization , username ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( status_code in [ status . HTTP_200_OK , status . HTTP_201_CREATED ] ) : #NEWLINE# #INDENT# members = get_organization_members ( organization ) #NEWLINE# data = [ u . username for u in members ] #NEWLINE# #UNINDENT# return Response ( data , status = status_code )