Skip to content

Commit e73b360

Browse files
fix django 1.9 deprecation warning
1 parent 6a081c9 commit e73b360

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

encode/encoders.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import logging
1212
import subprocess
1313

14-
from django.utils.module_loading import import_by_path
14+
try:
15+
from django.utils.module_loading import import_string
16+
except ImportError:
17+
from django.utils.module_loading import import_by_path as import_string
1518

1619
from converter.ffmpeg import FFMpeg, FFMpegError, FFMpegConvertError
1720

@@ -37,7 +40,7 @@ def get_encoder_class(import_path=None):
3740
:returns: The encoder class.
3841
:rtype: class
3942
"""
40-
return import_by_path(import_path or settings.ENCODE_DEFAULT_ENCODER_CLASS)
43+
return import_string(import_path or settings.ENCODE_DEFAULT_ENCODER_CLASS)
4144

4245

4346
class BaseEncoder(object):

encode/tests/test_encoders.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ def test_none(self):
4040
"""
4141
Retrieving a non-existing class raises an exception.
4242
"""
43-
self.assertRaises(ImproperlyConfigured, encoders.get_encoder_class,
44-
'does.not.Exist')
43+
module_path = 'does.not.Exist'
44+
try:
45+
# django >= 1.7
46+
from django.utils.module_loading import import_string
47+
exception = ImportError
48+
except:
49+
exception = ImproperlyConfigured
50+
self.assertRaises(exception, encoders.get_encoder_class, module_path)
4551

4652

4753
class BasicEncoderTestCase(WebTest, DummyDataMixin):

0 commit comments

Comments
 (0)