def filter_name(query, table, name, language, name_attribute='name'):
 if (language is None):
  query = query.filter((getattr(table, name_attribute) == name))
 else:
  names_table = table.names_table
  name_column = getattr(names_table, name_attribute)
  query = query.join(names_table)
  query = query.filter((names_table.foreign_id == table.id))
  query = query.filter((names_table.local_language_id == language.id))
  if isinstance(name, tuple):
   query = query.filter((name_column in name))
  else:
   query = query.filter((name_column == name))
 return query

def filter_name ( query , table , name , language , name_attribute = 'name' ) : if ( language is None ) : query = query . filter ( ( getattr ( table , name_attribute ) == name ) ) else : names_table = table . names_table name_column = getattr ( names_table , name_attribute ) query = query . join ( names_table ) query = query . filter ( ( names_table . foreign_id == table . id ) ) query = query . filter ( ( names_table . local_language_id == language . id ) ) if isinstance ( name , tuple ) : query = query . filter ( ( name_column in name ) ) else : query = query . filter ( ( name_column == name ) ) return query
filter a query by name .