#NEWLINE# def __init__( self , choices , order_by = 'display' ) : #NEWLINE# #INDENT# '\n\n        :param choices: dictionary of dictionary . ex: {\'choice1\': {\'id\':1, \'display\': \'Code One\'}, ...}\n        display key is optional. if not provided its assumed to be dict_key.replace("_", " ").capitalize()\n        :type choices: Choices | OrderedDict | dict | tuple | list\n        :param order_by: Whether generated Django choice list should be ordered (valid options "id", "display", None)\n        :type  order_by: str | None\n        ' #NEWLINE# self . _read_only = False #NEWLINE# super ( Choices , self ) . __init__ ( choices ) #NEWLINE# self . _choices = _choices = [ ] #NEWLINE# self . _order_by = order_by #NEWLINE# if ( not choice_code ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# choice_ids = set ( ) #NEWLINE# for ( choice_code , choice_options ) in self . items ( ) : #NEWLINE# #INDENT# if ( not issubclass ( choice_options . __class__ , dict ) ) : #NEWLINE# #INDENT# choice_options = { #NEWLINE# #INDENT# 'id' : choice_options , #NEWLINE# #UNINDENT# } #NEWLINE# self [ choice_code ] = choice_options #NEWLINE# #UNINDENT# choice_id = choice_options [ 'id' ] #NEWLINE# choice_ids . add ( choice_id ) #NEWLINE# if ( 'display' not in choice_options ) : #NEWLINE# #INDENT# choice_options [ 'display' ] = choice_code . replace ( '_' , ' ' ) . capitalize ( ) #NEWLINE# #UNINDENT# display = choice_options [ 'display' ] #NEWLINE# _choices . append ( ( choice_id , _ ( display ) ) ) #NEWLINE# #UNINDENT# if ( order_by == 'display' ) : #NEWLINE# #INDENT# _choices . sort ( key = ( lambda x : x [ 1 ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( order_by == 'id' ) : #NEWLINE# #INDENT# _choices . sort ( key = ( lambda x : x [ 0 ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# self . _read_only = True