From fb391b8b98e9e6a3dc89cfb43892f96cf70d199c Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Thu, 2 Dec 2010 00:49:15 +0000 Subject: [PATCH] Fixed #8217 -- Correctly sort files in FilePathFields on older Python versions. Thanks, bernd and davidb. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14772 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/forms/fields.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django/forms/fields.py b/django/forms/fields.py index 16c9218549..a0b559319b 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -867,14 +867,14 @@ class FilePathField(ChoiceField): self.match_re = re.compile(self.match) if recursive: - for root, dirs, files in os.walk(self.path): + for root, dirs, files in sorted(os.walk(self.path)): 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))) else: try: - for f in os.listdir(self.path): + for f in sorted(os.listdir(self.path)): full_file = os.path.join(self.path, f) if os.path.isfile(full_file) and (self.match is None or self.match_re.search(f)): self.choices.append((full_file, f))