diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-04-17 12:04:08 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-12 08:41:54 +0200 |
commit | 6c57e2b6974a7acffff684279ab2c2b74edd1676 (patch) | |
tree | 67d308063f0c78cbf26e3b040821e762fed5b4e3 /ishtar_common/widgets.py | |
parent | 674eeafec7e973bf0d0fe24ada9866d346fd34cf (diff) | |
download | Ishtar-6c57e2b6974a7acffff684279ab2c2b74edd1676.tar.bz2 Ishtar-6c57e2b6974a7acffff684279ab2c2b74edd1676.zip |
WIP on account wizard. Wizard: can use switch for deletion. Better display of formsets on done wizard.
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 |