Add the Grid.remove() method, deprecate hide_column() etc.

this is more clear, and aligns with how Form works
This commit is contained in:
Lance Edgar 2021-09-08 14:33:40 -05:00
parent 4474f30718
commit 82e730c18e

View file

@ -27,9 +27,10 @@ Core Grid Classes
from __future__ import unicode_literals, absolute_import
import datetime
from six.moves import urllib
import warnings
import six
from six.moves import urllib
import sqlalchemy as sa
from sqlalchemy import orm
@ -161,25 +162,32 @@ class Grid(object):
mapper = orm.class_mapper(self.model_class)
return [prop.key for prop in mapper.iterate_properties]
def remove(self, *keys):
"""
This *removes* some column(s) from the grid, altogether.
"""
for key in keys:
if key in self.columns:
self.columns.remove(key)
def hide_column(self, key):
"""
This *removes* a column from the grid, altogether.
This method should really be renamed to ``remove_column()``
instead.
This method is deprecated; use :meth:`remove()` instead.
"""
if key in self.columns:
self.columns.remove(key)
warnings.warn("Grid.hide_column() is deprecated; please use "
"Grid.remove() instead.",
DeprecationWarning)
self.remove(key)
def hide_columns(self, *keys):
"""
This *removes* columns from the grid, altogether.
This method should really be renamed to ``remove_columns()``
instead.
This method is deprecated; use :meth:`remove()` instead.
"""
for key in keys:
self.hide_column(key)
self.remove(*keys)
def set_invisible(self, key, invisible=True):
"""