Made EnumFieldRenderer
a proper class.
This commit is contained in:
parent
a11b8d9ff2
commit
3070c280cc
|
@ -76,26 +76,32 @@ class AutocompleteFieldRenderer(FieldRenderer):
|
||||||
return unicode(value)
|
return unicode(value)
|
||||||
|
|
||||||
|
|
||||||
def EnumFieldRenderer(enum):
|
class EnumFieldRenderer(SelectFieldRenderer):
|
||||||
"""
|
"""
|
||||||
Adds support for enumeration fields.
|
Renderer for simple enumeration fields.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Renderer(SelectFieldRenderer):
|
enumeration = {}
|
||||||
|
|
||||||
def render_readonly(self, **kwargs):
|
|
||||||
value = self.raw_value
|
|
||||||
if value is None:
|
|
||||||
return ''
|
|
||||||
if value in enum:
|
|
||||||
return enum[value]
|
|
||||||
return str(value)
|
|
||||||
|
|
||||||
def render(self, **kwargs):
|
def __init__(self, arg):
|
||||||
opts = [(enum[x], x) for x in sorted(enum)]
|
if isinstance(arg, dict):
|
||||||
return SelectFieldRenderer.render(self, opts, **kwargs)
|
self.enumeration = arg
|
||||||
|
else:
|
||||||
|
self(arg)
|
||||||
|
|
||||||
return Renderer
|
def __call__(self, field):
|
||||||
|
super(EnumFieldRenderer, self).__init__(field)
|
||||||
|
return self
|
||||||
|
|
||||||
|
def render_readonly(self, **kwargs):
|
||||||
|
value = self.raw_value
|
||||||
|
if value is None:
|
||||||
|
return u''
|
||||||
|
return self.enumeration.get(value, unicode(value))
|
||||||
|
|
||||||
|
def render(self, **kwargs):
|
||||||
|
opts = [(self.enumeration[x], x) for x in sorted(self.enumeration)]
|
||||||
|
return SelectFieldRenderer.render(self, opts, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class YesNoFieldRenderer(CheckBoxFieldRenderer):
|
class YesNoFieldRenderer(CheckBoxFieldRenderer):
|
||||||
|
|
Loading…
Reference in a new issue