#NEWLINE# def validate( self , attrs ) : #NEWLINE# #INDENT# formula = attrs . get ( 'formula' , None ) #NEWLINE# sls_path = attrs [ 'sls_path' ] #NEWLINE# attrs [ 'validated' ] = False #NEWLINE# content_object = self . context . get ( 'content_object' ) #NEWLINE# formula_versions = ( content_object . formula_versions . all ( ) if content_object else ( ) ) #NEWLINE# if ( formula is None ) : #NEWLINE# #INDENT# all_components = models . Formula . all_components ( formula_versions ) #NEWLINE# if ( sls_path not in all_components ) : #NEWLINE# #INDENT# raise serializers . ValidationError ( { #NEWLINE# #INDENT# 'sls_path' : [ 'sls_path `{0}` does not exist.' . format ( sls_path ) ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# sls_formulas = all_components [ sls_path ] #NEWLINE# if ( len ( sls_formulas ) > 1 ) : #NEWLINE# #INDENT# err_msg = 'sls_path `{0}` is contained in multiple formulas.  Please specify one.' #NEWLINE# raise serializers . ValidationError ( { #NEWLINE# #INDENT# 'sls_path' : [ err_msg . format ( sls_path ) ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# attrs [ 'formula' ] = sls_formulas [ 0 ] #NEWLINE# attrs [ 'validated' ] = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# validators . validate_formula_component ( attrs , formula_versions ) #NEWLINE# attrs [ 'validated' ] = True #NEWLINE# #UNINDENT# return attrs