#NEWLINE# @ login_required ( ) #NEWLINE# def users_group( request , group ) : #NEWLINE# #INDENT# if request . user . is_superuser : #NEWLINE# #INDENT# extra_context = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# g = group #NEWLINE# if g : #NEWLINE# #INDENT# grp = UserGroup . objects . get ( pk = g ) #NEWLINE# for ancestor in reversed ( grp . get_ancestors ( ) [ 2 : ] ) : #NEWLINE# #INDENT# grp . name = ( ( ancestor . name + ' / ' ) + grp . name ) #NEWLINE# #UNINDENT# extra_context [ 'group_name' ] = grp . name #NEWLINE# extra_context [ 'group_id' ] = grp . id #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# grp = None #NEWLINE# extra_context [ 'group_id' ] = '' #NEWLINE# #UNINDENT# if ( ( request . method == 'POST' ) and grp ) : #NEWLINE# #INDENT# selected = request . POST . getlist ( '_selected_action' ) #NEWLINE# args = [ obj for obj in UserProfile . objects . filter ( user__in = selected ) ] #NEWLINE# grp . userprofile_set . clear ( ) #NEWLINE# grp . userprofile_set . add ( * args ) #NEWLINE# u = request . POST . get ( 'u' , '' ) #NEWLINE# if u : #NEWLINE# #INDENT# u = User . objects . get ( pk = u ) . get_profile ( ) #NEWLINE# u . groups . add ( grp ) #NEWLINE# #UNINDENT# #UNINDENT# if grp : #NEWLINE# #INDENT# up = grp . userprofile_set . all ( ) #NEWLINE# extra_context [ 'users_groups' ] = [ g . user_id for g in up ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# extra_context [ 'users_groups' ] = [ ] #NEWLINE# #UNINDENT# group_lists = User . objects . filter ( pk__in = extra_context [ 'users_groups' ] ) . order_by ( 'first_name' ) #NEWLINE# return object_list ( request , queryset = group_lists , template_name = 'account/users_group.html' , extra_context = extra_context , paginate_by = 20 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return HttpResponseRedirect ( '/' )