Skip to content

Commit 764c815

Browse files
committed
Stop reusing internal APIs of Django (urlresolvers.get_callable)
Remove unused code while at it.
1 parent 8fb90c2 commit 764c815

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

feincms/content/application/models.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from feincms.admin.editor import ItemEditorForm
2121
from feincms.contrib.fields import JSONField
22+
from feincms.utils import get_object
2223

2324
try:
2425
from email.utils import parsedate
@@ -238,7 +239,7 @@ def __init__(self, *args, **kwargs):
238239
if isinstance(admin_fields, dict):
239240
self.custom_fields.update(admin_fields)
240241
else:
241-
get_fields = urlresolvers.get_callable(admin_fields)
242+
get_fields = get_object(admin_fields)
242243
self.custom_fields.update(get_fields(self, *args, **kwargs))
243244

244245
for k, v in self.custom_fields.items():
@@ -285,7 +286,7 @@ def process(self, request, **kwargs):
285286
# Provide a way for appcontent items to customize URL processing by
286287
# altering the perceived path of the page:
287288
if "path_mapper" in self.app_config:
288-
path_mapper = urlresolvers.get_callable(self.app_config["path_mapper"])
289+
path_mapper = get_object(self.app_config["path_mapper"])
289290
path, page_url = path_mapper(
290291
request.path,
291292
page_url,
@@ -314,7 +315,7 @@ def process(self, request, **kwargs):
314315
view_wrapper = self.app_config.get("view_wrapper", None)
315316
if view_wrapper:
316317
fn = partial(
317-
urlresolvers.get_callable(view_wrapper),
318+
get_object(view_wrapper),
318319
view=fn,
319320
appcontent_parameters=self.parameters
320321
)

feincms/module/medialibrary/models.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from django.contrib import admin, messages
88
from django.contrib.auth.decorators import permission_required
99
from django.conf import settings as django_settings
10-
from django.core.urlresolvers import get_callable
1110
from django.db import models
1211
from django.template.defaultfilters import filesizeformat
1312
from django.utils.safestring import mark_safe
@@ -87,11 +86,6 @@ class MediaFileBase(Base, TranslatedObjectMixin):
8786
because of the (handy) extension mechanism.
8887
"""
8988

90-
from django.core.files.storage import FileSystemStorage
91-
default_storage_class = getattr(django_settings, 'DEFAULT_FILE_STORAGE',
92-
'django.core.files.storage.FileSystemStorage')
93-
default_storage = get_callable(default_storage_class)
94-
9589
file = models.FileField(_('file'), max_length=255, upload_to=settings.FEINCMS_MEDIALIBRARY_UPLOAD_TO)
9690
type = models.CharField(_('file type'), max_length=12, editable=False, choices=())
9791
created = models.DateTimeField(_('created'), editable=False, default=datetime.now)

feincms/utils/__init__.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,29 @@ class Entry(Base):
5050
{% feincms_prefill_entry_list object_list "authors,richtextcontent_set,imagecontent_set" %}
5151
"""
5252

53-
from django.core.urlresolvers import get_callable
5453
from django.db import connection
5554
from django.db.models import AutoField
5655
from django.db.models.fields import related
56+
from django.utils.importlib import import_module
5757

5858
# ------------------------------------------------------------------------
5959
def get_object(path, fail_silently=False):
60-
return get_callable(path, fail_silently)
60+
# Return early if path isn't a string (might already be an callable or
61+
# a class or whatever)
62+
if not isinstance(path, (str, unicode)):
63+
return path
64+
65+
try:
66+
dot = path.rindex('.')
67+
mod, fn = path[:dot], path[dot+1:]
68+
except ValueError:
69+
mod, fn = callback, ''
70+
71+
try:
72+
return getattr(import_module(mod), fn)
73+
except (AttributeError, ImportError):
74+
if not fail_silently:
75+
raise
6176

6277
# ------------------------------------------------------------------------
6378
def prefilled_attribute(name):

0 commit comments

Comments
 (0)