Add buttons to toggle batch 'complete' flag when viewing batch
This commit is contained in:
parent
a4095b30f7
commit
218ac221e5
|
@ -36,6 +36,10 @@
|
|||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.complete form {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
</style>
|
||||
</%def>
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ from tailbone import forms, grids
|
|||
from tailbone.db import Session
|
||||
from tailbone.views import MasterView
|
||||
from tailbone.progress import SessionProgress
|
||||
from tailbone.util import csrf_token
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -240,6 +241,9 @@ class BatchMasterView(MasterView):
|
|||
f.set_renderer('status_code', self.make_status_renderer(self.model_class.STATUS))
|
||||
f.set_label('status_code', "Status")
|
||||
|
||||
# complete
|
||||
f.set_renderer('complete', self.render_complete)
|
||||
|
||||
# executed
|
||||
f.set_readonly('executed')
|
||||
f.set_readonly('executed_by')
|
||||
|
@ -281,6 +285,30 @@ class BatchMasterView(MasterView):
|
|||
return status_code_text
|
||||
return render_status
|
||||
|
||||
def render_complete(self, batch, field):
|
||||
content = [HTML.literal("Yes" if batch.complete else "No")]
|
||||
|
||||
if not batch.executed:
|
||||
if self.request.has_perm('{}.edit'.format(self.get_permission_prefix())):
|
||||
|
||||
if batch.complete:
|
||||
label = "Mark as NOT Complete"
|
||||
value = 'false'
|
||||
else:
|
||||
label = "Mark as Complete"
|
||||
value = 'true'
|
||||
|
||||
content.extend([
|
||||
HTML.literal(' '),
|
||||
tags.form(self.get_action_url('toggle_complete', batch), class_='autodisable'),
|
||||
csrf_token(self.request),
|
||||
tags.hidden('complete', value=value),
|
||||
tags.submit('submit', label),
|
||||
tags.end_form(),
|
||||
])
|
||||
|
||||
return HTML.tag('div', c=content)
|
||||
|
||||
def render_user(self, batch, field):
|
||||
user = getattr(batch, field)
|
||||
if not user:
|
||||
|
@ -413,6 +441,14 @@ class BatchMasterView(MasterView):
|
|||
kwargs['batch'] = batch
|
||||
return kwargs
|
||||
|
||||
def toggle_complete(self):
|
||||
batch = self.get_instance()
|
||||
if not batch.executed:
|
||||
form = forms.Form(schema=ToggleComplete(), request=self.request)
|
||||
if form.validate(newstyle=True):
|
||||
batch.complete = form.validated['complete']
|
||||
return self.redirect(self.get_action_url('view', batch))
|
||||
|
||||
def mobile_mark_complete(self):
|
||||
batch = self.get_instance()
|
||||
batch.complete = True
|
||||
|
@ -1151,6 +1187,11 @@ class BatchMasterView(MasterView):
|
|||
config.add_tailbone_permission(permission_prefix, '{}.delete_rows'.format(permission_prefix),
|
||||
"Bulk-delete data rows from {}".format(model_title))
|
||||
|
||||
# toggle complete
|
||||
config.add_route('{}.toggle_complete'.format(route_prefix), '{}/{{{}}}/toggle-complete'.format(url_prefix, model_key))
|
||||
config.add_view(cls, attr='toggle_complete', route_name='{}.toggle_complete'.format(route_prefix),
|
||||
permission='{}.edit'.format(permission_prefix))
|
||||
|
||||
# mobile mark complete
|
||||
config.add_route('mobile.{}.mark_complete'.format(route_prefix), '/mobile{}/{{{}}}/mark-complete'.format(url_prefix, model_key))
|
||||
config.add_view(cls, attr='mobile_mark_complete', route_name='mobile.{}.mark_complete'.format(route_prefix),
|
||||
|
@ -1214,6 +1255,11 @@ class FileBatchMasterView(BatchMasterView):
|
|||
return self.render_file_field(path, url)
|
||||
|
||||
|
||||
class ToggleComplete(colander.MappingSchema):
|
||||
|
||||
complete = colander.SchemaNode(colander.Boolean())
|
||||
|
||||
|
||||
class MobileBatchStatusFilter(grids.filters.MobileFilter):
|
||||
|
||||
value_choices = ['pending', 'complete', 'executed', 'all']
|
||||
|
|
Loading…
Reference in a new issue