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

@ -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