#NEWLINE# def get_context( self , name , value , attrs = None , choices = ( ) ) : #NEWLINE# #INDENT# if ( ( not hasattr ( value , '__iter__' ) ) or isinstance ( value , six . string_types ) ) : #NEWLINE# #INDENT# value = [ value ] #NEWLINE# #UNINDENT# context = super ( Select , self ) . get_context ( name , value , attrs ) #NEWLINE# if self . allow_multiple_selected : #NEWLINE# #INDENT# context [ 'attrs' ] [ 'multiple' ] = 'multiple' #NEWLINE# #UNINDENT# groups = [ ] #NEWLINE# for ( option_value , option_label ) in chain ( self . choices , group ) : #NEWLINE# #INDENT# if isinstance ( option_label , ( list , tuple ) ) : #NEWLINE# #INDENT# group = [ ] #NEWLINE# for ( val , lab ) in option_label : #NEWLINE# #INDENT# group . append ( ( force_text ( val ) , lab ) ) #NEWLINE# #UNINDENT# groups . append ( ( option_value , group ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# option_value = force_text ( option_value ) #NEWLINE# if ( groups and ( groups [ ( - 1 ) ] [ 0 ] is None ) ) : #NEWLINE# #INDENT# groups [ ( - 1 ) ] [ 1 ] . append ( ( option_value , option_label ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# groups . append ( ( None , [ ( option_value , option_label ) ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# context [ 'optgroups' ] = groups #NEWLINE# return context