當前位置: 首頁>>代碼示例>>Python>>正文


Python apps.get_app_configs方法代碼示例

本文整理匯總了Python中django.apps.apps.get_app_configs方法的典型用法代碼示例。如果您正苦於以下問題:Python apps.get_app_configs方法的具體用法?Python apps.get_app_configs怎麽用?Python apps.get_app_configs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.apps.apps的用法示例。


在下文中一共展示了apps.get_app_configs方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: discover_extensions

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import get_app_configs [as 別名]
def discover_extensions(self):
        """Discover available extensions."""
        if self._discovery_done:
            return

        try:
            previous_state = self._extensions.copy()

            for app_config in apps.get_app_configs():
                indexes_path = "{}.extensions".format(app_config.name)
                try:
                    import_module(indexes_path)
                except ImportError:
                    pass

            self._discovery_done = True
        except Exception:
            # Rollback state to prevent corrupted state on exceptions during import.
            self._extensions = previous_state
            raise 
開發者ID:genialis,項目名稱:resolwe,代碼行數:22,代碼來源:composer.py

示例2: get_apps_tools

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import get_app_configs [as 別名]
def get_apps_tools():
    """Get applications' tools and their paths.

    Return a dict with application names as keys and paths to tools'
    directories as values. Applications without tools are omitted.
    """
    tools_paths = {}

    for app_config in apps.get_app_configs():
        proc_path = os.path.join(app_config.path, "tools")
        if os.path.isdir(proc_path):
            tools_paths[app_config.name] = proc_path

    custom_tools_paths = getattr(settings, "RESOLWE_CUSTOM_TOOLS_PATHS", [])
    if not isinstance(custom_tools_paths, list):
        raise KeyError("`RESOLWE_CUSTOM_TOOLS_PATHS` setting must be a list.")

    for seq, custom_path in enumerate(custom_tools_paths):
        custom_key = "_custom_{}".format(seq)
        tools_paths[custom_key] = custom_path

    return tools_paths 
開發者ID:genialis,項目名稱:resolwe,代碼行數:24,代碼來源:__init__.py

示例3: sequence_list

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import get_app_configs [as 別名]
def sequence_list(self):
        "Returns a list of information about all DB sequences for all models in all apps."
        from django.apps import apps
        from django.db import models, router

        sequence_list = []

        for app_config in apps.get_app_configs():
            for model in router.get_migratable_models(app_config, self.connection.alias):
                if not model._meta.managed:
                    continue
                if model._meta.swapped:
                    continue
                for f in model._meta.local_fields:
                    if isinstance(f, models.AutoField):
                        sequence_list.append({'table': model._meta.db_table, 'column': f.column})
                        break  # Only one AutoField is allowed per model, so don't bother continuing.

                for f in model._meta.local_many_to_many:
                    # If this is an m2m using an intermediate table,
                    # we don't need to reset the sequence.
                    if f.rel.through is None:
                        sequence_list.append({'table': f.m2m_db_table(), 'column': None})

        return sequence_list 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:27,代碼來源:introspection.py

示例4: get_app_template_dirs

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import get_app_configs [as 別名]
def get_app_template_dirs(dirname):
    """
    Return an iterable of paths of directories to load app templates from.

    dirname is the name of the subdirectory containing templates inside
    installed applications.
    """
    template_dirs = []
    for app_config in apps.get_app_configs():
        if not app_config.path:
            continue
        template_dir = os.path.join(app_config.path, dirname)
        if os.path.isdir(template_dir):
            template_dirs.append(upath(template_dir))
    # Immutable return value because it will be cached and shared by callers.
    return tuple(template_dirs) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:18,代碼來源:utils.py

示例5: get_templatetags_modules

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import get_app_configs [as 別名]
def get_templatetags_modules():
    """
    Return the list of all available template tag modules.

    Caches the result for faster access.
    """
    templatetags_modules_candidates = ['django.templatetags']
    templatetags_modules_candidates.extend(
        '%s.templatetags' % app_config.name
        for app_config in apps.get_app_configs())

    templatetags_modules = []
    for templatetag_module in templatetags_modules_candidates:
        try:
            import_module(templatetag_module)
        except ImportError:
            continue
        else:
            templatetags_modules.append(templatetag_module)
    return templatetags_modules 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:22,代碼來源:base.py

