From ed0a1f27406909f8d8b593e2d14ccb8f1930907c Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 20 Dec 2022 19:15:31 -0600 Subject: [PATCH] Add `make_status_renderer()` to MasterView batches aren't the only table/view where a status code/text combo may be in use --- tailbone/views/batch/core.py | 11 ----------- tailbone/views/master.py | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/tailbone/views/batch/core.py b/tailbone/views/batch/core.py index 35b19e51..d0babe87 100644 --- a/tailbone/views/batch/core.py +++ b/tailbone/views/batch/core.py @@ -419,17 +419,6 @@ class BatchMasterView(MasterView): f.remove_fields('executed', 'executed_by') - def make_status_renderer(self, enum): - def render_status(batch, field): - value = batch.status_code - if value is None: - return "" - status_code_text = enum.get(value, six.text_type(value)) - if batch.status_text: - return HTML.tag('span', title=batch.status_text, c=status_code_text) - return status_code_text - return render_status - def render_complete(self, batch, field): permission_prefix = self.get_permission_prefix() use_buefy = self.get_use_buefy() diff --git a/tailbone/views/master.py b/tailbone/views/master.py index a0d51329..313d7fd8 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -953,6 +953,24 @@ class MasterView(View): return email_key + def make_status_renderer(self, enum): + """ + Creates and returns a function for use with rendering a + "status combo" field(s) for a record. Assumes the record has + both ``status_code`` and ``status_text`` fields, as batches + do. Renders the simple status code text, and if custom status + text is present, it is rendered as a tooltip. + """ + def render_status(obj, field): + value = obj.status_code + if value is None: + return "" + status_code_text = enum.get(value, six.text_type(value)) + if obj.status_text: + return HTML.tag('span', title=obj.status_text, c=status_code_text) + return status_code_text + return render_status + def before_create_flush(self, obj, form): pass