Add support for executing batch with options, via mobile
This commit is contained in:
parent
0a165c5b93
commit
3d79f9fd7d
3 changed files with 38 additions and 13 deletions
|
@ -898,9 +898,14 @@ class BatchMasterView(MasterView):
|
|||
|
||||
def mobile_execute(self):
|
||||
"""
|
||||
Execute a batch via mobile, i.e. (for now) blocking with no progress bar.
|
||||
Mobile view which can prompt user for execution options if applicable,
|
||||
and/or execute a batch. For now this is done in a "blocking" fashion,
|
||||
i.e. no progress bar.
|
||||
"""
|
||||
batch = self.get_instance()
|
||||
model_title = self.get_model_title()
|
||||
instance_title = self.get_instance_title(batch)
|
||||
view_url = self.get_action_url('view', batch, mobile=True)
|
||||
self.executing = True
|
||||
form = self.make_execute_form(batch)
|
||||
if form.validate(newstyle=True):
|
||||
|
@ -913,20 +918,26 @@ class BatchMasterView(MasterView):
|
|||
try:
|
||||
result = self.handler.execute(batch, user=self.request.user, **kwargs)
|
||||
except Exception as err:
|
||||
log.exception("failed to execute batch %s: %s", batch.id_str, batch)
|
||||
self.request.session.flash("Failed to execute batch: {}".format(err), 'error')
|
||||
log.exception("failed to execute %s %s", model_title, batch.id_str)
|
||||
self.request.session.flash(self.execute_error_message(err), 'error')
|
||||
else:
|
||||
if result:
|
||||
batch.executed = datetime.datetime.utcnow()
|
||||
batch.executed_by = self.request.user
|
||||
self.request.session.flash("Batch was executed: {}".format(batch))
|
||||
self.request.session.flash("{} was executed: {}".format(model_title, instance_title))
|
||||
else:
|
||||
log.error("not sure why, but failed to execute batch %s: %s", batch.id_str, batch)
|
||||
self.request.session.flash("Failed to execute batch: {}".format(err), 'error')
|
||||
return self.redirect(self.get_action_url('view', batch, mobile=True))
|
||||
log.error("not sure why, but failed to execute %s %s: %s", model_title, batch.id_str, batch)
|
||||
self.request.session.flash("Failed to execute {}: {}".format(model_title, err), 'error')
|
||||
return self.redirect(view_url)
|
||||
|
||||
self.request.session.flash("Invalid request: {}".format(form.make_deform_form().error), 'error')
|
||||
return self.redirect(self.get_action_url('view', batch, mobile=True))
|
||||
form.mobile = True
|
||||
form.submit_label = "Execute"
|
||||
form.cancel_url = view_url
|
||||
return self.render_to_response('execute', {
|
||||
'form': form,
|
||||
'instance_title': instance_title,
|
||||
'instance_url': view_url,
|
||||
}, mobile=True)
|
||||
|
||||
def execute_error_message(self, error):
|
||||
return "Batch execution failed: {}: {}".format(type(error).__name__, error)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue