From 30e6b6e29cfe4925b2554507c9cc940edc8d2782 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 6 Apr 2016 21:17:02 -0500 Subject: [PATCH] Add flag for rendering key value, for enum field renderers Only valid during the readonly rendering. Not sure how useful this will be in the long run... --- tailbone/forms/renderers/common.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tailbone/forms/renderers/common.py b/tailbone/forms/renderers/common.py index 43158ce3..c53a76c6 100644 --- a/tailbone/forms/renderers/common.py +++ b/tailbone/forms/renderers/common.py @@ -158,12 +158,13 @@ class EnumFieldRenderer(SelectFieldRenderer): """ Renderer for simple enumeration fields. """ - enumeration = {} + render_key = False - def __init__(self, arg): + def __init__(self, arg, render_key=False): if isinstance(arg, dict): self.enumeration = arg + self.render_key = render_key else: self(arg) @@ -174,8 +175,11 @@ class EnumFieldRenderer(SelectFieldRenderer): def render_readonly(self, **kwargs): value = self.raw_value if value is None: - return u'' - return self.enumeration.get(value, unicode(value)) + return '' + rendered = self.enumeration.get(value, unicode(value)) + if self.render_key: + rendered = '{} - {}'.format(value, rendered) + return rendered def render(self, **kwargs): opts = [(self.enumeration[x], x) for x in self.enumeration]