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