From 6c57e2b6974a7acffff684279ab2c2b74edd1676 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 17 Apr 2018 12:04:08 +0200 Subject: WIP on account wizard. Wizard: can use switch for deletion. Better display of formsets on done wizard. --- ishtar_common/widgets.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'ishtar_common/widgets.py') 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""" - -""".format(final_attrs, attrs['id']) + extra_label = "" + if self.extra_label: + extra_label = ''.format(attrs['id'], + self.extra_label) + output = u""" + {} +""".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 -- cgit v1.2.3