From 0b9fe2dfe720a053c29a93276208560d50e0bb6a Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 20 Sep 2018 15:58:45 -0500 Subject: [PATCH] Add simple row status breakdown when viewing batch --- tailbone/templates/batch/view.mako | 34 ++++++++++++++++++++++++++++++ tailbone/views/batch/core.py | 21 ++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/tailbone/templates/batch/view.mako b/tailbone/templates/batch/view.mako index b145cab0..f535ce4a 100644 --- a/tailbone/templates/batch/view.mako +++ b/tailbone/templates/batch/view.mako @@ -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; + } + @@ -79,6 +91,28 @@ ${self.context_menu_items()} +% if status_breakdown is not Undefined: +
+

Row Status Breakdown

+
+ % if status_breakdown: +
+ + % for i, (status, count) in enumerate(status_breakdown): + + + + + % endfor +
${status}${count}
+
+ % else: +

Nothing to report yet.

+ % endif +
+
+% endif +
${form.render(form_id='batch-form', buttons=capture(buttons))|n}
diff --git a/tailbone/views/batch/core.py b/tailbone/views/batch/core.py index f320ee2a..f29df6e3 100644 --- a/tailbone/views/batch/core.py +++ b/tailbone/views/batch/core.py @@ -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