Ticket #3119: filename_nomalizer_fix.diff
File filename_nomalizer_fix.diff, 2.4 KB (added by , 18 years ago) |
---|
-
docs/model-api.txt
196 196 197 197 A file-upload field. 198 198 199 Has an extra required argument, ``upload_to``, a local filesystem path to 200 which files should be upload. This path may contain `strftime formatting`_, 201 which will be replaced by the date/time of the file upload (so that 202 uploaded files don't fill up the given directory). 199 A ``FileField`` has an extra required argument ``upload_to`` and an 200 optional argument ``filename_normalizer``. The ``upload_to`` specifies a 201 local filesystem path to which files should be upload. This path may 202 contain `strftime formatting`_, which will be replaced by the date/time of 203 the file upload (so that uploaded files don't fill up the given 204 directory). The ``filename_normalizer`` is a function to "normalize" 205 filename from the value provided from file-upload widget. The default value 206 is set to ``django.utils.text.get_valid_filename`` which strips all 207 non-ascii characters. 203 208 204 209 The admin represents this as an ``<input type="file">`` (a file-upload widget). 205 210 -
django/db/models/fields/__init__.py
580 580 return forms.EmailField(**defaults) 581 581 582 582 class FileField(Field): 583 def __init__(self, verbose_name=None, name=None, upload_to='', **kwargs): 583 from django.utils.text import get_valid_filename 584 def __init__(self, verbose_name=None, name=None, upload_to='', filename_normalizer=get_valid_filename, **kwargs): 584 585 self.upload_to = upload_to 586 self.filename_normalizer = filename_normalizer 585 587 Field.__init__(self, verbose_name, name, **kwargs) 586 588 587 589 def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True): … … 656 658 return os.path.normpath(datetime.datetime.now().strftime(self.upload_to)) 657 659 658 660 def get_filename(self, filename): 659 from django.utils.text import get_valid_filename 660 f = os.path.join(self.get_directory_name(), get_valid_filename(os.path.basename(filename))) 661 f = os.path.join(self.get_directory_name(), self.filename_normalizer(os.path.basename(filename))) 661 662 return os.path.normpath(f) 662 663 663 664 class FilePathField(Field):