#NEWLINE# def clean( self , data , initial = None ) : #NEWLINE# #INDENT# ret = list ( ) #NEWLINE# for ( i , data_item ) in enumerate ( data ) : #NEWLINE# #INDENT# if data_item . get ( 'DELETE' , False ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( initial and ( len ( initial ) > i ) ) : #NEWLINE# #INDENT# initial_item = initial [ initial ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# initial_item = None #NEWLINE# #UNINDENT# val = self . subfield . bound_data ( data_item [ 'value' ] , initial_item ) #NEWLINE# arg_spec = inspect . getargspec ( self . subfield . clean ) #NEWLINE# try : #NEWLINE# #INDENT# if ( len ( arg_spec . args ) > 2 ) : #NEWLINE# #INDENT# val = self . subfield . clean ( val , initial_item ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# val = self . subfield . clean ( val ) #NEWLINE# #UNINDENT# #UNINDENT# except ValidationError : #NEWLINE# #INDENT# if val : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if val : #NEWLINE# #INDENT# ret . append ( ( val , data_item . get ( 'ORDER' , None ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# def compare_ordering_key( k ) : #NEWLINE# #INDENT# if ( k [ 1 ] is None ) : #NEWLINE# #INDENT# return ( 1 , 0 ) #NEWLINE# #UNINDENT# return ( 0 , k [ 1 ] ) #NEWLINE# #UNINDENT# ret . sort ( key = compare_ordering_key ) #NEWLINE# return [ item [ 0 ] for item in ret ]