Python django.utils.module_loading.import_module() Examples

The following are 6 code examples of django.utils.module_loading.import_module(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.utils.module_loading , or try the search function .
Example #1
Source File: helpers.py    From django-crudbuilder with Apache License 2.0 6 votes vote down vote up
def import_crud(app):
    '''
    Import crud module and register all model cruds which it contains
    '''

    try:
        app_path = import_module(app).__path__
    except (AttributeError, ImportError):
        return None

    try:
        imp.find_module('crud', app_path)
    except ImportError:
        return None

    module = import_module("%s.crud" % app)

    return module 
Example #2
Source File: utils.py    From django-test-addons with MIT License 5 votes vote down vote up
def __init__(self, method = 'GET'):
        super(EnhancedHttpRequest, self).__init__()
        self.method = method

        session_engine = import_module(settings.SESSION_ENGINE)
        self.session = session_engine.SessionStore(session_key = None) 
Example #3
Source File: utils.py    From django-test-addons with MIT License 5 votes vote down vote up
def create_session(self):
        session_engine = import_module(settings.SESSION_ENGINE)
        store = session_engine.SessionStore()
        store.save()
        self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key 
Example #4
Source File: __init__.py    From devops with MIT License 5 votes vote down vote up
def register_builtin_plugins(site):
    from django.conf import settings
    from django.utils.module_loading import import_module

    exclude_plugins = getattr(settings, 'XADMIN_EXCLUDE_PLUGINS', [])

    try:
        import formtools
    except Exception:
        exclude_plugins.append('wizard')

    [import_module('xadmin.plugins.%s' % plugin) for plugin in PLUGINS if plugin not in exclude_plugins] 
Example #5
Source File: checks.py    From django-pgschemas with MIT License 5 votes vote down vote up
def get_session_app():
    engine = import_module(settings.SESSION_ENGINE)
    store = engine.SessionStore
    if hasattr(store, "get_model_class"):
        session_model = store.get_model_class()
        if issubclass(session_model, AbstractBaseSession):
            return session_model._meta.app_config.name
    return None 
Example #6
Source File: __init__.py    From devops with MIT License 4 votes vote down vote up
def autodiscover():
    """
    Auto-discover INSTALLED_APPS admin.py modules and fail silently when
    not present. This forces an import on them to register any admin bits they
    may want.
    """

    from django.conf import settings
    from django.utils.module_loading import module_has_submodule, import_module

    setattr(settings, 'CRISPY_TEMPLATE_PACK', 'bootstrap3')
    setattr(settings, 'CRISPY_CLASS_CONVERTERS', {
        "textinput": "textinput textInput form-control",
        "fileinput": "fileinput fileUpload form-control",
        "passwordinput": "textinput textInput form-control",
    })

    from xadmin.views import register_builtin_views
    register_builtin_views(site)

    # load xadmin settings from XADMIN_CONF module
    try:
        xadmin_conf = getattr(settings, 'XADMIN_CONF', 'xadmin_conf.py')
        conf_mod = import_module(xadmin_conf)
    except Exception:
        conf_mod = None

    if conf_mod:
        for key in dir(conf_mod):
            setting = getattr(conf_mod, key)
            try:
                if issubclass(setting, Settings):
                    site.register_settings(setting.__name__, setting)
            except Exception:
                pass

    from xadmin.plugins import register_builtin_plugins
    register_builtin_plugins(site)

    from django.apps import apps
    
    for app_config in apps.get_app_configs():
        # Attempt to import the app's admin module.
        try:
            before_import_registry = site.copy_registry()
            import_module('%s.adminx' % app_config.name)
        except:
            # Reset the model registry to the state before the last import as
            # this import will have to reoccur on the next request and this
            # could raise NotRegistered and AlreadyRegistered exceptions
            # (see #8245).
            site.restore_registry(before_import_registry)

            # Decide whether to bubble up this error. If the app just
            # doesn't have an admin module, we can ignore the error
            # attempting to import it, otherwise we want it to bubble up.
            if module_has_submodule(app_config.module, 'adminx'):
                raise