Commits

David Jean Louis committed b750d9a

throw a meaningful exception if custom classes cannot be imported

Comments (0)

Files changed (2)

admin_tools/dashboard/utils.py

 
 from django.conf import settings
 from django.contrib import admin
+from django.core.exceptions import ImproperlyConfigured
 from django.core.urlresolvers import reverse
 from django.http import HttpRequest
 from django.utils.importlib import import_module
     """
     dashboard_cls = getattr(settings, 'ADMIN_TOOLS_INDEX_DASHBOARD', False)
     if dashboard_cls:
-        mod, inst = dashboard_cls.rsplit('.', 1)
-        mod = import_module(mod)
-        return getattr(mod, inst)()
+        try:
+            mod, inst = dashboard_cls.rsplit('.', 1)
+            mod = import_module(mod)
+            return getattr(mod, inst)()
+        except:
+            raise ImproperlyConfigured((
+                'The class pointed by your ADMIN_TOOLS_INDEX_DASHBOARD '
+                'setting variable cannot be imported'
+            ))
     return DefaultIndexDashboard()
 
 
     # try to discover a general app_index dashboard
     dashboard_cls = getattr(settings, 'ADMIN_TOOLS_APP_INDEX_DASHBOARD', False)
     if dashboard_cls:
-        mod, inst = dashboard_cls.rsplit('.', 1)
-        mod = import_module(mod)
-        return getattr(mod, inst)(app_title, model_list)
+        try:
+            mod, inst = dashboard_cls.rsplit('.', 1)
+            mod = import_module(mod)
+            return getattr(mod, inst)(app_title, model_list)
+        except:
+            raise ImproperlyConfigured((
+                'The class pointed by your ADMIN_TOOLS_APP_INDEX_DASHBOARD '
+                'setting variable cannot be imported'
+            ))
 
     # fallback to default dashboard
     return DefaultAppIndexDashboard(app_title, model_list)

admin_tools/menu/utils.py

 """
 
 from django.conf import settings
+from django.core.exceptions import ImproperlyConfigured
 from django.core.urlresolvers import reverse
 from django.utils.translation import ugettext_lazy as _
 from django.utils.importlib import import_module
     """
     menu_cls = getattr(settings, 'ADMIN_TOOLS_MENU', False)
     if menu_cls:
-        mod, inst = menu_cls.rsplit('.', 1)
-        mod = import_module(mod)
-        return getattr(mod, inst)()
+        try:
+            mod, inst = menu_cls.rsplit('.', 1)
+            mod = import_module(mod)
+            return getattr(mod, inst)()
+        except:
+            raise ImproperlyConfigured((
+                'The class pointed by your ADMIN_TOOLS_MENU setting variable '
+                'cannot be imported'
+            ))
 
     admin_menu = Menu()
     admin_menu.append(MenuItem(