Opened 7 years ago

Last modified 7 years ago

#28264 closed Cleanup/optimization

forms.FilePathField does not return sorted subdirectories in formfield — at Version 1

Reported by: Jean-Marie Thomas Owned by: nobody
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__':

Change History (2)

by Jean-Marie Thomas, 7 years ago

Attachment: fields.diff added

Two lines of diff

comment:1 by Tim Graham, 7 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?

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