198 |
198 |
|
199 |
199 |
|
200 |
200 |
class RadiobuttonsWidget(quixote.form.RadiobuttonsWidget):
|
|
201 |
template_name = 'qommon/forms/widgets/radiobuttons.html'
|
|
202 |
|
201 |
203 |
def __init__(self, name, value=None, **kwargs):
|
202 |
204 |
self.options_with_attributes = kwargs.pop('options_with_attributes', None)
|
203 |
205 |
super(RadiobuttonsWidget, self).__init__(name, value=value, **kwargs)
|
204 |
206 |
|
205 |
|
def render_content(self):
|
206 |
|
include_disabled = False
|
207 |
|
options = self.options[:]
|
208 |
|
if self.options_with_attributes:
|
209 |
|
options = self.options_with_attributes
|
210 |
|
include_disabled = True
|
211 |
|
|
212 |
|
r = TemplateIO(html=True)
|
|
207 |
def get_options(self):
|
|
208 |
options = self.options_with_attributes or self.options
|
213 |
209 |
for i, option in enumerate(options):
|
214 |
210 |
object, description, key = option[:3]
|
215 |
|
r += htmltext('<label>')
|
216 |
|
html_attrs = self.attrs.copy()
|
217 |
|
if self.is_selected(object):
|
218 |
|
html_attrs['checked'] = 'checked'
|
219 |
|
elif self.attrs.get('readonly'):
|
220 |
|
html_attrs['disabled'] = 'disabled'
|
221 |
|
if self.options_with_attributes and option[-1].get('disabled'):
|
222 |
|
html_attrs['disabled'] = 'disabled'
|
223 |
|
label_tag = htmltext('<label class="disabled">')
|
224 |
|
r += htmltag("input", xml_end=True,
|
225 |
|
type="radio",
|
226 |
|
name=self.name,
|
227 |
|
value=key,
|
228 |
|
**html_attrs)
|
229 |
|
r += htmltext('<span>%s</span>') % description
|
230 |
|
r += htmltext('</label>')
|
231 |
|
if i != len(options) - 1:
|
232 |
|
r += htmltext(self.delim)
|
233 |
|
return r.getvalue()
|
|
211 |
yield {
|
|
212 |
'value': key,
|
|
213 |
'label': description,
|
|
214 |
'disabled': bool(self.options_with_attributes and option[-1].get('disabled')),
|
|
215 |
'selected': self.is_selected(object)
|
|
216 |
}
|
234 |
217 |
|
235 |
218 |
def checkbox_render_content(self, standalone=True):
|
236 |
219 |
attrs = {'id': 'form_' + self.name}
|
237 |
|
-
|