def scaffold_filters(self, name): """ Return list of enabled filters """ join_tables = [] if isinstance(name, string_types): model = self.model for attribute in name.split('.'): value = getattr(model, attribute) if (hasattr(value, 'property') and hasattr(value.property, 'direction')): model = value.property.mapper.class_ table = model.__table__ if self._need_join(table): join_tables.append(table) attr = value else: attr = name if attr is None: raise Exception('Failed to find field for filter: %s' % name) # Figure out filters for related column if hasattr(attr, 'property') and hasattr(attr.property, 'direction'): filters = [] for p in self._get_model_iterator(attr.property.mapper.class_): if hasattr(p, 'columns'): # TODO: Check for multiple columns column = p.columns[0] if column.foreign_keys or column.primary_key: continue visible_name = '%s / %s' % (self.get_column_name(attr.prop.table.name), self.get_column_name(p.key)) type_name = type(column.type).__name__ flt = self.filter_converter.convert(type_name, column, visible_name) if flt: table = column.table if join_tables: self._filter_joins[table.name] = join_tables elif self._need_join(table.name): self._filter_joins[table.name] = [table.name] filters.extend(flt) return filters else: columns = self._get_columns_for_field(attr) if len(columns) > 1: raise Exception('Can not filter more than on one column for %s' % name) column = columns[0] if self._need_join(column.table) and name not in self.column_labels: visible_name = '%s / %s' % ( self.get_column_name(column.table.name), self.get_column_name(column.name) ) else: if not isinstance(name, string_types): visible_name = self.get_column_name(name.property.key) else: visible_name = self.get_column_name(name) type_name = type(column.type).__name__ if join_tables: self._filter_joins[column.table.name] = join_tables flt = self.filter_converter.convert( type_name, column, visible_name, options=self.column_choices.get(name), ) if flt and not join_tables and self._need_join(column.table): self._filter_joins[column.table.name] = [column.table] return flt
def scaffold_filters(self, name): """ Return list of enabled filters """ join_tables, attr = self._get_field_with_path(name) if attr is None: raise Exception("Failed to find field for filter: %s" % name) # Figure out filters for related column if hasattr(attr, "property") and hasattr(attr.property, "direction"): filters = [] for p in self._get_model_iterator(attr.property.mapper.class_): if hasattr(p, "columns"): # TODO: Check for multiple columns column = p.columns[0] if column.foreign_keys or column.primary_key: continue visible_name = "%s / %s" % (self.get_column_name(attr.prop.table.name), self.get_column_name(p.key)) type_name = type(column.type).__name__ flt = self.filter_converter.convert(type_name, column, visible_name) if flt: table = column.table if join_tables: self._filter_joins[table.name] = join_tables elif self._need_join(table): self._filter_joins[table.name] = [table] filters.extend(flt) return filters else: columns = self._get_columns_for_field(attr) if len(columns) > 1: raise Exception("Can not filter more than on one column for %s" % name) column = columns[0] if self._need_join(column.table) and name not in self.column_labels: visible_name = "%s / %s" % (self.get_column_name(column.table.name), self.get_column_name(column.name)) else: if not isinstance(name, string_types): visible_name = self.get_column_name(name.property.key) else: visible_name = self.get_column_name(name) type_name = type(column.type).__name__ if join_tables: self._filter_joins[column.table.name] = join_tables flt = self.filter_converter.convert(type_name, column, visible_name, options=self.column_choices.get(name)) if flt and not join_tables and self._need_join(column.table): self._filter_joins[column.table.name] = [column.table] return flt