diff --git a/pyproject.toml b/pyproject.toml index f1bb921..d785419 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,6 @@ dependencies = [ "pyramid_fanstatic", "pyramid_mako", "pyramid_tm", - "SQLAlchemy-Utils", "waitress", "WebHelpers2", "WuttJamaican[db]>=0.19.2", diff --git a/src/wuttaweb/grids/base.py b/src/wuttaweb/grids/base.py index 3a3d4f5..c2f3156 100644 --- a/src/wuttaweb/grids/base.py +++ b/src/wuttaweb/grids/base.py @@ -32,7 +32,6 @@ from collections import namedtuple, OrderedDict import sqlalchemy as sa from sqlalchemy import orm -from sqlalchemy_utils import get_columns import paginate from paginate_sqlalchemy import SqlalchemyOrmPage @@ -1147,16 +1146,29 @@ class Grid: filters = filters or {} if self.model_class: - # nb. i first tried self.get_model_columns() but my notes - # say that was too aggressive in many cases. then i tried - # using the *subset* of self.columns, just the ones which - # corresponded to a property on the model class. and now - # i am using sa-utils to give the "true" column list.. - for col in get_columns(self.model_class): - if col.key in filters: - continue - prop = getattr(self.model_class, col.key) - filters[prop.key] = self.make_filter(prop) + + # nb. i have found this confusing for some reason. some + # things i've tried so far include: + # + # i first tried self.get_model_columns() but my notes say + # that was too aggressive in many cases. + # + # then i tried using the *subset* of self.columns, just + # the ones which correspond to a property on the model + # class. but sometimes that skips filters we need. + # + # then i tried get_columns() from sa-utils to give the + # "true" column list, but that fails when the underlying + # column has different name than the prop/attr key. + # + # so now, we are looking directly at the sa mapper, for + # all column attrs and then using the prop key. + + inspector = sa.inspect(self.model_class) + for prop in inspector.column_attrs: + if prop.key not in filters: + attr = getattr(self.model_class, prop.key) + filters[prop.key] = self.make_filter(attr) return filters