Add basic mobile support for executing batches
no progress, or options, yet..
This commit is contained in:
parent
6ca69802f5
commit
a8a4e362a0
|
@ -11,18 +11,26 @@ ${parent.body()}
|
||||||
${grid.render_complete()|n}
|
${grid.render_complete()|n}
|
||||||
% endif
|
% endif
|
||||||
|
|
||||||
% if not batch.executed and request.has_perm('{}.edit'.format(permission_prefix)):
|
% if not batch.executed:
|
||||||
|
% if request.has_perm('{}.edit'.format(permission_prefix)):
|
||||||
% if batch.complete:
|
% if batch.complete:
|
||||||
${h.form(request.route_url('mobile.{}.mark_pending'.format(route_prefix), uuid=batch.uuid))}
|
${h.form(url('mobile.{}.mark_pending'.format(route_prefix), uuid=batch.uuid))}
|
||||||
${h.csrf_token(request)}
|
${h.csrf_token(request)}
|
||||||
${h.hidden('mark-pending', value='true')}
|
${h.hidden('mark-pending', value='true')}
|
||||||
${h.submit('submit', "Mark Batch as Pending")}
|
${h.submit('submit', "Mark Batch as Pending")}
|
||||||
${h.end_form()}
|
${h.end_form()}
|
||||||
% else:
|
% else:
|
||||||
${h.form(request.route_url('mobile.{}.mark_complete'.format(route_prefix), uuid=batch.uuid))}
|
${h.form(url('mobile.{}.mark_complete'.format(route_prefix), uuid=batch.uuid))}
|
||||||
${h.csrf_token(request)}
|
${h.csrf_token(request)}
|
||||||
${h.hidden('mark-complete', value='true')}
|
${h.hidden('mark-complete', value='true')}
|
||||||
${h.submit('submit', "Mark Batch as Complete")}
|
${h.submit('submit', "Mark Batch as Complete")}
|
||||||
${h.end_form()}
|
${h.end_form()}
|
||||||
% endif
|
% endif
|
||||||
% 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()}
|
||||||
|
% endif
|
||||||
|
% endif
|
||||||
|
|
|
@ -892,6 +892,38 @@ class BatchMasterView(MasterView):
|
||||||
self.request.session.flash("Invalid request: {}".format(form.make_deform_form().error), 'error')
|
self.request.session.flash("Invalid request: {}".format(form.make_deform_form().error), 'error')
|
||||||
return self.redirect(self.get_action_url('view', batch))
|
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):
|
def execute_error_message(self, error):
|
||||||
return "Batch execution failed: {}: {}".format(type(error).__name__, error)
|
return "Batch execution failed: {}: {}".format(type(error).__name__, error)
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,7 @@ class MasterView(View):
|
||||||
mobile_creatable = False
|
mobile_creatable = False
|
||||||
mobile_pageable = True
|
mobile_pageable = True
|
||||||
mobile_filterable = False
|
mobile_filterable = False
|
||||||
|
mobile_executable = False
|
||||||
|
|
||||||
listing = False
|
listing = False
|
||||||
creating = False
|
creating = False
|
||||||
|
@ -2746,12 +2747,17 @@ class MasterView(View):
|
||||||
"Edit {0}".format(model_title))
|
"Edit {0}".format(model_title))
|
||||||
|
|
||||||
# execute
|
# execute
|
||||||
if cls.executable:
|
if cls.executable or cls.mobile_executable:
|
||||||
config.add_tailbone_permission(permission_prefix, '{}.execute'.format(permission_prefix),
|
config.add_tailbone_permission(permission_prefix, '{}.execute'.format(permission_prefix),
|
||||||
"Execute {}".format(model_title))
|
"Execute {}".format(model_title))
|
||||||
|
if cls.executable:
|
||||||
config.add_route('{}.execute'.format(route_prefix), '{}/{{{}}}/execute'.format(url_prefix, model_key))
|
config.add_route('{}.execute'.format(route_prefix), '{}/{{{}}}/execute'.format(url_prefix, model_key))
|
||||||
config.add_view(cls, attr='execute', route_name='{}.execute'.format(route_prefix),
|
config.add_view(cls, attr='execute', route_name='{}.execute'.format(route_prefix),
|
||||||
permission='{}.execute'.format(permission_prefix))
|
permission='{}.execute'.format(permission_prefix))
|
||||||
|
if cls.mobile_executable:
|
||||||
|
config.add_route('mobile.{}.execute'.format(route_prefix), '/mobile{}/{{{}}}/execute'.format(url_prefix, model_key))
|
||||||
|
config.add_view(cls, attr='mobile_execute', route_name='mobile.{}.execute'.format(route_prefix),
|
||||||
|
permission='{}.execute'.format(permission_prefix))
|
||||||
|
|
||||||
# delete
|
# delete
|
||||||
if cls.deletable:
|
if cls.deletable:
|
||||||
|
|
Loading…
Reference in a new issue