Example #1
0
 def get_panel_classes(cls):
     if cls._panel_classes is None:
         # Load panels in a temporary variable for thread safety.
         panel_classes = []
         for panel_path in dt_settings.PANELS:
             # This logic could be replaced with import_by_path in Django 1.6.
             try:
                 panel_module, panel_classname = panel_path.rsplit('.', 1)
             except ValueError:
                 raise ImproperlyConfigured(
                     "%s isn't a debug panel module" % panel_path)
             try:
                 mod = import_module(panel_module)
             except ImportError as e:
                 raise ImproperlyConfigured(
                     'Error importing debug panel %s: "%s"' %
                     (panel_module, e))
             try:
                 panel_class = getattr(mod, panel_classname)
             except AttributeError:
                 raise ImproperlyConfigured(
                     'Toolbar Panel module "%s" does not define a "%s" class'
                     % (panel_module, panel_classname))
             panel_classes.append(panel_class)
         cls._panel_classes = panel_classes
     return cls._panel_classes
Example #2
0
 def gen_app_versions_1_6(self):
     for app in list(settings.INSTALLED_APPS):
         name = app.split('.')[-1].replace('_', ' ').capitalize()
         app = import_module(app)
         version = self.get_app_version(app)
         if version:
             yield name, version
Example #3
0
 def get_panel_classes(cls):
     if cls._panel_classes is None:
         # Load panels in a temporary variable for thread safety.
         panel_classes = []
         for panel_path in dt_settings.PANELS:
             # This logic could be replaced with import_by_path in Django 1.6.
             try:
                 panel_module, panel_classname = panel_path.rsplit('.', 1)
             except ValueError:
                 raise ImproperlyConfigured(
                     "%s isn't a debug panel module" % panel_path)
             try:
                 mod = import_module(panel_module)
             except ImportError as e:
                 raise ImproperlyConfigured(
                     'Error importing debug panel %s: "%s"' %
                     (panel_module, e))
             try:
                 panel_class = getattr(mod, panel_classname)
             except AttributeError:
                 raise ImproperlyConfigured(
                     'Toolbar Panel module "%s" does not define a "%s" class' %
                     (panel_module, panel_classname))
             panel_classes.append(panel_class)
         cls._panel_classes = panel_classes
     return cls._panel_classes
Example #4
0
 def signals(self):
     signals = self.SIGNALS.copy()
     for signal in self.toolbar.config["EXTRA_SIGNALS"]:
         mod_path, signal_name = signal.rsplit(".", 1)
         signals_mod = import_module(mod_path)
         signals[signal_name] = getattr(signals_mod, signal_name)
     return signals
Example #5
0
 def signals(self):
     signals = self.SIGNALS.copy()
     for signal in self.toolbar.config['EXTRA_SIGNALS']:
         mod_path, signal_name = signal.rsplit('.', 1)
         signals_mod = import_module(mod_path)
         signals[signal_name] = getattr(signals_mod, signal_name)
     return signals
Example #6
0
def is_middleware_class(middleware_class, middleware_path):
    # This could be replaced by import_by_path in Django >= 1.6.
    try:
        mod_path, cls_name = middleware_path.rsplit(".", 1)
        mod = import_module(mod_path)
        middleware_cls = getattr(mod, cls_name)
    except (AttributeError, ImportError, ValueError):
        return
    return issubclass(middleware_cls, middleware_class)
Example #7
0
def is_middleware_class(middleware_class, middleware_path):
    # This could be replaced by import_by_path in Django >= 1.6.
    try:
        mod_path, cls_name = middleware_path.rsplit('.', 1)
        mod = import_module(mod_path)
        middleware_cls = getattr(mod, cls_name)
    except (AttributeError, ImportError, ValueError):
        return
    return issubclass(middleware_cls, middleware_class)
Example #8
0
 def __init__(self):
     # If SHOW_TOOLBAR_CALLBACK is a string, which is the recommended
     # setup, resolve it to the corresponding callable.
     func_or_path = dt_settings.CONFIG['SHOW_TOOLBAR_CALLBACK']
     if isinstance(func_or_path, six.string_types):
         # Replace this with import_by_path in Django >= 1.6.
         mod_path, func_name = func_or_path.rsplit('.', 1)
         self.show_toolbar = getattr(import_module(mod_path), func_name)
     else:
         self.show_toolbar = func_or_path
 def __init__(self):
     # If SHOW_TOOLBAR_CALLBACK is a string, which is the recommended
     # setup, resolve it to the corresponding callable.
     func_or_path = dt_settings.CONFIG['SHOW_TOOLBAR_CALLBACK']
     if isinstance(func_or_path, six.string_types):
         # Replace this with import_by_path in Django >= 1.6.
         mod_path, func_name = func_or_path.rsplit('.', 1)
         self.show_toolbar = getattr(import_module(mod_path), func_name)
     else:
         self.show_toolbar = func_or_path
Example #10
0
File: utils.py Project: zvrr/sentry
def get_module_path(module_name):
    try:
        module = import_module(module_name)
    except ImportError as e:
        raise ImproperlyConfigured("Error importing HIDE_IN_STACKTRACES: %s" % (e,))
    else:
        source_path = inspect.getsourcefile(module)
        if source_path.endswith("__init__.py"):
            source_path = os.path.dirname(source_path)
        return os.path.realpath(source_path)
Example #11
0
def get_module_path(module_name):
    try:
        module = import_module(module_name)
    except ImportError as e:
        raise ImproperlyConfigured('Error importing HIDE_IN_STACKTRACES: %s' % (e, ))
    else:
        source_path = inspect.getsourcefile(module)
        if source_path.endswith('__init__.py'):
            source_path = os.path.dirname(source_path)
        return os.path.realpath(source_path)
Example #12
0
def patch_root_urlconf():
    from django.conf.urls import include, url
    from django.core.urlresolvers import clear_url_caches, reverse, NoReverseMatch
    import debug_toolbar
    try:
        reverse('djdt:render_panel')
    except NoReverseMatch:
        urlconf_module = import_module(settings.ROOT_URLCONF)
        urlconf_module.urlpatterns = [
            url(r'^__debug__/', include(debug_toolbar.urls)),
        ] + urlconf_module.urlpatterns
        clear_url_caches()
Example #13
0
def patch_root_urlconf():
    from django.conf.urls import include, url
    from django.core.urlresolvers import clear_url_caches, reverse, NoReverseMatch
    import debug_toolbar
    try:
        reverse('djdt:render_panel')
    except NoReverseMatch:
        urlconf_module = import_module(settings.ROOT_URLCONF)
        urlconf_module.urlpatterns = [
            url(r'^__debug__/', include(debug_toolbar.urls)),
        ] + urlconf_module.urlpatterns
        clear_url_caches()
Example #14
0
    def signals(self):
        signals = self.SIGNALS.copy()

        if post_syncdb is not None:
            signals['post_syncdb'] = post_syncdb

        if post_migrate is not None:
            signals['post_migrate'] = post_migrate

        for signal in self.toolbar.config['EXTRA_SIGNALS']:
            mod_path, signal_name = signal.rsplit('.', 1)
            signals_mod = import_module(mod_path)
            signals[signal_name] = getattr(signals_mod, signal_name)
        return signals