Refs #26058 -- Removed deprecated FileField.get_directory_name()/get_filename().
This commit is contained in:
parent
58d3d14aea
commit
0dfc5479a8
|
@ -1,7 +1,5 @@
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
|
||||||
import posixpath
|
import posixpath
|
||||||
import warnings
|
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core import checks
|
from django.core import checks
|
||||||
|
@ -12,7 +10,6 @@ from django.core.validators import validate_image_file_extension
|
||||||
from django.db.models import signals
|
from django.db.models import signals
|
||||||
from django.db.models.fields import Field
|
from django.db.models.fields import Field
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils.deprecation import RemovedInDjango20Warning
|
|
||||||
from django.utils.encoding import force_str, force_text
|
from django.utils.encoding import force_str, force_text
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
@ -301,22 +298,6 @@ class FileField(Field):
|
||||||
super(FileField, self).contribute_to_class(cls, name, **kwargs)
|
super(FileField, self).contribute_to_class(cls, name, **kwargs)
|
||||||
setattr(cls, self.name, self.descriptor_class(self))
|
setattr(cls, self.name, self.descriptor_class(self))
|
||||||
|
|
||||||
def get_directory_name(self):
|
|
||||||
warnings.warn(
|
|
||||||
'FileField now delegates file name and folder processing to the '
|
|
||||||
'storage. get_directory_name() will be removed in Django 2.0.',
|
|
||||||
RemovedInDjango20Warning, stacklevel=2
|
|
||||||
)
|
|
||||||
return os.path.normpath(force_text(datetime.datetime.now().strftime(force_str(self.upload_to))))
|
|
||||||
|
|
||||||
def get_filename(self, filename):
|
|
||||||
warnings.warn(
|
|
||||||
'FileField now delegates file name and folder processing to the '
|
|
||||||
'storage. get_filename() will be removed in Django 2.0.',
|
|
||||||
RemovedInDjango20Warning, stacklevel=2
|
|
||||||
)
|
|
||||||
return os.path.normpath(self.storage.get_valid_name(os.path.basename(filename)))
|
|
||||||
|
|
||||||
def generate_filename(self, instance, filename):
|
def generate_filename(self, instance, filename):
|
||||||
"""
|
"""
|
||||||
Apply (if callable) or prepend (if a string) upload_to to the filename,
|
Apply (if callable) or prepend (if a string) upload_to to the filename,
|
||||||
|
|
|
@ -375,3 +375,6 @@ these features.
|
||||||
``parent_link`` is removed.
|
``parent_link`` is removed.
|
||||||
|
|
||||||
* Support for ``Widget._format_value()`` is removed.
|
* Support for ``Widget._format_value()`` is removed.
|
||||||
|
|
||||||
|
* ``FileField`` methods ``get_directory_name()`` and ``get_filename()`` are
|
||||||
|
removed.
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import os
|
import os
|
||||||
import warnings
|
|
||||||
|
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
from django.core.files.storage import Storage
|
from django.core.files.storage import Storage
|
||||||
|
@ -38,32 +37,6 @@ class AWSS3Storage(Storage):
|
||||||
|
|
||||||
class GenerateFilenameStorageTests(SimpleTestCase):
|
class GenerateFilenameStorageTests(SimpleTestCase):
|
||||||
|
|
||||||
def test_filefield_get_directory_deprecation(self):
|
|
||||||
with warnings.catch_warnings(record=True) as warns:
|
|
||||||
warnings.simplefilter('always')
|
|
||||||
f = FileField(upload_to='some/folder/')
|
|
||||||
self.assertEqual(f.get_directory_name(), os.path.normpath('some/folder/'))
|
|
||||||
|
|
||||||
self.assertEqual(len(warns), 1)
|
|
||||||
self.assertEqual(
|
|
||||||
warns[0].message.args[0],
|
|
||||||
'FileField now delegates file name and folder processing to the '
|
|
||||||
'storage. get_directory_name() will be removed in Django 2.0.'
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_filefield_get_filename_deprecation(self):
|
|
||||||
with warnings.catch_warnings(record=True) as warns:
|
|
||||||
warnings.simplefilter('always')
|
|
||||||
f = FileField(upload_to='some/folder/')
|
|
||||||
self.assertEqual(f.get_filename('some/folder/test.txt'), 'test.txt')
|
|
||||||
|
|
||||||
self.assertEqual(len(warns), 1)
|
|
||||||
self.assertEqual(
|
|
||||||
warns[0].message.args[0],
|
|
||||||
'FileField now delegates file name and folder processing to the '
|
|
||||||
'storage. get_filename() will be removed in Django 2.0.'
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_filefield_generate_filename(self):
|
def test_filefield_generate_filename(self):
|
||||||
f = FileField(upload_to='some/folder/')
|
f = FileField(upload_to='some/folder/')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
Loading…
Reference in New Issue