{{{
class SelectWithData(forms.widgets.Select):
def __init__(self, *args, **kwargs):
self.options_data = kwargs.pop('options_data', None)
super(SelectWithData, self).__init__(*args, **kwargs)
def render_option(self, selected_choices, option_value, option_label):
if self.options_data and option_value in self.options_data:
price=''
if 'price' in self.options_data[option_value]:
price = self.options_data[option_value]['price']
html = u'<option value="{}" price="{}" >{}</option>'.format(
escape(option_value),
price,
conditional_escape(force_unicode(option_label)))
else:
# No options_data
option_value = force_unicode(option_value)
html = u'<option value="{}">{}</option>'.format(
escape(option_value),
conditional_escape(force_unicode(option_label)))
return html
class MyForm(forms.Form):
state = forms.ChoiceField(widget=forms.SelectWithData(choices=[]))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28308>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"f2b698631719c6df082a627b6f7ddf2d7f9fa751" f2b69863]:
{{{
#!CommitTicketReference repository=""
revision="f2b698631719c6df082a627b6f7ddf2d7f9fa751"
Fixed #28308 -- Doc'd removal of Select.render_option() (refs #15667).
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28308#comment:1>
Comment (by Tim Graham <timograham@…>):
In [changeset:"f20168e873d9c55b66aa49aee85d9e4804697afb" f20168e8]:
{{{
#!CommitTicketReference repository=""
revision="f20168e873d9c55b66aa49aee85d9e4804697afb"
[1.11.x] Fixed #28308 -- Doc'd removal of Select.render_option() (refs
#15667).
Backport of f2b698631719c6df082a627b6f7ddf2d7f9fa751 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28308#comment:2>
* component: Forms => Documentation
* stage: Unreviewed => Accepted
* type: Bug => Cleanup/optimization
Comment:
Usually we don't document removal of undocumented APIs but I suppose it
doesn't hurt here.
--
Ticket URL: <https://code.djangoproject.com/ticket/28308#comment:3>