示例6: load_template_source

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import get_app_configs [as 別名]
def load_template_source(self, template_name, template_dirs=None):
        """
        Loads templates from Python eggs via pkg_resource.resource_string.

        For every installed app, it tries to get the resource (app, template_name).
        """
        if resource_string is not None:
            pkg_name = 'templates/' + template_name
            for app_config in apps.get_app_configs():
                try:
                    resource = resource_string(app_config.name, pkg_name)
                except Exception:
                    continue
                if six.PY2:
                    resource = resource.decode(self.engine.file_charset)
                return (resource, 'egg:%s:%s' % (app_config.name, pkg_name))
        raise TemplateDoesNotExist(template_name) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:19,代碼來源:eggs.py

示例7: __init__

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import get_app_configs [as 別名]
def __init__(self, app_names=None, *args, **kwargs):
        # The list of apps that are handled
        self.apps = []
        # Mapping of app names to storage instances
        self.storages = OrderedDict()
        app_configs = apps.get_app_configs()
        if app_names:
            app_names = set(app_names)
            app_configs = [ac for ac in app_configs if ac.name in app_names]
        for app_config in app_configs:
            app_storage = self.storage_class(
                os.path.join(app_config.path, self.source_dir))
            if os.path.isdir(app_storage.location):
                self.storages[app_config.name] = app_storage
                if app_config.name not in self.apps:
                    self.apps.append(app_config.name)
        super(AppDirectoriesFinder, self).__init__(*args, **kwargs) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:19,代碼來源:finders.py

示例8: emit_pre_migrate_signal

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import get_app_configs [as 別名]
def emit_pre_migrate_signal(create_models, verbosity, interactive, db):
    # Emit the pre_migrate signal for every application.
    for app_config in apps.get_app_configs():
        if app_config.models_module is None:
            continue
        if verbosity >= 2:
            print("Running pre-migrate handlers for application %s" % app_config.label)
        models.signals.pre_migrate.send(
            sender=app_config,
            app_config=app_config,
            verbosity=verbosity,
            interactive=interactive,
            using=db)
        # For backwards-compatibility -- remove in Django 1.9.
        models.signals.pre_syncdb.send(
            sender=app_config.models_module,
            app=app_config.models_module,
            create_models=create_models,
            verbosity=verbosity,
            interactive=interactive,
            db=db) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:23,代碼來源:sql.py

示例9: emit_post_migrate_signal

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import get_app_configs [as 別名]
def emit_post_migrate_signal(created_models, verbosity, interactive, db):
    # Emit the post_migrate signal for every application.
    for app_config in apps.get_app_configs():
        if app_config.models_module is None:
            continue
        if verbosity >= 2:
            print("Running post-migrate handlers for application %s" % app_config.label)
        models.signals.post_migrate.send(
            sender=app_config,
            app_config=app_config,
            verbosity=verbosity,
            interactive=interactive,
            using=db)
        # For backwards-compatibility -- remove in Django 1.9.
        models.signals.post_syncdb.send(
            sender=app_config.models_module,
            app=app_config.models_module,
            created_models=created_models,
            verbosity=verbosity,
            interactive=interactive,
            db=db) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:23,代碼來源:sql.py

示例10: sequence_list

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import get_app_configs [as 別名]
def sequence_list(self):
        """
        Return a list of information about all DB sequences for all models in
        all apps.
        """
        from django.apps import apps
        from django.db import router

        sequence_list = []
        cursor = self.connection.cursor()

        for app_config in apps.get_app_configs():
            for model in router.get_migratable_models(app_config, self.connection.alias):
                if not model._meta.managed:
                    continue
                if model._meta.swapped:
                    continue
                sequence_list.extend(self.get_sequences(cursor, model._meta.db_table, model._meta.local_fields))
                for f in model._meta.local_many_to_many:
                    # If this is an m2m using an intermediate table,
                    # we don't need to reset the sequence.
                    if f.remote_field.through is None:
                        sequence = self.get_sequences(cursor, f.m2m_db_table())
                        sequence_list.extend(sequence if sequence else [{'table': f.m2m_db_table(), 'column': None}])
        return sequence_list 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:27,代碼來源:introspection.py

示例11: get_app_template_dirs

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import get_app_configs [as 別名]
def get_app_template_dirs(dirname):
    """
    Return an iterable of paths of directories to load app templates from.

    dirname is the name of the subdirectory containing templates inside
    installed applications.
    """
    template_dirs = []
    for app_config in apps.get_app_configs():
        if not app_config.path:
            continue
        template_dir = os.path.join(app_config.path, dirname)
        if os.path.isdir(template_dir):
            template_dirs.append(template_dir)
    # Immutable return value because it will be cached and shared by callers.
    return tuple(template_dirs) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:18,代碼來源:utils.py

示例12: get_installed_libraries

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import get_app_configs [as 別名]
def get_installed_libraries():
    """
    Return the built-in template tag libraries and those from installed
    applications. Libraries are stored in a dictionary where keys are the
    individual module names, not the full module paths. Example:
    django.templatetags.i18n is stored as i18n.
    """
    libraries = {}
    candidates = ['django.templatetags']
    candidates.extend(
        '%s.templatetags' % app_config.name
        for app_config in apps.get_app_configs())

    for candidate in candidates:
        try:
            pkg = import_module(candidate)
        except ImportError:
            # No templatetags package defined. This is safe to ignore.
            continue

        if hasattr(pkg, '__path__'):
            for name in get_package_libraries(pkg):
                libraries[name[len(candidate) + 1:]] = name

    return libraries 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:27,代碼來源:django.py

示例13: __init__

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import get_app_configs [as 別名]
def __init__(self, app_names=None, *args, **kwargs):
        # The list of apps that are handled
        self.apps = []
        # Mapping of app names to storage instances
        self.storages = OrderedDict()
        app_configs = apps.get_app_configs()
        if app_names:
            app_names = set(app_names)
            app_configs = [ac for ac in app_configs if ac.name in app_names]
        for app_config in app_configs:
            app_storage = self.storage_class(
                os.path.join(app_config.path, self.source_dir))
            if os.path.isdir(app_storage.location):
                self.storages[app_config.name] = app_storage
                if app_config.name not in self.apps:
                    self.apps.append(app_config.name)
        super().__init__(*args, **kwargs) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:19,代碼來源:finders.py

示例14: get_config_context

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import get_app_configs [as 別名]
def get_config_context():
    from django.apps import apps
    import importlib
    from app.db_manager.config_manager import get_config_by_name

    result = {}

    for app in apps.get_app_configs():
        deeru_config = getattr(app, 'deeru_config_context', None)
        if deeru_config:
            deeru_config = deeru_config.split('.')
            module_name = '.'.join(deeru_config[:-1])
            consts = importlib.import_module(module_name)
            app_config = getattr(consts, deeru_config[-1], {})
            for k, v in app_config.items():
                config = get_config_by_name(v)
                if config:
                    result[k] = config.v2_real_config
    return result 
開發者ID:gojuukaze,項目名稱:DeerU,代碼行數:21,代碼來源:__init__.py

示例15: get_installed_apps

# 需要導入模塊: from django.apps import apps [as 別名]
# 或者: from django.apps.apps import get_app_configs [as 別名]
def get_installed_apps():
    """
    Return list of all installed apps
    """
    if django.VERSION >= (1, 7):
        from django.apps import apps

        return [
            a.models_module
            for a in apps.get_app_configs()
            if a.models_module is not None
        ]
    else:
        from django.db import models

        return models.get_apps() 
開發者ID:r4fek,項目名稱:django-cassandra-engine,代碼行數:18,代碼來源:utils.py


注:本文中的django.apps.apps.get_app_configs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。