Django

Code

Ticket #4412 (closed: fixed)

Opened 1 year ago

Last modified 21 hours ago

Allow Select and SelectMultiple widgets to render HTML optgroups from nested choices structures

Reported by: mrmachine Assigned to: SmileyChris
Milestone: 1.0 beta Component: django.newforms
Version: SVN Keywords: newforms select widget nested choices optgroup
Cc: real.human@mrmachine.net Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

if the label of a choices iterable is a list or tuple, treat that option as an option group with the value as the label.

this shouldn't break any backwards compatibility and negates the need for a separate SelectGrouped? widget (which has been previously rejected).

Attachments

4412-1.diff (7.3 kB) - added by Matt McClanahan <cardinal@dodds.net> on 05/29/07 01:46:10.
4412-2.diff (8.9 kB) - added by Matt McClanahan <cardinal@dodds.net> on 06/01/07 03:58:48.
4412-3.diff (9.0 kB) - added by Matt McClanahan <cardinal@dodds.net> on 07/05/07 19:57:49.
Updated for the unicode branch merge
4412-4.diff (9.0 kB) - added by Matt McClanahan <cardinal@dodds.net> on 07/05/07 20:06:08.
Bugfix, sigh.
4412.diff (8.9 kB) - added by Tai Lee <real.human@mrmachine.net> on 08/01/07 23:51:15.
updated to work on trunk, after unicode changes.
4412-r6025.diff (10.7 kB) - added by russellm on 08/30/07 08:07:04.
Update to r6025, plus some polish to docs and implementation
4412-r7000.diff (7.2 kB) - added by Tai Lee <real.human@mrmachine.net> on 01/09/08 18:52:29.
Updated to r7000.
4412.2.diff (11.9 kB) - added by SmileyChris on 07/08/08 18:28:15.
Updated patch, fixed to work with multiple select and old admin

Change History

05/29/07 01:46:10 changed by Matt McClanahan <cardinal@dodds.net>

  • attachment 4412-1.diff added.

05/29/07 01:58:57 changed by Matt McClanahan <cardinal@dodds.net>

  • needs_better_patch changed.
  • summary changed from [patch] changed newforms' Select widget to accept nested choices and display using the optgroup tag. to Allow Select and SelectMultiple widgets to render HTML optgroups from nested choices structures.
  • needs_tests changed.
  • needs_docs changed.

Initial implementation proposal. An example choices structure (from the tests in the patch):

choices = (
    ('outer1', 'Outer 1'),
    ('Group 1', (
            ('inner1', 'Inner 1'),
            ('inner2', 'Inner 2'),
        )
    )
)

yields the following HTML:

<select name="nestchoice">
<option value="outer1">Outer 1</option>
<optgroup label="Group 1">
<option value="inner1">Inner 1</option>
<option value="inner2">Inner 2</option>
</optgroup>
</select>

05/29/07 03:50:51 changed by ubernostrum

  • stage changed from Unreviewed to Design decision needed.

05/31/07 12:05:22 changed by jacob

  • needs_docs set to 1.
  • stage changed from Design decision needed to Accepted.

Accepted; needs documentation.

06/01/07 03:58:48 changed by Matt McClanahan <cardinal@dodds.net>

  • attachment 4412-2.diff added.

06/01/07 04:00:30 changed by Matt McClanahan <cardinal@dodds.net>

  • needs_docs deleted.

That reminded me that I overlooked get_FIELD_display. Done and done.

07/05/07 19:57:49 changed by Matt McClanahan <cardinal@dodds.net>

  • attachment 4412-3.diff added.

Updated for the unicode branch merge

07/05/07 20:06:08 changed by Matt McClanahan <cardinal@dodds.net>

  • attachment 4412-4.diff added.

Bugfix, sigh.

08/01/07 23:51:15 changed by Tai Lee <real.human@mrmachine.net>

  • attachment 4412.diff added.

updated to work on trunk, after unicode changes.

08/02/07 02:01:32 changed by Simon G. <dev@simon.net.nz>

  • stage changed from Accepted to Ready for checkin.

Ready for checkin: JKM accepted, has tests, has docs, looks good.

08/30/07 08:07:04 changed by russellm

  • attachment 4412-r6025.diff added.

Update to r6025, plus some polish to docs and implementation

09/16/07 00:22:34 changed by mattmcc

  • owner changed from nobody to mattmcc.
  • status changed from new to assigned.

09/16/07 00:23:14 changed by mattmcc

  • owner changed from mattmcc to nobody.
  • status changed from assigned to new.

Er. No, I don't own this. :P

10/20/07 09:27:22 changed by mtredinnick

  • stage changed from Ready for checkin to Accepted.

I think "ready to checkin" is a little optimistic at this point. As Russell points out in the related django-dev thread, the patch will have problems with existing admin, so it needs to wait until after newforms-admin is merged.

01/09/08 18:52:29 changed by Tai Lee <real.human@mrmachine.net>

  • attachment 4412-r7000.diff added.

Updated to r7000.

06/17/08 20:17:51 changed by anonymous

  • milestone set to 1.0 beta.

06/19/08 13:06:18 changed by SmileyChris

  • owner changed from nobody to SmileyChris.
  • status changed from new to assigned.

Note: I've got an updated version of this patch running which fixes a few issues... If i haven't put it live in a week, bug me about it.

07/08/08 18:28:15 changed by SmileyChris

  • attachment 4412.2.diff added.

Updated patch, fixed to work with multiple select and old admin

07/08/08 18:30:46 changed by SmileyChris

This new patch allows this to continue with the old admin (even if it is going to be short-lived - i needed it for now) and also makes MultipleSelect work. I abstracted some of the widget rendering logic between Select and MultipleSelect which also meant making MultipleSelect a subclass of Select, which I always thought it should have been anyway...

Added tests for the new MultipleSelect functionality.

07/08/08 18:34:16 changed by SmileyChris

Amusingly, I see that Russ had already done the SelectMultiple work. But I like my abstraction a bit better.

07/19/08 02:53:02 changed by russellm

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [7977]) Fixed #4412 -- Added support for optgroups, both in the model when defining choices, and in the form field and widgets when the optgroups are displayed. Thanks to Matt McClanahan? <cardinal@dodds.net>, Tai Lee <real.human@mrmachine.net> and SmileyChris? for their contributions at various stages in the life of this ticket.


Add/Change #4412 (Allow Select and SelectMultiple widgets to render HTML optgroups from nested choices structures)




Change Properties
Action