From 3d79f9fd7d605f65deb4b0ff64d2250d5cc266d2 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 22 Feb 2018 11:20:12 -0600 Subject: [PATCH] Add support for executing batch with options, via mobile --- tailbone/templates/mobile/batch/execute.mako | 10 +++++++ tailbone/templates/mobile/batch/view.mako | 12 +++++--- tailbone/views/batch/core.py | 29 ++++++++++++++------ 3 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 tailbone/templates/mobile/batch/execute.mako diff --git a/tailbone/templates/mobile/batch/execute.mako b/tailbone/templates/mobile/batch/execute.mako new file mode 100644 index 00000000..a6c7c6ef --- /dev/null +++ b/tailbone/templates/mobile/batch/execute.mako @@ -0,0 +1,10 @@ +## -*- coding: utf-8; -*- +<%inherit file="/mobile/base.mako" /> + +<%def name="title()">${index_title} » ${instance_title} » Execute + +<%def name="page_title()">${h.link_to(index_title, index_url)} » ${h.link_to(instance_title, instance_url)} » Execute + +
+ ${form.render()|n} +
diff --git a/tailbone/templates/mobile/batch/view.mako b/tailbone/templates/mobile/batch/view.mako index 9a24b21e..9e64c4bf 100644 --- a/tailbone/templates/mobile/batch/view.mako +++ b/tailbone/templates/mobile/batch/view.mako @@ -28,9 +28,13 @@ ${parent.body()} % endif % endif % if batch.complete and master.mobile_executable and request.has_perm('{}.execute'.format(permission_prefix)): - ${h.form(url('mobile.{}.execute'.format(route_prefix), uuid=batch.uuid))} - ${h.csrf_token(request)} - ${h.submit('submit', "Execute Batch")} - ${h.end_form()} + % if master.has_execution_options(batch): + ${h.link_to("Execute Batch", url('mobile.{}.execute'.format(route_prefix), uuid=batch.uuid), class_='ui-btn ui-corner-all')} + % else: + ${h.form(url('mobile.{}.execute'.format(route_prefix), uuid=batch.uuid))} + ${h.csrf_token(request)} + ${h.submit('submit', "Execute Batch")} + ${h.end_form()} + % endif % endif % endif diff --git a/tailbone/views/batch/core.py b/tailbone/views/batch/core.py index b872e736..4bac53e4 100644 --- a/tailbone/views/batch/core.py +++ b/tailbone/views/batch/core.py @@ -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)