本文整理匯總了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
示例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)
示例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]
示例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,
)
示例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()
示例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
示例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')
示例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')
示例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')
示例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')
示例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')
示例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())
示例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__=[]))
示例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']))
示例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')