From c50368eb34e3cb0049886b9a75afe40724ca8fd1 Mon Sep 17 00:00:00 2001 From: Julien Delasoie Date: Thu, 12 Oct 2017 15:29:53 +0200 Subject: [PATCH] Change module discovery to use the one from Django --- authority/__init__.py | 5 +++-- authority/utils.py | 25 +------------------------ 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/authority/__init__.py b/authority/__init__.py index 87b45d3..71a6420 100644 --- a/authority/__init__.py +++ b/authority/__init__.py @@ -1,3 +1,5 @@ +from django.utils.module_loading import autodiscover_modules + LOADING = False @@ -11,5 +13,4 @@ def autodiscover(): return LOADING = True - from authority import utils - utils.autodiscover_modules() + autodiscover_modules('permissions') diff --git a/authority/utils.py b/authority/utils.py index bd8c1fc..da6e6cf 100644 --- a/authority/utils.py +++ b/authority/utils.py @@ -1,26 +1,3 @@ import sys -from authority.sites import site, get_check, get_choices_for, register, unregister # noqa - - -def autodiscover_modules(): - """ - Goes and imports the permissions submodule of every app in INSTALLED_APPS - to make sure the permission set classes are registered correctly. - """ - import imp - from django.conf import settings - - for app in settings.INSTALLED_APPS: - try: - __import__(app) - app_path = sys.modules[app].__path__ - except AttributeError: - continue - try: - imp.find_module('permissions', app_path) - except ImportError: - continue - __import__("%s.permissions" % app) - app_path = sys.modules["%s.permissions" % app] - LOADING = False +from authority.sites import site, get_check, get_choices_for, register, unregister # noqa