本文整理匯總了Python中django.core.exceptions.AppRegistryNotReady方法的典型用法代碼示例。如果您正苦於以下問題:Python exceptions.AppRegistryNotReady方法的具體用法?Python exceptions.AppRegistryNotReady怎麽用?Python exceptions.AppRegistryNotReady使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.core.exceptions
的用法示例。
在下文中一共展示了exceptions.AppRegistryNotReady方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: set_installed_apps
# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import AppRegistryNotReady [as 別名]
def set_installed_apps(self, installed):
"""
Enables a different set of installed apps for get_app_config[s].
installed must be an iterable in the same format as INSTALLED_APPS.
set_installed_apps() must be balanced with unset_installed_apps(),
even if it exits with an exception.
Primarily used as a receiver of the setting_changed signal in tests.
This method may trigger new imports, which may add new models to the
registry of all imported models. They will stay in the registry even
after unset_installed_apps(). Since it isn't possible to replay
imports safely (eg. that could lead to registering listeners twice),
models are registered when they're imported and never removed.
"""
if not self.ready:
raise AppRegistryNotReady("App registry isn't ready yet.")
self.stored_app_configs.append(self.app_configs)
self.app_configs = OrderedDict()
self.apps_ready = self.models_ready = self.ready = False
self.clear_cache()
self.populate(installed)
示例2: hydrate_models_and_permissions
# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import AppRegistryNotReady [as 別名]
def hydrate_models_and_permissions(app_config):
"""
Setup content types, base permissions and data source
specific permission groups for use in the admin.
"""
try:
create_contenttypes(app_config, interactive=False, verbosity=4)
except OperationalError as e:
logger.error("Error creating content-types: %s" % e)
try:
create_permissions(app_config, interactive=False, verbosity=4)
except OperationalError as e:
logger.error("Error creating permissions: %s" % e)
try:
build_permission_groups(app_config.name)
except (OperationalError, AppRegistryNotReady) as e:
logger.error("Error creating permission groups: %s" % e)
try:
build_tag_permission_group()
except (OperationalError, AppRegistryNotReady) as e:
logger.error("Error creating tagging perm group: %s" % e)
示例3: _add_installed_apps_translations
# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import AppRegistryNotReady [as 別名]
def _add_installed_apps_translations(self):
"""Merges translations from each installed app."""
try:
app_configs = reversed(list(apps.get_app_configs()))
except AppRegistryNotReady:
raise AppRegistryNotReady(
"The translation infrastructure cannot be initialized before the "
"apps registry is ready. Check that you don't make non-lazy "
"gettext calls at import time.")
for app_config in app_configs:
localedir = os.path.join(app_config.path, 'locale')
translation = self._new_gnu_trans(localedir)
self.merge(translation)
示例4: check_apps_ready
# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import AppRegistryNotReady [as 別名]
def check_apps_ready(self):
"""
Raises an exception if all apps haven't been imported yet.
"""
if not self.apps_ready:
raise AppRegistryNotReady("Apps aren't loaded yet.")
示例5: check_models_ready
# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import AppRegistryNotReady [as 別名]
def check_models_ready(self):
"""
Raises an exception if all models haven't been imported yet.
"""
if not self.models_ready:
raise AppRegistryNotReady("Models aren't loaded yet.")
示例6: check_models_ready
# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import AppRegistryNotReady [as 別名]
def check_models_ready(self):
"""
Raises an exception if models haven't been imported yet.
"""
if self.models is None:
raise AppRegistryNotReady(
"Models for app '%s' haven't been imported yet." % self.label)
示例7: _add_installed_apps_translations
# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import AppRegistryNotReady [as 別名]
def _add_installed_apps_translations(self):
"""Merge translations from each installed app."""
try:
app_configs = reversed(list(apps.get_app_configs()))
except AppRegistryNotReady:
raise AppRegistryNotReady(
"The translation infrastructure cannot be initialized before the "
"apps registry is ready. Check that you don't make non-lazy "
"gettext calls at import time.")
for app_config in app_configs:
localedir = os.path.join(app_config.path, 'locale')
if os.path.exists(localedir):
translation = self._new_gnu_trans(localedir)
self.merge(translation)
示例8: _add_installed_apps_translations
# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import AppRegistryNotReady [as 別名]
def _add_installed_apps_translations(self):
"""Merges translations from each installed app."""
try:
app_configs = reversed(list(apps.get_app_configs()))
except AppRegistryNotReady:
raise AppRegistryNotReady(
"The translation infrastructure cannot be initialized before the "
"apps registry is ready. Check that you don't make non-lazy "
"gettext calls at import time.")
for app_config in app_configs:
localedir = os.path.join(app_config.path, 'locale')
if os.path.exists(localedir):
translation = self._new_gnu_trans(localedir)
self.merge(translation)
示例9: test_models_not_loaded
# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import AppRegistryNotReady [as 別名]
def test_models_not_loaded(self):
"""
apps.get_models() raises an exception if apps.models_ready isn't True.
"""
apps.models_ready = False
try:
# The cache must be cleared to trigger the exception.
apps.get_models.cache_clear()
with self.assertRaisesMessage(AppRegistryNotReady, "Models aren't loaded yet."):
apps.get_models()
finally:
apps.models_ready = True
示例10: test_get_containing_app_config_apps_not_ready
# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import AppRegistryNotReady [as 別名]
def test_get_containing_app_config_apps_not_ready(self):
"""
apps.get_containing_app_config() should raise an exception if
apps.apps_ready isn't True.
"""
apps.apps_ready = False
try:
with self.assertRaisesMessage(AppRegistryNotReady, "Apps aren't loaded yet"):
apps.get_containing_app_config('foo')
finally:
apps.apps_ready = True