#NEWLINE# def validate( self , attrs ) : #NEWLINE# #INDENT# '\n        1. Disallow multiple conditions with the same element name\n        2. Use introspection to validate individual conditions which are present.\n        ' #NEWLINE# from . util import duplicates_in #NEWLINE# conditions = attrs . get ( 'conditions' , [ ] ) #NEWLINE# errors = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# all_names = [ item . element_name for item in conditions ] #NEWLINE# for name in duplicates_in ( all_names ) : #NEWLINE# #INDENT# message = _ ( 'Duplicate element name' ) #NEWLINE# errors [ ( 'conditions.' + name ) ] = [ message ] #NEWLINE# #UNINDENT# for item in conditions : #NEWLINE# #INDENT# sanitized_element_name = item . element_name . replace ( '-' , '_' ) #NEWLINE# condition_validate = getattr ( self , ( 'validate_condition_%s' % sanitized_element_name ) , None ) #NEWLINE# if condition_validate : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# condition_validate ( item ) #NEWLINE# #UNINDENT# except ValidationError as err : #NEWLINE# #INDENT# field_name = ( 'conditions.' + item . element_name ) #NEWLINE# errors [ field_name ] = ( errors . get ( field_name , [ ] ) + list ( err . messages ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if len ( errors ) : #NEWLINE# #INDENT# raise ValidationError ( errors ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return attrs