Deprecated get_apps().
This commit is contained in:
parent
d44de9b933
commit
2732edc5f2
|
@ -189,12 +189,6 @@ class BaseAppCache(object):
|
|||
raise UnavailableApp("App with label %r isn't available." % app_label)
|
||||
return app_config
|
||||
|
||||
def get_apps(self):
|
||||
"""
|
||||
Returns a list of all installed modules that contain models.
|
||||
"""
|
||||
return [app_config.models_module for app_config in self.get_app_configs()]
|
||||
|
||||
def get_app(self, app_label):
|
||||
"""
|
||||
Returns the module containing the models for the given app_label.
|
||||
|
@ -338,6 +332,15 @@ class BaseAppCache(object):
|
|||
|
||||
### DEPRECATED METHODS GO BELOW THIS LINE ###
|
||||
|
||||
def get_apps(self):
|
||||
"""
|
||||
Returns a list of all installed modules that contain models.
|
||||
"""
|
||||
warnings.warn(
|
||||
"[a.models_module for a in get_app_configs()] supersedes get_apps().",
|
||||
PendingDeprecationWarning, stacklevel=2)
|
||||
return [app_config.models_module for app_config in self.get_app_configs()]
|
||||
|
||||
def _get_app_package(self, app):
|
||||
return '.'.join(app.__name__.split('.')[:-1])
|
||||
|
||||
|
|
|
@ -86,8 +86,8 @@ If you're unsure, answer 'no'.
|
|||
|
||||
|
||||
def update_all_contenttypes(verbosity=2, **kwargs):
|
||||
for app in app_cache.get_apps():
|
||||
update_contenttypes(app, None, verbosity, **kwargs)
|
||||
for app_config in app_cache.get_app_configs():
|
||||
update_contenttypes(app_config.models_module, None, verbosity, **kwargs)
|
||||
|
||||
signals.post_migrate.connect(update_contenttypes)
|
||||
|
||||
|
|
|
@ -78,7 +78,9 @@ class Command(BaseCommand):
|
|||
if len(app_labels) == 0:
|
||||
if primary_keys:
|
||||
raise CommandError("You can only use --pks option with one model")
|
||||
app_list = OrderedDict((app, None) for app in app_cache.get_apps() if app not in excluded_apps)
|
||||
app_list = OrderedDict((app_config.models_module, None)
|
||||
for app_config in app_cache.get_app_configs()
|
||||
if app_config.models_module not in excluded_apps)
|
||||
else:
|
||||
if len(app_labels) > 1 and primary_keys:
|
||||
raise CommandError("You can only use --pks option with one model")
|
||||
|
|
|
@ -94,6 +94,6 @@ Are you sure you want to do this?
|
|||
# Emit the post migrate signal. This allows individual applications to
|
||||
# respond as if the database had been migrated from scratch.
|
||||
all_models = []
|
||||
for app in app_cache.get_apps():
|
||||
all_models.extend(router.get_migratable_models(app, database, include_auto_created=True))
|
||||
for app_config in app_cache.get_app_configs():
|
||||
all_models.extend(router.get_migratable_models(app_config.models_module, database, include_auto_created=True))
|
||||
emit_post_migrate_signal(set(all_models), verbosity, interactive, database)
|
||||
|
|
|
@ -180,9 +180,10 @@ class Command(BaseCommand):
|
|||
|
||||
# Build the manifest of apps and models that are to be synchronized
|
||||
all_models = [
|
||||
(app.__name__.split('.')[-2],
|
||||
router.get_migratable_models(app, connection.alias, include_auto_created=True))
|
||||
for app in app_cache.get_apps() if app.__name__.split('.')[-2] in apps
|
||||
(app_config.label,
|
||||
router.get_migratable_models(app_config.models_module, connection.alias, include_auto_created=True))
|
||||
for app_config in app_cache.get_app_configs()
|
||||
if app_config.label in apps
|
||||
]
|
||||
|
||||
def model_installed(model):
|
||||
|
|
|
@ -207,11 +207,12 @@ def custom_sql_for_model(model, style, connection):
|
|||
|
||||
def emit_pre_migrate_signal(create_models, verbosity, interactive, db):
|
||||
# Emit the pre_migrate signal for every application.
|
||||
for app in app_cache.get_apps():
|
||||
app_name = app.__name__.split('.')[-2]
|
||||
for app_config in app_cache.get_app_configs():
|
||||
if verbosity >= 2:
|
||||
print("Running pre-migrate handlers for application %s" % app_name)
|
||||
models.signals.pre_migrate.send(sender=app, app=app,
|
||||
print("Running pre-migrate handlers for application %s" % app_config.label)
|
||||
models.signals.pre_migrate.send(
|
||||
sender=app_config.models_module,
|
||||
app=app_config.models_module,
|
||||
create_models=create_models,
|
||||
verbosity=verbosity,
|
||||
interactive=interactive,
|
||||
|
@ -220,10 +221,13 @@ def emit_pre_migrate_signal(create_models, verbosity, interactive, db):
|
|||
|
||||
def emit_post_migrate_signal(created_models, verbosity, interactive, db):
|
||||
# Emit the post_migrate signal for every application.
|
||||
for app in app_cache.get_apps():
|
||||
app_name = app.__name__.split('.')[-2]
|
||||
for app_config in app_cache.get_app_configs():
|
||||
if verbosity >= 2:
|
||||
print("Running post-migrate handlers for application %s" % app_name)
|
||||
models.signals.post_migrate.send(sender=app, app=app,
|
||||
created_models=created_models, verbosity=verbosity,
|
||||
interactive=interactive, db=db)
|
||||
print("Running post-migrate handlers for application %s" % app_config.label)
|
||||
models.signals.post_migrate.send(
|
||||
sender=app_config.models_module,
|
||||
app=app_config.models_module,
|
||||
created_models=created_models,
|
||||
verbosity=verbosity,
|
||||
interactive=interactive,
|
||||
db=db)
|
||||
|
|
|
@ -1271,8 +1271,8 @@ class BaseDatabaseIntrospection(object):
|
|||
from django.apps import app_cache
|
||||
from django.db import router
|
||||
tables = set()
|
||||
for app in app_cache.get_apps():
|
||||
for model in router.get_migratable_models(app, self.connection.alias):
|
||||
for app_config in app_cache.get_app_configs():
|
||||
for model in router.get_migratable_models(app_config.models_module, self.connection.alias):
|
||||
if not model._meta.managed:
|
||||
continue
|
||||
tables.add(model._meta.db_table)
|
||||
|
@ -1292,8 +1292,8 @@ class BaseDatabaseIntrospection(object):
|
|||
from django.apps import app_cache
|
||||
from django.db import router
|
||||
all_models = []
|
||||
for app in app_cache.get_apps():
|
||||
all_models.extend(router.get_migratable_models(app, self.connection.alias))
|
||||
for app_config in app_cache.get_app_configs():
|
||||
all_models.extend(router.get_migratable_models(app_config.models_module, self.connection.alias))
|
||||
tables = list(map(self.table_name_converter, tables))
|
||||
return set([
|
||||
m for m in all_models
|
||||
|
@ -1305,11 +1305,10 @@ class BaseDatabaseIntrospection(object):
|
|||
from django.apps import app_cache
|
||||
from django.db import models, router
|
||||
|
||||
apps = app_cache.get_apps()
|
||||
sequence_list = []
|
||||
|
||||
for app in apps:
|
||||
for model in router.get_migratable_models(app, self.connection.alias):
|
||||
for app_config in app_cache.get_app_configs():
|
||||
for model in router.get_migratable_models(app_config.models_module, self.connection.alias):
|
||||
if not model._meta.managed:
|
||||
continue
|
||||
if model._meta.swapped:
|
||||
|
|
|
@ -55,10 +55,9 @@ class MigrationLoader(object):
|
|||
self.disk_migrations = {}
|
||||
self.unmigrated_apps = set()
|
||||
self.migrated_apps = set()
|
||||
for app in app_cache.get_apps():
|
||||
for app_config in app_cache.get_app_configs():
|
||||
# Get the migrations module directory
|
||||
app_label = app.__name__.split(".")[-2]
|
||||
module_name = self.migrations_module(app_label)
|
||||
module_name = self.migrations_module(app_config.label)
|
||||
was_loaded = module_name in sys.modules
|
||||
try:
|
||||
module = import_module(module_name)
|
||||
|
@ -66,7 +65,7 @@ class MigrationLoader(object):
|
|||
# I hate doing this, but I don't want to squash other import errors.
|
||||
# Might be better to try a directory check directly.
|
||||
if "No module named" in str(e) and "migrations" in str(e):
|
||||
self.unmigrated_apps.add(app_label)
|
||||
self.unmigrated_apps.add(app_config.label)
|
||||
continue
|
||||
raise
|
||||
else:
|
||||
|
@ -79,7 +78,7 @@ class MigrationLoader(object):
|
|||
# Force a reload if it's already loaded (tests need this)
|
||||
if was_loaded:
|
||||
six.moves.reload_module(module)
|
||||
self.migrated_apps.add(app_label)
|
||||
self.migrated_apps.add(app_config.label)
|
||||
directory = os.path.dirname(module.__file__)
|
||||
# Scan for .py[c|o] files
|
||||
migration_names = set()
|
||||
|
@ -100,14 +99,14 @@ class MigrationLoader(object):
|
|||
break
|
||||
raise
|
||||
if not hasattr(migration_module, "Migration"):
|
||||
raise BadMigrationError("Migration %s in app %s has no Migration class" % (migration_name, app_label))
|
||||
raise BadMigrationError("Migration %s in app %s has no Migration class" % (migration_name, app_config.label))
|
||||
# Ignore South-style migrations
|
||||
if hasattr(migration_module.Migration, "forwards"):
|
||||
south_style_migrations = True
|
||||
break
|
||||
self.disk_migrations[app_label, migration_name] = migration_module.Migration(migration_name, app_label)
|
||||
self.disk_migrations[app_config.label, migration_name] = migration_module.Migration(migration_name, app_config.label)
|
||||
if south_style_migrations:
|
||||
self.unmigrated_apps.add(app_label)
|
||||
self.unmigrated_apps.add(app_config.label)
|
||||
|
||||
def get_migration(self, app_label, name_prefix):
|
||||
"Gets the migration exactly named, or raises KeyError"
|
||||
|
|
|
@ -244,8 +244,8 @@ class DjangoTestSuiteRunner(runner.DiscoverRunner):
|
|||
app = app_cache.get_app(label)
|
||||
suite.addTest(build_suite(app))
|
||||
else:
|
||||
for app in app_cache.get_apps():
|
||||
suite.addTest(build_suite(app))
|
||||
for app_config in app_cache.get_app_configs():
|
||||
suite.addTest(build_suite(app_config.models_module))
|
||||
|
||||
if extra_tests:
|
||||
for test in extra_tests:
|
||||
|
|
|
@ -81,7 +81,7 @@ def get_test_modules():
|
|||
|
||||
def get_installed():
|
||||
from django.apps import app_cache
|
||||
return [app.__name__.rsplit('.', 1)[0] for app in app_cache.get_apps()]
|
||||
return [app_config.name for app_config in app_cache.get_app_configs()]
|
||||
|
||||
|
||||
def setup(verbosity, test_labels):
|
||||
|
|
Loading…
Reference in New Issue