Improve merge support for records with no uuid
for now we "pretend" they have a uuid still, custom view is responsible for determining the value for each row if needed
This commit is contained in:
parent
58354e7adf
commit
214f3d9b1e
4 changed files with 74 additions and 18 deletions
tailbone/grids
|
@ -170,6 +170,21 @@ class Grid(object):
|
|||
'myfield': myrender,
|
||||
},
|
||||
)
|
||||
|
||||
.. attribute row_uuid_getter::
|
||||
|
||||
Optional callable to obtain the "UUID" (sic) value for each
|
||||
data row. The default assumption as that each row object has a
|
||||
``uuid`` attribute, but when that isn't the case, *and* the
|
||||
grid needs to support checkboxes, we must "pretend" by
|
||||
injecting some custom value to the ``uuid`` of the row data.
|
||||
|
||||
If necssary, set this to a callable like so::
|
||||
|
||||
def fake_uuid(row):
|
||||
return row.some_custom_key
|
||||
|
||||
grid.row_uuid_getter = fake_uuid
|
||||
"""
|
||||
|
||||
def __init__(self, key, data, columns=None, width='auto', request=None,
|
||||
|
@ -182,7 +197,7 @@ class Grid(object):
|
|||
sortable=False, sorters={}, default_sortkey=None, default_sortdir='asc',
|
||||
pageable=False, default_pagesize=None, default_page=1,
|
||||
checkboxes=False, checked=None, check_handler=None, check_all_handler=None,
|
||||
checkable=None,
|
||||
checkable=None, row_uuid_getter=None,
|
||||
clicking_row_checks_box=False, click_handlers=None,
|
||||
main_actions=[], more_actions=[], delete_speedbump=False,
|
||||
ajax_data_url=None, component='tailbone-grid',
|
||||
|
@ -243,6 +258,7 @@ class Grid(object):
|
|||
self.check_handler = check_handler
|
||||
self.check_all_handler = check_all_handler
|
||||
self.checkable = checkable
|
||||
self.row_uuid_getter = row_uuid_getter
|
||||
self.clicking_row_checks_box = clicking_row_checks_box
|
||||
|
||||
self.click_handlers = click_handlers or {}
|
||||
|
@ -1425,6 +1441,16 @@ class Grid(object):
|
|||
})
|
||||
return columns
|
||||
|
||||
def get_uuid_for_row(self, rowobj):
|
||||
|
||||
# use custom getter if set
|
||||
if self.row_uuid_getter:
|
||||
return self.row_uuid_getter(rowobj)
|
||||
|
||||
# otherwise fallback to normal uuid, if present
|
||||
if hasattr(rowobj, 'uuid'):
|
||||
return rowobj.uuid
|
||||
|
||||
def get_buefy_data(self):
|
||||
"""
|
||||
Returns a list of data rows for the grid, for use with Buefy table.
|
||||
|
@ -1481,8 +1507,9 @@ class Grid(object):
|
|||
|
||||
# maybe add UUID for convenience
|
||||
if 'uuid' not in self.columns:
|
||||
if hasattr(rowobj, 'uuid'):
|
||||
row['uuid'] = rowobj.uuid
|
||||
uuid = self.get_uuid_for_row(rowobj)
|
||||
if uuid:
|
||||
row['uuid'] = uuid
|
||||
|
||||
# set action URL(s) for row, as needed
|
||||
self.set_action_urls(row, rowobj, i)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue