1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #24105 -- Called Storage.get_valid_name() when upload_to is callable

This commit is contained in:
Abhaya Agarwal
2015-05-03 09:40:24 +05:30
committed by Tim Graham
parent 7c7b855106
commit 9de9c24017
5 changed files with 39 additions and 6 deletions

View File

@@ -25,6 +25,12 @@ class OldStyleFSStorage(FileSystemStorage):
return super(OldStyleFSStorage, self).save(name, content)
class CustomValidNameStorage(FileSystemStorage):
def get_valid_name(self, name):
# mark the name to show that this was called
return name + '_valid'
temp_storage_location = tempfile.mkdtemp()
temp_storage = FileSystemStorage(location=temp_storage_location)
@@ -41,6 +47,10 @@ class Storage(models.Model):
normal = models.FileField(storage=temp_storage, upload_to='tests')
custom = models.FileField(storage=temp_storage, upload_to=custom_upload_to)
random = models.FileField(storage=temp_storage, upload_to=random_upload_to)
custom_valid_name = models.FileField(
storage=CustomValidNameStorage(location=temp_storage_location),
upload_to=random_upload_to,
)
default = models.FileField(storage=temp_storage, upload_to='tests', default='tests/default.txt')
empty = models.FileField(storage=temp_storage)
limited_length = models.FileField(storage=temp_storage, upload_to='tests', max_length=20)