fix: do not auto-create grid filters for uuid columns
This commit is contained in:
parent
d0e5ad9053
commit
70ed2dc78c
|
@ -41,6 +41,7 @@ from webhelpers2.html import HTML
|
||||||
from wuttaweb.db import Session
|
from wuttaweb.db import Session
|
||||||
from wuttaweb.util import FieldList, get_model_fields, make_json_safe
|
from wuttaweb.util import FieldList, get_model_fields, make_json_safe
|
||||||
from wuttjamaican.util import UNSPECIFIED
|
from wuttjamaican.util import UNSPECIFIED
|
||||||
|
from wuttjamaican.db.util import UUID
|
||||||
from wuttaweb.grids.filters import default_sqlalchemy_filters, VerbNotSupported
|
from wuttaweb.grids.filters import default_sqlalchemy_filters, VerbNotSupported
|
||||||
|
|
||||||
|
|
||||||
|
@ -1136,14 +1137,15 @@ class Grid:
|
||||||
|
|
||||||
def make_backend_filters(self, filters=None):
|
def make_backend_filters(self, filters=None):
|
||||||
"""
|
"""
|
||||||
Make backend filters for all columns in the grid.
|
Make "automatic" backend filters for the grid.
|
||||||
|
|
||||||
This is called by the constructor, if :attr:`filterable` is
|
This is called by the constructor, if :attr:`filterable` is
|
||||||
true.
|
true.
|
||||||
|
|
||||||
For each column in the grid, this checks the provided
|
For each "column" in the model class, this will call
|
||||||
``filters`` and if the column is not yet in there, will call
|
:meth:`make_filter()` to add an automatic filter. However it
|
||||||
:meth:`make_filter()` to add it.
|
first checks the provided ``filters`` and will not override
|
||||||
|
any of those.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
|
@ -1181,9 +1183,18 @@ class Grid:
|
||||||
|
|
||||||
inspector = sa.inspect(self.model_class)
|
inspector = sa.inspect(self.model_class)
|
||||||
for prop in inspector.column_attrs:
|
for prop in inspector.column_attrs:
|
||||||
if prop.key not in filters:
|
|
||||||
attr = getattr(self.model_class, prop.key)
|
# do not overwrite existing filters
|
||||||
filters[prop.key] = self.make_filter(attr)
|
if prop.key in filters:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# do not create filter for UUID field
|
||||||
|
if (len(prop.columns) == 1
|
||||||
|
and isinstance(prop.columns[0].type, UUID)):
|
||||||
|
continue
|
||||||
|
|
||||||
|
attr = getattr(self.model_class, prop.key)
|
||||||
|
filters[prop.key] = self.make_filter(attr)
|
||||||
|
|
||||||
return filters
|
return filters
|
||||||
|
|
||||||
|
|
|
@ -1021,6 +1021,9 @@ class TestGrid(WebTestCase):
|
||||||
self.assertIn('active', filters)
|
self.assertIn('active', filters)
|
||||||
# nb. relationship not included by default
|
# nb. relationship not included by default
|
||||||
self.assertNotIn('person', filters)
|
self.assertNotIn('person', filters)
|
||||||
|
# nb. uuid fields not included by default
|
||||||
|
self.assertNotIn('uuid', filters)
|
||||||
|
self.assertNotIn('person_uuid', filters)
|
||||||
|
|
||||||
def test_make_filter(self):
|
def test_make_filter(self):
|
||||||
model = self.app.model
|
model = self.app.model
|
||||||
|
|
Loading…
Reference in a new issue