#NEWLINE# def __init__( self , * args , **kwargs ) : #NEWLINE# #INDENT# initial = kwargs . get ( 'initial' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# instance = kwargs . get ( 'instance' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# user_is_admin = kwargs . pop ( 'user_is_admin' , False ) #NEWLINE# if instance : #NEWLINE# #INDENT# groups = instance . groups . all ( ) #NEWLINE# initial [ 'user_level' ] = ( groups [ 0 ] . id if groups . exists ( ) else None ) #NEWLINE# initial [ 'is_active' ] = instance . is_active #NEWLINE# #UNINDENT# kwargs [ 'initial' ] = initial #NEWLINE# super ( UserChangeForm , self ) . __init__ ( * args , ** self ) #NEWLINE# if ( not user_is_admin ) : #NEWLINE# #INDENT# self . fields . pop ( 'user_level' , None ) #NEWLINE# self . fields . pop ( 'is_active' , None ) #NEWLINE# #UNINDENT# f = self . fields . get ( 'user_permissions' , None ) #NEWLINE# if ( f is not None ) : #NEWLINE# #INDENT# f . queryset = f . queryset . select_related ( 'content_type' )