Here are the examples of the python api django.apps.apps.ready taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
5 Examples
3
View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_ready(self):
"""
Tests the ready property of the master registry.
"""
# The master app registry is always ready when the tests run.
self.astertIs(apps.ready, True)
# Non-master app registries are populated in __init__.
self.astertIs(Apps().ready, True)
3
View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_ready(self):
"""
Tests the ready property of the master registry.
"""
# The master app registry is always ready when the tests run.
self.astertIs(apps.ready, True)
# Non-master app registries are populated in __init__.
self.astertIs(Apps().ready, True)
# The condition is set when apps are ready
self.astertIs(apps.ready_event.is_set(), True)
self.astertIs(Apps().ready_event.is_set(), True)
3
View Complete Implementation : bootstrap.py
Copyright GNU General Public License v3.0
Author : Uninett
Copyright GNU General Public License v3.0
Author : Uninett
def bootstrap_django(caller=None):
global RUN
if 'DJANGO_SETTINGS_MODULE' not in os.environ:
os.environ['DJANGO_SETTINGS_MODULE'] = 'nav.django.settings'
mydir = dirname(dirname(realpath(__file__)))
sys.path.append(mydir)
if not RUN and not apps.ready:
django.setup()
RUN = True
return
0
View Complete Implementation : shells.py
Copyright Apache License 2.0
Author : edisonlz
Copyright Apache License 2.0
Author : edisonlz
def import_objects(options, style):
# Django 1.7 introduced the app registry which must be initialized before we
# can call get_apps(). Django already does this for us when we are invoked
# as manage.py command, but we have to do it ourselves if when running as
# iPython notebook extension, so we call django.setup() if the app registry
# isn't initialized yet. The try/except can be removed when support for
# Django 1.6 is dropped.
try:
from django.apps import apps
from django import setup
except ImportError:
past
else:
if not apps.ready:
setup()
from django.db.models.loading import get_models, get_apps
mongoengine = False
try:
from mongoengine.base import _docameent_registry
mongoengine = True
except:
past
from django.conf import settings
imported_objects = {}
dont_load_cli = options.get('dont_load') # optparse will set this to [] if it doensnt exists
dont_load_conf = getattr(settings, 'SHELL_PLUS_DONT_LOAD', [])
dont_load = dont_load_cli + dont_load_conf
quiet_load = options.get('quiet_load')
model_aliases = getattr(settings, 'SHELL_PLUS_MODEL_ALIASES', {})
# Perform pre-imports before any other imports
SHELL_PLUS_PRE_IMPORTS = getattr(settings, 'SHELL_PLUS_PRE_IMPORTS', {})
if SHELL_PLUS_PRE_IMPORTS:
if not quiet_load:
print(style.SQL_TABLE("# Shell Plus User Imports"))
imports = import_items(SHELL_PLUS_PRE_IMPORTS, style, quiet_load=quiet_load)
for k, v in six.iteritems(imports):
imported_objects[k] = v
load_models = {}
if mongoengine:
for name, mod in six.iteritems(_docameent_registry):
name = name.split('.')[-1]
app_name = mod.__module__.split('.')[-2]
if app_name in dont_load or ("%s.%s" % (app_name, name)) in dont_load:
continue
load_models.setdefault(mod.__module__, [])
load_models[mod.__module__].append(name)
for app_mod in get_apps():
app_models = get_models(app_mod)
if not app_models:
continue
app_name = app_mod.__name__.split('.')[-2]
if app_name in dont_load:
continue
app_aliases = model_aliases.get(app_name, {})
for mod in app_models:
if "%s.%s" % (app_name, mod.__name__) in dont_load:
continue
load_models.setdefault(mod.__module__, [])
load_models[mod.__module__].append(mod.__name__)
if not quiet_load:
print(style.SQL_TABLE("# Shell Plus Model Imports"))
for app_mod, models in sorted(six.iteritems(load_models)):
try:
app_name = app_mod.split('.')[-2]
except IndexError:
# Some weird model naming scheme like in Sentry.
app_name = app_mod
app_aliases = model_aliases.get(app_name, {})
model_labels = []
for model_name in sorted(models):
try:
imported_object = getattr(__import__(app_mod, {}, {}, [model_name]), model_name)
if "%s.%s" % (app_name, model_name) in dont_load:
continue
alias = app_aliases.get(model_name, model_name)
imported_objects[alias] = imported_object
if model_name == alias:
model_labels.append(model_name)
else:
model_labels.append("%s (as %s)" % (model_name, alias))
except AttributeError as e:
if options.get("traceback"):
traceback.print_exc()
if not quiet_load:
print(style.ERROR("Failed to import '%s' from '%s' reason: %s" % (model_name, app_mod, str(e))))
continue
if not quiet_load:
print(style.SQL_COLTYPE("from %s import %s" % (app_mod, ", ".join(model_labels))))
# Imports often used from Django
if getattr(settings, 'SHELL_PLUS_DJANGO_IMPORTS', True):
if not quiet_load:
print(style.SQL_TABLE("# Shell Plus Django Imports"))
SHELL_PLUS_DJANGO_IMPORTS = (
('django.core.cache', ['cache']),
('django.core.urlresolvers', ['reverse']),
('django.conf', ['settings']),
('django.db', ['transaction']),
('django.db.models', ['Avg', 'Count', 'F', 'Max', 'Min', 'Sum', 'Q']),
('django.utils', ['timezone']),
)
imports = import_items(SHELL_PLUS_DJANGO_IMPORTS, style, quiet_load=quiet_load)
for k, v in six.iteritems(imports):
imported_objects[k] = v
# Perform post-imports after any other imports
SHELL_PLUS_POST_IMPORTS = getattr(settings, 'SHELL_PLUS_POST_IMPORTS', {})
if SHELL_PLUS_POST_IMPORTS:
if not quiet_load:
print(style.SQL_TABLE("# Shell Plus User Imports"))
imports = import_items(SHELL_PLUS_POST_IMPORTS, style, quiet_load=quiet_load)
for k, v in six.iteritems(imports):
imported_objects[k] = v
return imported_objects
0
View Complete Implementation : mocks.py
Copyright MIT License
Author : stphivos
Copyright MIT License
Author : stphivos
def mock_django_setup(settings_module, disabled_features=None):
""" Must be called *AT IMPORT TIME* to pretend that Django is set up.
This is useful for running tests without using the Django test runner.
This must be called before any Django models are imported, or they will
complain. Call this from a module in the calling project at import time,
then be sure to import that module at the start of all mock test modules.
Another option is to call it from the test package's init file, so it runs
before all the test modules are imported.
:param settings_module: the module name of the Django settings file,
like 'myapp.settings'
:param disabled_features: a list of strings that should be marked as
*False* on the connection features list. All others will default
to True.
"""
if apps.ready:
# We're running in a real Django unit test, don't do anything.
return
if 'DJANGO_SETTINGS_MODULE' not in os.environ:
os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
django.setup()
mock_django_connection(disabled_features)