当前位置: 首页>>代码示例>>Python>>正文


Python apps.AppConfig方法代码示例

本文整理汇总了Python中django.apps.AppConfig方法的典型用法代码示例。如果您正苦于以下问题:Python apps.AppConfig方法的具体用法?Python apps.AppConfig怎么用?Python apps.AppConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.apps的用法示例。


在下文中一共展示了apps.AppConfig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_app_config_class

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import AppConfig [as 别名]
def get_app_config_class(path):
    """
    Return a subclass of AppConfig to configure the app
    :param path: the path to the apps.py file, can be accessed as __file__
    :return: a subclass of AppConfig that configures the given app
    """

    file_path = os.path.abspath(path)
    app_directory = os.path.dirname(file_path)
    app_directory_name = os.path.basename(app_directory)
    conf = settings.DISCOVERY.get_app_configuration(app_directory_name)

    class Config(AppConfig):
        name = app_directory_name
        label = conf.nomenclature.name
        verbose_name = conf.nomenclature.verbose_name
        configuration = conf

    return Config 
开发者ID:IMGIITRoorkee,项目名称:omniport-backend,代码行数:21,代码来源:app_config_class.py

示例2: index_adjustments

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import AppConfig [as 别名]
def index_adjustments(sender, using=None, **kwargs):
    """
    Remove -like indexes (varchar_pattern_ops) on UUID fields and create
    version-unique indexes for models that have a VERSION_UNIQUE attribute.
    :param AppConfig sender:
    :param str sender: database alias
    :param kwargs:
    """
    from versions.util.postgresql import (
        remove_uuid_id_like_indexes,
        create_current_version_unique_indexes,
        create_current_version_unique_identity_indexes
    )
    remove_uuid_id_like_indexes(sender.name, using)
    create_current_version_unique_indexes(sender.name, using)
    create_current_version_unique_identity_indexes(sender.name, using) 
开发者ID:swisscom,项目名称:cleanerversion,代码行数:18,代码来源:apps.py

示例3: define_fake_app

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import AppConfig [as 别名]
def define_fake_app():
    """Creates and registers a fake Django app."""

    name = str(uuid.uuid4()).replace("-", "")[:8] + "-app"

    app_config_cls = type(
        name + "Config",
        (AppConfig,),
        {"name": name, "path": os.path.dirname(__file__)},
    )

    app_config = app_config_cls(name, "")
    app_config.apps = apps
    app_config.models = {}

    apps.app_configs[name] = app_config
    sys.modules[name] = {}

    try:
        yield app_config
    finally:
        del apps.app_configs[name]
        del sys.modules[name] 
开发者ID:SectorLabs,项目名称:django-postgres-extra,代码行数:25,代码来源:fake_model.py

示例4: _create_app

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import AppConfig [as 别名]
def _create_app(stack):
    parent_module = sys.modules[stack[1][0].f_locals['__name__']]
    parent_module_dir = os.path.dirname(os.path.abspath(parent_module.__file__))

    # use parent directory of application as import root
    sys.path[0] = os.path.dirname(parent_module_dir)

    app_module = os.path.basename(parent_module_dir)
    entrypoint = '{}.{}'.format(app_module, os.path.basename(parent_module.__file__).split('.')[0])

    # allow relative import from app.py
    parent_module.__package__ = app_module
    import_module(app_module)

    # allow recursive import app.py
    if parent_module.__name__ != app_module:
        sys.modules[entrypoint] = parent_module

    class MicroAppConfig(AppConfig):
        module = app_module
        label = app_module
        name = app_module

        def import_models(self):
            super().import_models()
            if self.models_module is None:
                self.models_module = parent_module

    globals().update(
        _app_config=MicroAppConfig,
        _parent_module=parent_module,
    ) 
开发者ID:zenwalker,项目名称:django-micro,代码行数:34,代码来源:django_micro.py

示例5: flush_cache

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import AppConfig [as 别名]
def flush_cache(sender: AppConfig, **kwargs: Any) -> None:
    logging.info("Clearing memcached cache after migrations")
    cache.clear() 
