Add basic checkbox support to new grids.
Also: * Add 'creatable', 'editable' etc. to master view class. * Add styles for warning/notice grid rows. * Misc. other tweaks.
This commit is contained in:
parent
e79531fda8
commit
d2b065a8fc
13 changed files with 229 additions and 71 deletions
|
@ -159,5 +159,10 @@ class AlchemyGrid(Grid):
|
|||
self._fa_grid._set_active(row, orm.object_session(row))
|
||||
yield row
|
||||
|
||||
def get_row_key(self, row):
|
||||
mapper = orm.object_mapper(row)
|
||||
assert len(mapper.primary_key) == 1
|
||||
return getattr(row, mapper.primary_key[0].key)
|
||||
|
||||
def render_cell(self, row, column):
|
||||
return column.field.render_readonly()
|
||||
|
|
|
@ -42,7 +42,8 @@ class Grid(object):
|
|||
joiners={}, filterable=False, filters={},
|
||||
sortable=False, sorters={}, default_sortkey=None, default_sortdir='asc',
|
||||
pageable=False, default_pagesize=20, default_page=1,
|
||||
width='auto', checkboxes=False, **kwargs):
|
||||
width='auto', checkboxes=False, row_attrs={}, cell_attrs={},
|
||||
**kwargs):
|
||||
self.key = key
|
||||
self.request = request
|
||||
self.columns = columns
|
||||
|
@ -73,6 +74,8 @@ class Grid(object):
|
|||
|
||||
self.width = width
|
||||
self.checkboxes = checkboxes
|
||||
self.row_attrs = row_attrs
|
||||
self.cell_attrs = cell_attrs
|
||||
|
||||
def get_default_filters(self):
|
||||
"""
|
||||
|
@ -473,6 +476,8 @@ class Grid(object):
|
|||
classes = ['newgrid']
|
||||
if self.width == 'full':
|
||||
classes.append('full')
|
||||
if self.checkboxes:
|
||||
classes.append('selectable')
|
||||
return {'class_': ' '.join(classes),
|
||||
'data-url': self.request.current_route_url(_query=None),
|
||||
'data-permalink': self.request.current_route_url()}
|
||||
|
@ -533,16 +538,14 @@ class Grid(object):
|
|||
|
||||
def get_row_attrs(self, row, i):
|
||||
"""
|
||||
Returns a properly-formatted set of attributes which will be applied to
|
||||
the ``<tr>`` element for the given row. Note that ``i`` will be a
|
||||
1-based index value for the row within its table. The meaning of
|
||||
``row`` is basically not defined; it depends on the type of data the
|
||||
grid deals with.
|
||||
Returns a dict of HTML attributes which is to be applied to the row's
|
||||
``<tr>`` element. Note that ``i`` will be a 1-based index value for
|
||||
the row within its table. The meaning of ``row`` is basically not
|
||||
defined; it depends on the type of data the grid deals with.
|
||||
"""
|
||||
# attrs = {'class_': self.get_row_class(row, i)}
|
||||
# attrs = {}
|
||||
# return format_attrs(**attrs)
|
||||
return {}
|
||||
if callable(self.row_attrs):
|
||||
return self.row_attrs(row, i)
|
||||
return self.row_attrs
|
||||
|
||||
# def get_row_class(self, row, i):
|
||||
# class_ = self.default_row_class(row, i)
|
||||
|
@ -552,18 +555,34 @@ class Grid(object):
|
|||
# class_ = '{0} {1}'.format(class_, extra)
|
||||
# return class_
|
||||
|
||||
# def checkbox(self, key):
|
||||
# """
|
||||
# Render a checkbox using the given key.
|
||||
# """
|
||||
# return tags.checkbox('checkbox-{0}-{1}'.format(self.key, key))
|
||||
def get_row_key(self, row):
|
||||
raise NotImplementedError
|
||||
|
||||
def checkbox(self, row):
|
||||
return True
|
||||
|
||||
def checked(self, row):
|
||||
return False
|
||||
|
||||
def render_checkbox(self, row):
|
||||
"""
|
||||
Returns a boolean indicating whether ot not a checkbox should be
|
||||
rendererd for the given row. Default implementation returns ``True``
|
||||
in all cases.
|
||||
"""
|
||||
if not self.checkbox(row):
|
||||
return ''
|
||||
return tags.checkbox('checkbox-{0}-{1}'.format(self.key, self.get_row_key(row)),
|
||||
checked=self.checked(row))
|
||||
|
||||
def get_cell_attrs(self, row, column):
|
||||
"""
|
||||
Returns a dictionary of HTML attributes which should be applied to the
|
||||
``<td>`` element in which the given row and column "intersect".
|
||||
"""
|
||||
return {}
|
||||
if callable(self.cell_attrs):
|
||||
return self.cell_attrs(row, column)
|
||||
return self.cell_attrs
|
||||
|
||||
def render_cell(self, row, column):
|
||||
return ''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue