Add progress support when deleting a batch
b/c we must delete all rows individually, and some batches can be several thousand rows each
This commit is contained in:
parent
8579b89002
commit
cabe422508
|
@ -82,6 +82,7 @@ class BatchMasterView(MasterView):
|
||||||
results_executable = False
|
results_executable = False
|
||||||
has_worksheet = False
|
has_worksheet = False
|
||||||
has_worksheet_file = False
|
has_worksheet_file = False
|
||||||
|
delete_requires_progress = True
|
||||||
|
|
||||||
input_file_template_config_section = 'rattail.batch'
|
input_file_template_config_section = 'rattail.batch'
|
||||||
|
|
||||||
|
@ -742,8 +743,55 @@ class BatchMasterView(MasterView):
|
||||||
"""
|
"""
|
||||||
Delete all data (files etc.) for the batch.
|
Delete all data (files etc.) for the batch.
|
||||||
"""
|
"""
|
||||||
self.handler.do_delete(batch)
|
app = self.get_rattail_app()
|
||||||
super(BatchMasterView, self).delete_instance(batch)
|
session = app.get_session(batch)
|
||||||
|
self.batch_handler.do_delete(batch)
|
||||||
|
session.flush()
|
||||||
|
|
||||||
|
def delete_instance_with_progress(self, batch):
|
||||||
|
"""
|
||||||
|
Delete all data (files etc.) for the batch.
|
||||||
|
"""
|
||||||
|
return self.handler_action(batch, 'delete')
|
||||||
|
|
||||||
|
def delete_thread(self, key, user_uuid, progress, **kwargs):
|
||||||
|
"""
|
||||||
|
Thread target for deleting a batch with progress indicator.
|
||||||
|
"""
|
||||||
|
app = self.get_rattail_app()
|
||||||
|
model = self.model
|
||||||
|
# nb. must make new session, separate from main thread
|
||||||
|
session = app.make_session()
|
||||||
|
batch = self.get_instance_for_key(key, session)
|
||||||
|
batch_str = six.text_type(batch)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# try to delete batch
|
||||||
|
self.handler.do_delete(batch, progress=progress, **kwargs)
|
||||||
|
|
||||||
|
except Exception as error:
|
||||||
|
# error; log that and rollback
|
||||||
|
log.exception("delete failed for batch: %s", batch)
|
||||||
|
session.rollback()
|
||||||
|
session.close()
|
||||||
|
if progress:
|
||||||
|
progress.session.load()
|
||||||
|
progress.session['error'] = True
|
||||||
|
progress.session['error_msg'] = "Batch deletion failed: {}".format(
|
||||||
|
simple_error(error))
|
||||||
|
progress.session.save()
|
||||||
|
|
||||||
|
else:
|
||||||
|
# no error; finish up
|
||||||
|
session.commit()
|
||||||
|
session.close()
|
||||||
|
if progress:
|
||||||
|
progress.session.load()
|
||||||
|
progress.session['complete'] = True
|
||||||
|
progress.session['success_url'] = self.get_index_url()
|
||||||
|
progress.session['success_msg'] = "Batch has been deleted: {}".format(
|
||||||
|
batch_str)
|
||||||
|
progress.session.save()
|
||||||
|
|
||||||
def get_fallback_templates(self, template, **kwargs):
|
def get_fallback_templates(self, template, **kwargs):
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -100,6 +100,7 @@ class MasterView(View):
|
||||||
viewable = True
|
viewable = True
|
||||||
editable = True
|
editable = True
|
||||||
deletable = True
|
deletable = True
|
||||||
|
delete_requires_progress = False
|
||||||
delete_confirm = 'full'
|
delete_confirm = 'full'
|
||||||
bulk_deletable = False
|
bulk_deletable = False
|
||||||
set_deletable = False
|
set_deletable = False
|
||||||
|
@ -1590,6 +1591,9 @@ class MasterView(View):
|
||||||
if isinstance(result, httpexceptions.HTTPException):
|
if isinstance(result, httpexceptions.HTTPException):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
if self.delete_requires_progress:
|
||||||
|
return self.delete_instance_with_progress(instance)
|
||||||
|
else:
|
||||||
self.delete_instance(instance)
|
self.delete_instance(instance)
|
||||||
self.request.session.flash("{} has been deleted: {}".format(
|
self.request.session.flash("{} has been deleted: {}".format(
|
||||||
self.get_model_title(), instance_title))
|
self.get_model_title(), instance_title))
|
||||||
|
|
Loading…
Reference in a new issue