1483 |
1483 |
|
1484 |
1484 |
|
1485 |
1485 |
class SingleSelectHintWidget(SingleSelectWidget):
|
|
1486 |
template_name = 'qommon/forms/widgets/select.html'
|
|
1487 |
|
1486 |
1488 |
def __init__(self, name, value=None, **kwargs):
|
1487 |
1489 |
self.options_with_attributes = kwargs.pop('options_with_attributes', None)
|
1488 |
1490 |
super(SingleSelectHintWidget, self).__init__(name, value=value, **kwargs)
|
... | ... | |
1490 |
1492 |
def separate_hint(self):
|
1491 |
1493 |
return (self.hint and len(self.hint) > 80)
|
1492 |
1494 |
|
1493 |
|
def render_content(self):
|
1494 |
|
attrs = {'id': 'form_' + self.name}
|
1495 |
|
if self.attrs:
|
1496 |
|
attrs.update(self.attrs)
|
1497 |
|
tags = [htmltag('select', name=self.name, **attrs)]
|
1498 |
|
options = self.options[:]
|
1499 |
|
include_disabled = False
|
|
1495 |
def get_options(self):
|
1500 |
1496 |
if self.options_with_attributes:
|
1501 |
|
options = self.options_with_attributes
|
1502 |
|
include_disabled = True
|
1503 |
|
if not self.separate_hint() and self.hint:
|
1504 |
|
r = htmltag('option', value='', selected=None)
|
1505 |
|
tags.append(r + htmlescape(self.hint) + htmltext('</option>'))
|
1506 |
|
if self.options[0][0] is None:
|
1507 |
|
# hint has been put as first element, skip the default empty
|
1508 |
|
# value.
|
1509 |
|
options = self.options[1:]
|
|
1497 |
options = self.options_with_attributes[:]
|
|
1498 |
else:
|
|
1499 |
options = self.options[:]
|
|
1500 |
if options[0][0] is None:
|
|
1501 |
options = self.options[1:]
|
|
1502 |
|
|
1503 |
tags = []
|
1510 |
1504 |
for option in options:
|
1511 |
1505 |
object, description, key = option[:3]
|
1512 |
1506 |
html_attrs = {}
|
... | ... | |
1517 |
1511 |
html_attrs['disabled'] = 'disabled'
|
1518 |
1512 |
if description is None:
|
1519 |
1513 |
description = ''
|
1520 |
|
r = htmltag('option', **html_attrs)
|
1521 |
|
tags.append(r + htmlescape(description) + htmltext('</option>'))
|
1522 |
|
tags.append(htmltext('</select>'))
|
1523 |
|
return htmltext('\n').join(tags)
|
|
1514 |
yield {'description': description, 'attrs': html_attrs,
|
|
1515 |
'options': option[-1] if self.options_with_attributes else None}
|
1524 |
1516 |
|
1525 |
1517 |
def get_hint(self):
|
1526 |
1518 |
if self.separate_hint():
|