Add basic mobile support for executing batches

no progress, or options, yet..
This commit is contained in:
Lance Edgar 2018-02-21 18:55:16 -06:00
parent 6ca69802f5
commit a8a4e362a0
3 changed files with 58 additions and 12 deletions

View file

@ -892,6 +892,38 @@ class BatchMasterView(MasterView):
self.request.session.flash("Invalid request: {}".format(form.make_deform_form().error), 'error')
return self.redirect(self.get_action_url('view', batch))
def mobile_execute(self):
"""
Execute a batch via mobile, i.e. (for now) blocking with no progress bar.
"""
batch = self.get_instance()
self.executing = True
form = self.make_execute_form(batch)
if form.validate(newstyle=True):
kwargs = dict(form.validated)
# cache options to use as defaults next time
for key, value in form.validated.items():
self.request.session['batch.{}.execute_option.{}'.format(batch.batch_key, key)] = value
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')
else:
if result:
batch.executed = datetime.datetime.utcnow()
batch.executed_by = self.request.user
self.request.session.flash("Batch was executed: {}".format(batch))
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))
self.request.session.flash("Invalid request: {}".format(form.make_deform_form().error), 'error')
return self.redirect(self.get_action_url('view', batch, mobile=True))
def execute_error_message(self, error):
return "Batch execution failed: {}: {}".format(type(error).__name__, error)