From 5cec585fdf7bbf761ff0056ff5696cac12138f67 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 2 Jan 2025 23:14:10 -0600 Subject: [PATCH] fix: improve rendering for batch row status --- src/wuttaweb/views/batch.py | 12 +++++++++++- tests/views/test_batch.py | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/wuttaweb/views/batch.py b/src/wuttaweb/views/batch.py index be44320..7ce3199 100644 --- a/src/wuttaweb/views/batch.py +++ b/src/wuttaweb/views/batch.py @@ -53,7 +53,7 @@ class BatchMasterView(MasterView): labels = { 'id': "Batch ID", - 'status_code': "Batch Status", + 'status_code': "Status", } sort_defaults = ('id', 'desc') @@ -62,6 +62,10 @@ class BatchMasterView(MasterView): rows_title = "Batch Rows" rows_sort_defaults = 'sequence' + row_labels = { + 'status_code': "Status", + } + def __init__(self, request, context=None): super().__init__(request, context=context) self.batch_handler = self.get_batch_handler() @@ -381,6 +385,12 @@ class BatchMasterView(MasterView): g.set_label('sequence', "Seq.", column_only=True) + g.set_renderer('status_code', self.render_row_status) + + def render_row_status(self, row, key, value): + """ """ + return row.STATUS.get(value, value) + ############################## # configuration ############################## diff --git a/tests/views/test_batch.py b/tests/views/test_batch.py index a3a34fe..9b1db0f 100644 --- a/tests/views/test_batch.py +++ b/tests/views/test_batch.py @@ -367,6 +367,12 @@ class TestBatchMasterView(WebTestCase): self.assertIn('sequence', grid.labels) self.assertEqual(grid.labels['sequence'], "Seq.") + def test_render_row_status(self): + with patch.object(mod.BatchMasterView, 'get_batch_handler', return_value=None): + view = self.make_view() + row = MagicMock(foo=1, STATUS={1: 'bar'}) + self.assertEqual(view.render_row_status(row, 'foo', 1), 'bar') + def test_defaults(self): # nb. coverage only with patch.object(mod.BatchMasterView, 'model_class', new=MockBatch, create=True):