﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26382	Better decouple Storage and FileField	Cristiano Coelho	nobody	"Hello, following this: https://groups.google.com/forum/#!topic/django-developers/CjoPZq8lZms

It seems like the Storage and FileField classes are doing too much work that should be actually be delegated to the storage implementation, making it currently a bit more complicated to implement custom storages since the base Storage and FileField classes perform some os dependent work and based on assumptions like files should be always be saved with forward slashes or os dependant semantics like folders and paths.

In particular, the methods get_directory_name, get_filename and generate_file_name from FileField (https://github.com/django/django/blob/master/django/db/models/fields/files.py#L297) and the method save from Storage (https://github.com/django/django/blob/master/django/core/files/storage.py#L57) should be changed a bit so they delegate their work to the actual storage system.

Finally for Storage.save, the below line should be moved to the ._save method of FileSystemStorage 

{{{
# Store filenames with forward slashes, even on Windows
return force_text(name.replace('\\', '/'))
}}}

I would move get_directory_name, get_filename and generate_file_name to the Storage class, however those methods also rely on the actual instance and upload_to value or callable and having those parameters sent to the storage class might not be a good idea. I'm not sure what would be the best way to remove any 'os.path' usage of FileField into the actual storage class without breaking everything.
"	Cleanup/optimization	closed	File uploads/storage	1.9	Normal	duplicate	storage filefield	Cristiano Coelho	Accepted	1	0	0	1	0	0
