#NEWLINE# def set_clearinghouse( request ) : #NEWLINE# #INDENT# if ( not request . user . is_staff ) : #NEWLINE# #INDENT# return HttpResponseRedirect ( '/dashboard' ) #NEWLINE# #UNINDENT# ch_users = UserProfile . objects . filter ( is_clearinghouse_user = True ) #NEWLINE# profile = None #NEWLINE# if ( len ( ch_users ) == 1 ) : #NEWLINE# #INDENT# profile = ch_users [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ch_users . count ( ) > 1 ) : #NEWLINE# #INDENT# logger . debug ( 'More than one clearinghouse user in OM!!!' ) #NEWLINE# raise Exception ( 'There are more than one clearinghouse user! Unexpected error.' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# form = CHUserForm ( request . POST ) #NEWLINE# if form . is_valid ( ) : #NEWLINE# #INDENT# if ( len ( ch_users ) == 0 ) : #NEWLINE# #INDENT# ch_user = User ( username = request . POST [ 'username' ] ) #NEWLINE# ch_user . set_password ( request . POST [ 'password1' ] ) #NEWLINE# ch_user . save ( ) #NEWLINE# ch_profile = UserProfile . get_or_create_profile ( ch_user ) #NEWLINE# ch_profile . is_net_admin = False #NEWLINE# ch_profile . is_clearinghouse_user = True #NEWLINE# ch_profile . max_priority_level = 0 #NEWLINE# ch_profile . save ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# profile . user . username = request . POST [ 'username' ] #NEWLINE# profile . user . set_password ( request . POST [ 'password1' ] ) #NEWLINE# profile . user . save ( ) #NEWLINE# #UNINDENT# return HttpResponseRedirect ( '/dashboard' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( ch_users ) == 1 ) : #NEWLINE# #INDENT# form = CHUserForm ( pack_ch_user_info ( profile . user ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# form = CHUserForm ( ) #NEWLINE# #UNINDENT# #UNINDENT# return simple . direct_to_template ( request , template = 'openflow/optin_manager/controls/set_clearinghouse.html' , extra_context = { #NEWLINE# #INDENT# 'profile' : profile , #NEWLINE# 'form' : form , #NEWLINE# #UNINDENT# } )