Add make_status_renderer() to MasterView

batches aren't the only table/view where a status code/text combo may
be in use
This commit is contained in:
Lance Edgar 2022-12-20 19:15:31 -06:00
parent 871ea84f96
commit ed0a1f2740
2 changed files with 18 additions and 11 deletions

View file

@ -419,17 +419,6 @@ class BatchMasterView(MasterView):
f.remove_fields('executed', f.remove_fields('executed',
'executed_by') '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): def render_complete(self, batch, field):
permission_prefix = self.get_permission_prefix() permission_prefix = self.get_permission_prefix()
use_buefy = self.get_use_buefy() use_buefy = self.get_use_buefy()

View file

@ -953,6 +953,24 @@ class MasterView(View):
return email_key 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): def before_create_flush(self, obj, form):
pass pass