Changes between Initial Version and Version 1 of Ticket #23681
- Timestamp:
- Oct 18, 2014, 10:24:02 AM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #23681
- Property Owner changed from to
- Property Status new → assigned
- Property Summary NullBooleanSelect should have empty_label or similar → NullBooleanSelect should have choices kwarg
-
Ticket #23681 – Description
initial v1 1 `NullBooleanSelect` is responsible of making the values 1, 2, and 3 turn into None, True or False. That's why having custom "choices" kwarg is perhaps a bit over the top. Well, it's pretty meaningless to have a utility class if you start passing a choices kwarg that contains half of the code that makes up NullBooleanSelect.1 `NullBooleanSelect` is responsible of making the values 1, 2, and 3 turn into None, True or False. That's very nice of it, however it does not allow to customize the texts of the choices. 2 2 3 However, I need one small feature from this widget! Namely, that the following...3 I'm not sure if exposing the internal 1, 2, 3 representation is a good idea, but it would seem okay since it follows the convention of other Select widgets. Ideally, I would like to see this... 4 4 5 5 … … 17 17 18 18 19 ... ischanged to:19 ...changed to: 20 20 21 21 … … 25 25 A Select Widget intended to be used with NullBooleanField. 26 26 """ 27 def __init__(self, empty_label=None, attrs=None): 28 choices = (('1', empty_label or ugettext_lazy('Unknown')), 29 ('2', ugettext_lazy('Yes')), 30 ('3', ugettext_lazy('No'))) 27 def __init__(self, choices=None, attrs=None): 28 if not choices: 29 choices = (('1', empty_label or ugettext_lazy('Unknown')), 30 ('2', ugettext_lazy('Yes')), 31 ('3', ugettext_lazy('No'))) 31 32 super(NullBooleanSelect, self).__init__(attrs, choices) 32 33 }}} … … 35 36 The motivation is that I often leave out labels to have them put as the default first option of the Select. An example use: 36 37 37 38 38 {{{ 39 39 class MyForm(forms.Form): 40 has_payments= forms.NullBooleanField(40 gender = forms.NullBooleanField( 41 41 label="", 42 42 required=False, 43 widget=NullBooleanSelect(empty_label=_(u"Has previous payments?")) 43 widget=NullBooleanSelect(choices=[("1", "Male and female"), 44 ("2", "Only female"), 45 ("3", "Only Male")]) 44 46 help_text=_(u"Only show subscriptions that have previously been charged"), 45 47 ) … … 47 49 }}} 48 50 49 Even more preferable, would be to place the `empty_label` kwarg in `NullBooleanField`, as that would match the options for ModelChoiceField. 51 Even more preferable, would be to place the `choices` kwarg in `NullBooleanField`, as that would match the options for ChoiceField. 52 53 <b>Updated</b> In the original issue report, I put `empty_label` but realized that when selecting "Yes", it was impossible for the user to see what "Yes" was the answer to.