Add support for the two state widget to be centered.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -79,21 +79,26 @@ class TextAreaDiv(forms.widgets.Widget):
|
||||
|
||||
|
||||
class TwoStateWidget(object):
|
||||
def __init__(self, state, icon_ok=None, icon_fail=None):
|
||||
def __init__(self, state, center=False, icon_ok=None, icon_fail=None):
|
||||
self.state = state
|
||||
self.icon_ok = icon_ok or default_icon_ok
|
||||
self.icon_fail = icon_fail or default_icon_fail
|
||||
self.center = center
|
||||
|
||||
def render(self):
|
||||
center_class = ''
|
||||
if self.center:
|
||||
center_class = 'text-center'
|
||||
|
||||
if self.state:
|
||||
return mark_safe(
|
||||
'<div class="text-success">{}</div>'.format(
|
||||
self.icon_ok.render()
|
||||
'<div class="{} text-success">{}</div>'.format(
|
||||
center_class, self.icon_ok.render()
|
||||
)
|
||||
)
|
||||
else:
|
||||
return mark_safe(
|
||||
'<div class="text-danger">{}</div>'.format(
|
||||
self.icon_fail.render()
|
||||
'<div class="{} text-danger">{}</div>'.format(
|
||||
center_class, self.icon_fail.render()
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user