Ticket #5893: diff.5.diff
File diff.5.diff, 3.7 KB (added by , 17 years ago) |
---|
-
django/oldforms/__init__.py
946 946 947 947 class FilePathField(SelectField): 948 948 "A SelectField whose choices are the files in a given directory." 949 def __init__(self, field_name, path, match=None, recursive=False, is_required=False, validator_list=None, max_length=None ):949 def __init__(self, field_name, path, match=None, recursive=False, is_required=False, validator_list=None, max_length=None, allow_files=True, allow_folders=False): 950 950 import os 951 951 from django.db.models import BLANK_CHOICE_DASH 952 952 if match is not None: … … 955 955 choices = not is_required and BLANK_CHOICE_DASH[:] or [] 956 956 if recursive: 957 957 for root, dirs, files in os.walk(path): 958 for f in files: 959 if match is None or match_re.search(f): 960 f = os.path.join(root, f) 961 choices.append((f, f.replace(path, "", 1))) 958 if allow_folders: 959 for f in dirs: 960 if match is None or match_re.search(f): 961 f = os.path.join(root, f) 962 choices.append((f, f.replace(path, "", 1))) 963 if allow_files: 964 for f in files: 965 if match is None or match_re.search(f): 966 f = os.path.join(root, f) 967 choices.append((f, f.replace(path, "", 1))) 968 962 969 else: 963 970 try: 964 971 for f in os.listdir(path): 965 972 full_file = os.path.join(path, f) 966 if os.path.isfile(full_file) and (match is None or match_re.search(f)):973 if allow_folders and (os.path.isdir(full_file) and (match is None or match_re.search(f))): 967 974 choices.append((full_file, f)) 975 if allow_files and (os.path.isfile(full_file) and (match is None or match_re.search(f))): 976 choices.append((full_file, f)) 968 977 except OSError: 969 978 pass 970 979 SelectField.__init__(self, field_name, choices, 1, is_required, validator_list) -
django/db/models/fields/__init__.py
810 810 return super(FileField, self).formfield(**defaults) 811 811 812 812 class FilePathField(Field): 813 def __init__(self, verbose_name=None, name=None, path='', match=None, recursive=False, **kwargs):814 self.path, self.match, self.recursive = path, match, recursive813 def __init__(self, verbose_name=None, name=None, path='', match=None, recursive=False, allow_files=True, allow_folders=False, **kwargs): 814 self.path, self.match, self.recursive, self.allow_files, self.allow_folders = path, match, recursive, allow_files, allow_folders 815 815 kwargs['max_length'] = kwargs.get('max_length', 100) 816 816 Field.__init__(self, verbose_name, name, **kwargs) 817 assert self.allow_folders or self.allow_files, "allow_folders or allow_files can not be both False" 817 818 818 819 def get_manipulator_field_objs(self): 819 return [curry(oldforms.FilePathField, path=self.path, match=self.match, recursive=self.recursive )]820 return [curry(oldforms.FilePathField, path=self.path, match=self.match, recursive=self.recursive, allow_files=self.allow_files, allow_folders=self.allow_folders)] 820 821 821 822 class FloatField(Field): 822 823 empty_strings_allowed = False