diff options
Diffstat (limited to 'ishtar_common/widgets.py')
-rw-r--r-- | ishtar_common/widgets.py | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 2df06cf21..60e5fc016 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -261,19 +261,35 @@ class DeleteWidget(forms.CheckboxInput): class SwitchWidget(forms.CheckboxInput): + extra_class = "" + extra_label = "" + def render(self, name, value, attrs=None, renderer=None): + extra_class = (" " + self.extra_class) if self.extra_class else "" + default = {"name": name, "value": "1", + 'class': "switch" + extra_class, + 'type': 'checkbox'} + if value: + default['checked'] = 'checked' attrs = self.build_attrs( - attrs, {"name": name, "value": '0', - 'class': "switch", - 'type': 'checkbox'} + attrs, default ) final_attrs = flatatt(attrs) - output = u"""<span class="switch"> - <input{}> -</span>""".format(final_attrs, attrs['id']) + extra_label = "" + if self.extra_label: + extra_label = '<label for="{}">{}</label>'.format(attrs['id'], + self.extra_label) + output = u"""<span class="switch{}"> + <input{}>{} +</span>""".format(extra_class, final_attrs, extra_label) return mark_safe(output) +class DeleteSwitchWidget(SwitchWidget): + extra_class = "danger" + extra_label = _(u"Delete") + + class ImageFileInput(ClearableFileInput): template_name = 'widgets/image_input.html' NO_FORM_CONTROL = True |