Opened 8 years ago

Closed 7 years ago

#28264 closed Cleanup/optimization (fixed)

forms.FilePathField does not return sorted subdirectories in formfield

Reported by: Jean-Marie Thomas Owned by: Srinivas Reddy Thatiparthy
Component: Forms Version: 1.11
Severity: Normal Keywords: FilePathField
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

In the code :

for root, dirs, files in sorted(os.walk(self.path)):
    if self.allow_files:
# here, files are not sorted
        for f in files:
            if self.match is None or self.match_re.search(f):
                f = os.path.join(root, f)
                self.choices.append((f, f.replace(path, "", 1)))
    if self.allow_folders:
# and here, dirs are not sorted
        for f in dirs:
            if f == '__pycache__':

Attachments (1)

fields.diff (194 bytes ) - added by Jean-Marie Thomas 8 years ago.
Two lines of diff

Download all attachments as: .zip

Change History (5)

by Jean-Marie Thomas, 8 years ago

Attachment: fields.diff added

Two lines of diff

comment:1 by Tim Graham, 8 years ago

Description: modified (diff)
Needs tests: set
Summary: django.forms.FilePathField does not return sorted subdirectories in formfieldforms.FilePathField does not return sorted subdirectories in formfield
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

Could you also add a test and send a pull request on GitHub?

comment:2 by Srinivas Reddy Thatiparthy, 7 years ago

Owner: changed from nobody to Srinivas Reddy Thatiparthy
Status: newassigned

comment:3 by Tim Graham, 7 years ago

Needs tests: unset
Patch needs improvement: set

comment:4 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In b306c0c:

Fixed #28264 -- Made FilePathField sort files and directories when recursive=True.

Note: See TracTickets for help on using tickets.
Back to Top