Add simple row status breakdown when viewing batch

This commit is contained in:
Lance Edgar 2018-09-20 15:58:45 -05:00
parent 3b0292029d
commit 0b9fe2dfe7
2 changed files with 55 additions and 0 deletions

View file

@ -40,6 +40,18 @@
display: inline;
}
.batch-helper {
border: 1px solid black;
float: right;
margin-top: 1em;
padding: 1em;
width: 20em;
}
.batch-helper-content {
margin-top: 1em;
}
</style>
</%def>
@ -79,6 +91,28 @@
${self.context_menu_items()}
</ul>
% if status_breakdown is not Undefined:
<div class="batch-helper">
<h3>Row Status Breakdown</h3>
<div class="batch-helper-content">
% if status_breakdown:
<div class="grid full">
<table>
% for i, (status, count) in enumerate(status_breakdown):
<tr class="${'even' if i % 2 == 0 else 'odd'}">
<td>${status}</td>
<td>${count}</td>
</tr>
% endfor
</table>
</div>
% else:
<p>Nothing to report yet.</p>
% endif
</div>
</div>
% endif
<div class="form-wrapper">
${form.render(form_id='batch-form', buttons=capture(buttons))|n}
</div><!-- form-wrapper -->

View file

@ -159,8 +159,29 @@ class BatchMasterView(MasterView):
kwargs['execute_form'] = self.make_execute_form(batch, action_url=url)
else:
kwargs['why_not_execute'] = self.handler.why_not_execute(batch)
kwargs['status_breakdown'] = self.make_status_breakdown(batch)
return kwargs
def make_status_breakdown(self, batch):
"""
Returns a simple list of 2-tuples, each of which has the status display
title as first member, and number of rows with that status as second
member.
"""
breakdown = {}
for row in batch.active_rows():
if row.status_code not in breakdown:
breakdown[row.status_code] = {
'code': row.status_code,
'title': row.STATUS[row.status_code],
'count': 0,
}
breakdown[row.status_code]['count'] += 1
breakdown = [
(status['title'], status['count'])
for code, status in six.iteritems(breakdown)]
return breakdown
def allow_worksheet(self, batch):
return not batch.executed and not batch.complete