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

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