开发者ID:zulip,项目名称:zulip,代码行数:5,代码来源:apps.py

示例6: test_not_an_app_config

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import AppConfig [as 别名]
def test_not_an_app_config(self):
        """
        Tests when INSTALLED_APPS contains a class that isn't an app config.
        """
        msg = "'apps.apps.NotAConfig' isn't a subclass of AppConfig."
        with self.assertRaisesMessage(ImproperlyConfigured, msg):
            with self.settings(INSTALLED_APPS=['apps.apps.NotAConfig']):
                pass 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py

示例7: test_path_set_explicitly

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import AppConfig [as 别名]
def test_path_set_explicitly(self):
        """If subclass sets path as class attr, no module attributes needed."""
        class MyAppConfig(AppConfig):
            path = 'foo'

        ac = MyAppConfig('label', Stub())

        self.assertEqual(ac.path, 'foo') 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py

示例8: test_explicit_path_overrides

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import AppConfig [as 别名]
def test_explicit_path_overrides(self):
        """If path set as class attr, overrides __path__ and __file__."""
        class MyAppConfig(AppConfig):
            path = 'foo'

        ac = MyAppConfig('label', Stub(__path__=['a'], __file__='b/__init__.py'))

        self.assertEqual(ac.path, 'foo') 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py

示例9: test_dunder_path

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import AppConfig [as 别名]
def test_dunder_path(self):
        """If single element in __path__, use it (in preference to __file__)."""
        ac = AppConfig('label', Stub(__path__=['a'], __file__='b/__init__.py'))

        self.assertEqual(ac.path, 'a') 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:tests.py

示例10: test_no_dunder_path_fallback_to_dunder_file

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import AppConfig [as 别名]
def test_no_dunder_path_fallback_to_dunder_file(self):
        """If there is no __path__ attr, use __file__."""
        ac = AppConfig('label', Stub(__file__='b/__init__.py'))

        self.assertEqual(ac.path, 'b') 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:tests.py

示例11: test_multiple_dunder_path_fallback_to_dunder_file

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import AppConfig [as 别名]
def test_multiple_dunder_path_fallback_to_dunder_file(self):
        """If the __path__ attr is length>1, use __file__ if set."""
        ac = AppConfig('label', Stub(__path__=['a', 'b'], __file__='c/__init__.py'))

        self.assertEqual(ac.path, 'c') 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:tests.py

示例12: test_no_dunder_path_or_dunder_file

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import AppConfig [as 别名]
def test_no_dunder_path_or_dunder_file(self):
        """If there is no __path__ or __file__, raise ImproperlyConfigured."""
        with self.assertRaises(ImproperlyConfigured):
            AppConfig('label', Stub()) 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:tests.py

示例13: test_empty_dunder_path_no_dunder_file

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import AppConfig [as 别名]
def test_empty_dunder_path_no_dunder_file(self):
        """If the __path__ attr is empty and there is no __file__, raise."""
        with self.assertRaises(ImproperlyConfigured):
            AppConfig('label', Stub(__path__=[])) 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:tests.py

示例14: test_multiple_dunder_path_no_dunder_file

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import AppConfig [as 别名]
def test_multiple_dunder_path_no_dunder_file(self):
        """If the __path__ attr is length>1 and there is no __file__, raise."""
        with self.assertRaises(ImproperlyConfigured):
            AppConfig('label', Stub(__path__=['a', 'b'])) 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:tests.py

示例15: test_duplicate_dunder_path_no_dunder_file

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import AppConfig [as 别名]
def test_duplicate_dunder_path_no_dunder_file(self):
        """
        If the __path__ attr contains duplicate paths and there is no
        __file__, they duplicates should be deduplicated (#25246).
        """
        ac = AppConfig('label', Stub(__path__=['a', 'a']))
        self.assertEqual(ac.path, 'a') 
开发者ID:nesdis,项目名称:djongo,代码行数:9,代码来源:tests.py


注:本文中的django.apps.AppConfig方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。