summaryrefslogtreecommitdiff
path: root/chimere/widgets.py
diff options
context:
space:
mode:
Diffstat (limited to 'chimere/widgets.py')
-rw-r--r--chimere/widgets.py35
1 files changed, 21 insertions, 14 deletions
diff --git a/chimere/widgets.py b/chimere/widgets.py
index 480eb9b..f735db1 100644
--- a/chimere/widgets.py
+++ b/chimere/widgets.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2008-2016 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
@@ -130,27 +130,34 @@ JQuery UI button select widget.
class ButtonRadioInput(RadioSelect):
- def render(self, name=None, value=None, attrs=None, choices=()):
- name = name or self.name
- value = value or self.value
+ def tag(self, name, value):
+ selected = str(value) == str(self.choices[0][0])
+ return '<input type="radio" name="{}" value="{}"{}>'.format(
+ name, self.choices[0][0],
+ ' selected="selected"' if selected else '')
+
+ def render(self, name=None, value=None, attrs=None, choices=(),
+ index=0):
attrs = attrs or self.attrs
if 'id' in self.attrs:
- label_for = ' for="%s_%s"' % (self.attrs['id'], self.index)
+ label_for = ' for="%s_%s"' % (self.attrs['id'], index)
else:
label_for = ''
- choice_label = conditional_escape(str(self.choice_label))
- return mark_safe(u'%s <label%s>%s</label>' % (self.tag(), label_for,
- choice_label))
+ choice_label = conditional_escape(str(self.choices[0][1]))
+ return mark_safe('%s <label%s>%s</label>' % (self.tag(name, value),
+ label_for,
+ choice_label))
class ButtonRadioFieldRenderer(RadioFieldRenderer):
def __iter__(self):
for i, choice in enumerate(self.choices):
- yield ButtonRadioInput(self.name, self.value, self.attrs.copy(),
- choice, i)
+ yield ButtonRadioInput(self.attrs.copy(), [choice])
def render(self):
- return mark_safe('\n'.join([str(w) for w in self]))
+ return mark_safe('\n'.join([
+ w.render(self.name, self.value, index=idx)
+ for idx, w in enumerate(self)]))
class ButtonSelectWidget(forms.RadioSelect):
@@ -690,11 +697,11 @@ class ImportFiltrWidget(AreaWidget):
name, _("Tag:"), name, self.xapi_tag)
tpl += "<script type='text/javascript'>\n"
tpl += "var default_xapi='%s';" % settings.CHIMERE_XAPI_URL
- tpl += u'var msg_missing_area = "%s";' % \
+ tpl += 'var msg_missing_area = "%s";' % \
_("You have to select an area.")
- tpl += u'var msg_missing_type = "%s";' % \
+ tpl += 'var msg_missing_type = "%s";' % \
_("You have to select a type.")
- tpl += u'var msg_missing_filtr = "%s";' % \
+ tpl += 'var msg_missing_filtr = "%s";' % \
_("You have to insert a filter tag.")
tpl += "</script>\n"
help_msg = _("If you change the above form don't forget to refresh "