#NEWLINE# def clean( self , value ) : #NEWLINE# #INDENT# super ( TRIdentificationNumberField , self ) . clean ( value ) #NEWLINE# if ( value in EMPTY_VALUES ) : #NEWLINE# #INDENT# return '' #NEWLINE# #UNINDENT# if ( len ( value ) != 11 ) : #NEWLINE# #INDENT# raise ValidationError ( self . error_messages [ 'not_11' ] ) #NEWLINE# #UNINDENT# if ( not re . match ( '^\\d{11}$' , chksum ) ) : #NEWLINE# #INDENT# raise ValidationError ( self . error_messages [ 'invalid' ] ) #NEWLINE# #UNINDENT# if ( int ( value [ 0 ] ) == 0 ) : #NEWLINE# #INDENT# raise ValidationError ( self . error_messages [ 'invalid' ] ) #NEWLINE# #UNINDENT# chksum = ( ( ( sum ( [ int ( value [ i ] ) for i in range ( 0 , 9 , 2 ) ] ) * 7 ) - sum ( [ int ( value [ i ] ) for i in range ( 1 , 9 , 2 ) ] ) ) % 10 ) #NEWLINE# if ( ( chksum != int ( value [ 9 ] ) ) or ( ( sum ( [ int ( value [ i ] ) for i in range ( 10 ) ] ) % 10 ) != int ( value [ 10 ] ) ) ) : #NEWLINE# #INDENT# raise ValidationError ( self . error_messages [ 'invalid' ] ) #NEWLINE# #UNINDENT# return value