Opened 5 years ago

Closed 5 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 5 years ago.
Two lines of diff

Download all attachments as: .zip

Change History (5)

Changed 5 years ago by Jean-Marie Thomas

Attachment: fields.diff added

Two lines of diff

comment:1 Changed 5 years ago by Tim Graham

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 Changed 5 years ago by Srinivas Reddy Thatiparthy

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

comment:3 Changed 5 years ago by Tim Graham

Needs tests: unset
Patch needs improvement: set

comment:4 Changed 5 years ago by Tim Graham <timograham@…>

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