fix: do not auto-create grid filters for uuid columns
This commit is contained in:
		
							parent
							
								
									d0e5ad9053
								
							
						
					
					
						commit
						70ed2dc78c
					
				
					 2 changed files with 21 additions and 7 deletions
				
			
		|  | @ -41,6 +41,7 @@ from webhelpers2.html import HTML | |||
| from wuttaweb.db import Session | ||||
| from wuttaweb.util import FieldList, get_model_fields, make_json_safe | ||||
| from wuttjamaican.util import UNSPECIFIED | ||||
| from wuttjamaican.db.util import UUID | ||||
| from wuttaweb.grids.filters import default_sqlalchemy_filters, VerbNotSupported | ||||
| 
 | ||||
| 
 | ||||
|  | @ -1136,14 +1137,15 @@ class Grid: | |||
| 
 | ||||
|     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 | ||||
|         true. | ||||
| 
 | ||||
|         For each column in the grid, this checks the provided | ||||
|         ``filters`` and if the column is not yet in there, will call | ||||
|         :meth:`make_filter()` to add it. | ||||
|         For each "column" in the model class, this will call | ||||
|         :meth:`make_filter()` to add an automatic filter.  However it | ||||
|         first checks the provided ``filters`` and will not override | ||||
|         any of those. | ||||
| 
 | ||||
|         .. note:: | ||||
| 
 | ||||
|  | @ -1181,9 +1183,18 @@ class Grid: | |||
| 
 | ||||
|             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) | ||||
| 
 | ||||
|                 # do not overwrite existing filters | ||||
|                 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 | ||||
| 
 | ||||
|  |  | |||
|  | @ -1021,6 +1021,9 @@ class TestGrid(WebTestCase): | |||
|             self.assertIn('active', filters) | ||||
|             # nb. relationship not included by default | ||||
|             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): | ||||
|         model = self.app.model | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue