Move logic for "bulk-delete row objects" into MasterView
i guess so far it has only been needed for batch, but some day surely it will be needed for something else..? some of the template logic is still batch only i think..
This commit is contained in:
parent
b5a519d132
commit
c43a4edec7
|
@ -1264,22 +1264,19 @@ class BatchMasterView(MasterView):
|
|||
"""
|
||||
self.handler.do_remove_row(row)
|
||||
|
||||
def bulk_delete_rows(self):
|
||||
"""
|
||||
"Delete" all rows matching the current row grid view query. This sets
|
||||
the ``removed`` flag on the rows but does not truly delete them.
|
||||
"""
|
||||
def delete_row_objects(self, rows):
|
||||
deleted = super(BatchMasterView, self).delete_row_objects(rows)
|
||||
batch = self.get_instance()
|
||||
query = self.get_effective_row_data(sort=False)
|
||||
|
||||
# TODO: this should surely be handled by the handler...
|
||||
# decrement rowcount for batch
|
||||
if batch.rowcount is not None:
|
||||
batch.rowcount -= query.count()
|
||||
query.update({'removed': True}, synchronize_session=False)
|
||||
batch.rowcount -= deleted
|
||||
|
||||
# refresh batch status
|
||||
self.Session.refresh(batch)
|
||||
self.handler.refresh_batch_status(batch)
|
||||
|
||||
return self.redirect(self.get_action_url('view', batch))
|
||||
return deleted
|
||||
|
||||
def execute(self):
|
||||
"""
|
||||
|
@ -1505,14 +1502,6 @@ class BatchMasterView(MasterView):
|
|||
config.add_tailbone_permission(permission_prefix, '{}.refresh'.format(permission_prefix),
|
||||
"Refresh data for {}".format(model_title))
|
||||
|
||||
# bulk delete rows
|
||||
if cls.rows_bulk_deletable:
|
||||
config.add_route('{}.delete_rows'.format(route_prefix), '{}/{{uuid}}/rows/delete'.format(url_prefix))
|
||||
config.add_view(cls, attr='bulk_delete_rows', route_name='{}.delete_rows'.format(route_prefix),
|
||||
permission='{}.delete_rows'.format(permission_prefix))
|
||||
config.add_tailbone_permission(permission_prefix, '{}.delete_rows'.format(permission_prefix),
|
||||
"Bulk-delete data rows from {}".format(model_title))
|
||||
|
||||
# toggle complete
|
||||
config.add_route('{}.toggle_complete'.format(route_prefix), '{}/{{{}}}/toggle-complete'.format(url_prefix, model_key))
|
||||
config.add_view(cls, attr='toggle_complete', route_name='{}.toggle_complete'.format(route_prefix),
|
||||
|
|
|
@ -4182,6 +4182,30 @@ class MasterView(View):
|
|||
self.delete_row_object(row)
|
||||
return self.redirect(self.get_action_url('view', self.get_parent(row)))
|
||||
|
||||
def bulk_delete_rows(self):
|
||||
"""
|
||||
Delete all row objects matching the current row grid query.
|
||||
"""
|
||||
obj = self.get_instance()
|
||||
rows = self.get_effective_row_data(sort=False).all()
|
||||
|
||||
# TODO: this should use a separate thread with progress
|
||||
self.delete_row_objects(rows)
|
||||
self.Session.refresh(obj)
|
||||
|
||||
return self.redirect(self.get_action_url('view', obj))
|
||||
|
||||
def delete_row_objects(self, rows):
|
||||
"""
|
||||
Perform the actual deletion of given row objects.
|
||||
"""
|
||||
deleted = 0
|
||||
for row in rows:
|
||||
if self.row_deletable(row):
|
||||
self.delete_row_object(row)
|
||||
deleted += 1
|
||||
return deleted
|
||||
|
||||
def get_parent(self, row):
|
||||
raise NotImplementedError
|
||||
|
||||
|
@ -4940,6 +4964,22 @@ class MasterView(View):
|
|||
config.add_view(cls, attr='create_row', route_name='{}.create_row'.format(route_prefix),
|
||||
permission='{}.create_row'.format(permission_prefix))
|
||||
|
||||
# bulk-delete rows
|
||||
# nb. must be defined before view_row b/c of url similarity
|
||||
if cls.rows_bulk_deletable:
|
||||
config.add_tailbone_permission(permission_prefix,
|
||||
'{}.delete_rows'.format(permission_prefix),
|
||||
"Bulk-delete {} from {}".format(
|
||||
row_model_title_plural, model_title))
|
||||
config.add_route('{}.delete_rows'.format(route_prefix),
|
||||
'{}/rows/delete'.format(instance_url_prefix),
|
||||
# TODO: should enforce this
|
||||
# request_method='POST'
|
||||
)
|
||||
config.add_view(cls, attr='bulk_delete_rows',
|
||||
route_name='{}.delete_rows'.format(route_prefix),
|
||||
permission='{}.delete_rows'.format(permission_prefix))
|
||||
|
||||
# view row
|
||||
if cls.has_rows:
|
||||
if cls.rows_viewable:
|
||||
|
|
Loading…
Reference in a new issue