Code

Opened 7 years ago

Closed 7 years ago

#3993 closed (fixed)

[patch] Add convenience methods to SortedDict

Reported by: Paul Collier <paul@…> Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When generating dynamic fields for a newforms form it is convenient to have a few more SortedDict methods (particularly insert(), which is not entirely trivial) for DRY.

Attachments (1)

sorted_dict.diff (1.4 KB) - added by Paul Collier <paul@…> 7 years ago.

Download all attachments as: .zip

Change History (7)

Changed 7 years ago by Paul Collier <paul@…>

comment:1 Changed 7 years ago by Paul Collier <paul@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Add convenience methods to SortedDict to [patch] Add convenience methods to SortedDict

comment:2 Changed 7 years ago by SmileyChris

  • Triage Stage changed from Unreviewed to Design decision needed

Seems useful, what does core think?

comment:3 Changed 7 years ago by mtredinnick

  • Triage Stage changed from Design decision needed to Accepted

Seems reasonable. We should check this really does implement all the useful dictionary methods and get it right -- rather than just implementing the ones Paul needs right now.

I don't think the insert() method is needed, though. SortedDict is sorted by insert order, not by anything else, so inserting out of order seems to go against the grain.

comment:4 Changed 7 years ago by Paul Collier <paul@…>

Hmm, okay... I was using that to dynamically insert a field at the top of a Form I was using. If it violates what's expected, don't worry about it; either I'll come up with something else or just continue to patch it solely on my installation :)

comment:5 Changed 7 years ago by Fredrik Lundh <fredrik@…>

  • Triage Stage changed from Accepted to Ready for checkin

I think "insert" makes sense (there's already a "value_for_index" method, which breaks the "dictness" of this class). Maybe it could be called "insert_at_index"?

comment:6 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(In [6350]) Fixed #3993 -- Added some useful dictionary methods to SortedDict, plus an insert() method. Patch from Paul Collier.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.