From dc4fc73901f78ef818f1733f14098f6f6cc88887 Mon Sep 17 00:00:00 2001 From: Raffaele Salmaso Date: Thu, 22 Feb 2018 07:00:32 +0100 Subject: [PATCH] Use django import_string instead of get_class_from_str --- src/wiki/core/utils.py | 10 ---------- src/wiki/urls.py | 8 ++++---- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/wiki/core/utils.py b/src/wiki/core/utils.py index 2f8b7962..957701e6 100644 --- a/src/wiki/core/utils.py +++ b/src/wiki/core/utils.py @@ -1,16 +1,6 @@ -from importlib import import_module - from django.http.response import JsonResponse -def get_class_from_str(class_path): - """Dynamically load a View class from a string path - "myapp.views.MyView" -- used for dynamic settings""" - module_path, klass_name = class_path.rsplit('.', 1) - module = import_module(module_path) - return getattr(module, klass_name) - - def object_to_json_response(obj, status=200): """ Given an object, returns an HttpResponse object with a JSON serialized diff --git a/src/wiki/urls.py b/src/wiki/urls.py index 8d257c42..65340337 100644 --- a/src/wiki/urls.py +++ b/src/wiki/urls.py @@ -1,8 +1,8 @@ +from django.utils.module_loading import import_string from wiki.compat import include, url from wiki.conf import settings from wiki.core.plugins import registry from wiki.core.plugins.loader import load_wiki_plugins -from wiki.core.utils import get_class_from_str from wiki.views import accounts, article, deleted_list @@ -70,7 +70,7 @@ class WikiURLPatterns: article.MissingRootView.as_view(), name='root_missing'), url(r'^_search/$', - get_class_from_str(self.search_view_class).as_view(), + import_string(self.search_view_class).as_view(), name='search'), url(r'^_revision/diff/(?P[0-9]+)/$', self.article_diff_view_class.as_view(), @@ -198,7 +198,7 @@ class WikiURLPatterns: self.article_dir_view_class.as_view(), name='dir'), url(r'^(?P.+/|)_search/$', - get_class_from_str(self.search_view_class).as_view(), + import_string(self.search_view_class).as_view(), name='search'), url(r'^(?P.+/|)_settings/$', self.article_settings_view_class.as_view(), @@ -255,7 +255,7 @@ def get_pattern(app_name="wiki", namespace="wiki", url_config_class=None): if url_config_classname is None: url_config_class = WikiURLPatterns else: - url_config_class = get_class_from_str(url_config_classname) + url_config_class = import_string(url_config_classname) urlpatterns = url_config_class().get_urls() return urlpatterns, app_name, namespace -- 2.45.2