Ticket #5893: diff.2.diff
File diff.2.diff, 3.9 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_files: 959 for f in files: 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_folders: 964 for f in dirs: 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))) 962 968 else: 963 969 try: 964 970 for f in os.listdir(path): 965 971 full_file = os.path.join(path, f) 966 if os.path.isfile(full_file) and (match is None or match_re.search(f)): 967 choices.append((full_file, f)) 972 if allow_files and allow_folders: 973 if (os.path.isfile(full_file) or os.path.isdir(full_file)) and (match is None or match_re.search(f)): 974 choices.append((full_file, f)) 975 elif allow_folders: 976 if os.path.isdir(full_file) and (match is None or match_re.search(f)): 977 choices.append((full_file, f)) 978 elif allow_files: 979 if os.path.isfile(full_file) and (match is None or match_re.search(f)): 980 choices.append((full_file, f)) 968 981 except OSError: 969 982 pass 970 983 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 817 818 818 def get_manipulator_field_objs(self): 819 return [curry(oldforms.FilePathField, path=self.path, match=self.match, recursive=self.recursive )]819 return [curry(oldforms.FilePathField, path=self.path, match=self.match, recursive=self.recursive, allow_files=self.allow_files, allow_folders=self.allow_folders)] 820 820 821 821 class FloatField(Field): 822 822 empty_strings_allowed = False