#NEWLINE# def render_options( self , choices , selected_choices ) : #NEWLINE# #INDENT# def render_option( option_value , option_label ) : #NEWLINE# #INDENT# option_value = force_unicode ( option_value ) #NEWLINE# selected_html = ( ( ( option_value in selected_choices ) and ' selected="selected"' ) or '' ) #NEWLINE# return ( '<option value="%s"%s>%s</option>' % ( escape ( option_value ) , selected_html , conditional_escape ( force_unicode ( option_label ) ) ) ) #NEWLINE# #UNINDENT# selected_choices = set ( [ force_unicode ( v ) for v in selected_choices ] ) #NEWLINE# output = [ ] #NEWLINE# for ( option_value , option_label ) in chain ( self . choices , choices ) : #NEWLINE# #INDENT# if isinstance ( option_label , ( list , tuple ) ) : #NEWLINE# #INDENT# output . append ( ( '<optgroup label="%s">' % escape ( force_unicode ( option_value ) ) ) ) #NEWLINE# for option in option_label : #NEWLINE# #INDENT# output . append ( render_option ( * option ) ) #NEWLINE# #UNINDENT# output . append ( '</optgroup>' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# output . append ( render_option ( option_value , option_label ) ) #NEWLINE# #UNINDENT# #UNINDENT# return '\n' . join ( output )