def smart_fill(variable_name, db=PARAM_NAME_KNOWLEDGE, default='56'):
 variable_name = variable_name.lower()
 possible_results = []
 for (filled_value, variable_name_list) in db.items():
  for variable_name_db in variable_name_list:
   if (variable_name_db == variable_name):
    return filled_value
   if (variable_name in variable_name_db):
    match_rate = get_match_rate(variable_name, variable_name_db)
    possible_results.append((filled_value, match_rate))
   elif (variable_name_db in variable_name):
    match_rate = get_match_rate(variable_name, variable_name_db)
    possible_results.append((filled_value, match_rate))
 if possible_results:
  possible_results.sort(sortfunc)
  return possible_results[0][0]
 else:
  msg = '[smart_fill] Failed to find a value for parameter with name "%s"'
  om.out.debug((msg % variable_name))
  return default

def smart_fill ( variable_name , db = PARAM_NAME_KNOWLEDGE , default = '56' ) : variable_name = variable_name . lower ( ) possible_results = [ ] for ( filled_value , variable_name_list ) in db . items ( ) : for variable_name_db in variable_name_list : if ( variable_name_db == variable_name ) : return filled_value if ( variable_name in variable_name_db ) : match_rate = get_match_rate ( variable_name , variable_name_db ) possible_results . append ( ( filled_value , match_rate ) ) elif ( variable_name_db in variable_name ) : match_rate = get_match_rate ( variable_name , variable_name_db ) possible_results . append ( ( filled_value , match_rate ) ) if possible_results : possible_results . sort ( sortfunc ) return possible_results [ 0 ] [ 0 ] else : msg = '[smart_fill] Failed to find a value for parameter with name "%s"' om . out . debug ( ( msg % variable_name ) ) return default
this method returns a "smart" option for a variable name inside a form .