mirror of
https://github.com/django/django.git
synced 2025-06-05 11:39:13 +00:00
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)
|
raise UnavailableApp("App with label %r isn't available." % app_label)
|
||||||
return app_config
|
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):
|
def get_app(self, app_label):
|
||||||
"""
|
"""
|
||||||
Returns the module containing the models for the given 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 ###
|
### 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):
|
def _get_app_package(self, app):
|
||||||
return '.'.join(app.__name__.split('.')[:-1])
|
return '.'.join(app.__name__.split('.')[:-1])
|
||||||
|
|
||||||
|
@ -86,8 +86,8 @@ If you're unsure, answer 'no'.
|
|||||||
|
|
||||||
|
|
||||||
def update_all_contenttypes(verbosity=2, **kwargs):
|
def update_all_contenttypes(verbosity=2, **kwargs):
|
||||||
for app in app_cache.get_apps():
|
for app_config in app_cache.get_app_configs():
|
||||||
update_contenttypes(app, None, verbosity, **kwargs)
|
update_contenttypes(app_config.models_module, None, verbosity, **kwargs)
|
||||||
|
|
||||||
signals.post_migrate.connect(update_contenttypes)
|
signals.post_migrate.connect(update_contenttypes)
|
||||||
|
|
||||||
|
@ -78,7 +78,9 @@ class Command(BaseCommand):
|
|||||||
if len(app_labels) == 0:
|
if len(app_labels) == 0:
|
||||||
if primary_keys:
|
if primary_keys:
|
||||||
raise CommandError("You can only use --pks option with one model")
|
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:
|
else:
|
||||||
if len(app_labels) > 1 and primary_keys:
|
if len(app_labels) > 1 and primary_keys:
|
||||||
raise CommandError("You can only use --pks option with one model")
|
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
|
# Emit the post migrate signal. This allows individual applications to
|
||||||
# respond as if the database had been migrated from scratch.
|
# respond as if the database had been migrated from scratch.
|
||||||
all_models = []
|
all_models = []
|
||||||
for app in app_cache.get_apps():
|
for app_config in app_cache.get_app_configs():
|
||||||
all_models.extend(router.get_migratable_models(app, database, include_auto_created=True))
|
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)
|
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
|
# Build the manifest of apps and models that are to be synchronized
|
||||||
all_models = [
|
all_models = [
|
||||||
(app.__name__.split('.')[-2],
|
(app_config.label,
|
||||||
router.get_migratable_models(app, connection.alias, include_auto_created=True))
|
router.get_migratable_models(app_config.models_module, connection.alias, include_auto_created=True))
|
||||||
for app in app_cache.get_apps() if app.__name__.split('.')[-2] in apps
|
for app_config in app_cache.get_app_configs()
|
||||||
|
if app_config.label in apps
|
||||||
]
|
]
|
||||||
|
|
||||||
def model_installed(model):
|
def model_installed(model):
|
||||||
|
@ -207,23 +207,27 @@ def custom_sql_for_model(model, style, connection):
|
|||||||
|
|
||||||
def emit_pre_migrate_signal(create_models, verbosity, interactive, db):
|
def emit_pre_migrate_signal(create_models, verbosity, interactive, db):
|
||||||
# Emit the pre_migrate signal for every application.
|
# Emit the pre_migrate signal for every application.
|
||||||
for app in app_cache.get_apps():
|
for app_config in app_cache.get_app_configs():
|
||||||
app_name = app.__name__.split('.')[-2]
|
|
||||||
if verbosity >= 2:
|
if verbosity >= 2:
|
||||||
print("Running pre-migrate handlers for application %s" % app_name)
|
print("Running pre-migrate handlers for application %s" % app_config.label)
|
||||||
models.signals.pre_migrate.send(sender=app, app=app,
|
models.signals.pre_migrate.send(
|
||||||
create_models=create_models,
|
sender=app_config.models_module,
|
||||||
verbosity=verbosity,
|
app=app_config.models_module,
|
||||||
interactive=interactive,
|
create_models=create_models,
|
||||||
db=db)
|
verbosity=verbosity,
|
||||||
|
interactive=interactive,
|
||||||
|
db=db)
|
||||||
|
|
||||||
|
|
||||||
def emit_post_migrate_signal(created_models, verbosity, interactive, db):
|
def emit_post_migrate_signal(created_models, verbosity, interactive, db):
|
||||||
# Emit the post_migrate signal for every application.
|
# Emit the post_migrate signal for every application.
|
||||||
for app in app_cache.get_apps():
|
for app_config in app_cache.get_app_configs():
|
||||||
app_name = app.__name__.split('.')[-2]
|
|
||||||
if verbosity >= 2:
|
if verbosity >= 2:
|
||||||
print("Running post-migrate handlers for application %s" % app_name)
|
print("Running post-migrate handlers for application %s" % app_config.label)
|
||||||
models.signals.post_migrate.send(sender=app, app=app,
|
models.signals.post_migrate.send(
|
||||||
created_models=created_models, verbosity=verbosity,
|
sender=app_config.models_module,
|
||||||
interactive=interactive, db=db)
|
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.apps import app_cache
|
||||||
from django.db import router
|
from django.db import router
|
||||||
tables = set()
|
tables = set()
|
||||||
for app in app_cache.get_apps():
|
for app_config in app_cache.get_app_configs():
|
||||||
for model in router.get_migratable_models(app, self.connection.alias):
|
for model in router.get_migratable_models(app_config.models_module, self.connection.alias):
|
||||||
if not model._meta.managed:
|
if not model._meta.managed:
|
||||||
continue
|
continue
|
||||||
tables.add(model._meta.db_table)
|
tables.add(model._meta.db_table)
|
||||||
@ -1292,8 +1292,8 @@ class BaseDatabaseIntrospection(object):
|
|||||||
from django.apps import app_cache
|
from django.apps import app_cache
|
||||||
from django.db import router
|
from django.db import router
|
||||||
all_models = []
|
all_models = []
|
||||||
for app in app_cache.get_apps():
|
for app_config in app_cache.get_app_configs():
|
||||||
all_models.extend(router.get_migratable_models(app, self.connection.alias))
|
all_models.extend(router.get_migratable_models(app_config.models_module, self.connection.alias))
|
||||||
tables = list(map(self.table_name_converter, tables))
|
tables = list(map(self.table_name_converter, tables))
|
||||||
return set([
|
return set([
|
||||||
m for m in all_models
|
m for m in all_models
|
||||||
@ -1305,11 +1305,10 @@ class BaseDatabaseIntrospection(object):
|
|||||||
from django.apps import app_cache
|
from django.apps import app_cache
|
||||||
from django.db import models, router
|
from django.db import models, router
|
||||||
|
|
||||||
apps = app_cache.get_apps()
|
|
||||||
sequence_list = []
|
sequence_list = []
|
||||||
|
|
||||||
for app in apps:
|
for app_config in app_cache.get_app_configs():
|
||||||
for model in router.get_migratable_models(app, self.connection.alias):
|
for model in router.get_migratable_models(app_config.models_module, self.connection.alias):
|
||||||
if not model._meta.managed:
|
if not model._meta.managed:
|
||||||
continue
|
continue
|
||||||
if model._meta.swapped:
|
if model._meta.swapped:
|
||||||
|
@ -55,10 +55,9 @@ class MigrationLoader(object):
|
|||||||
self.disk_migrations = {}
|
self.disk_migrations = {}
|
||||||
self.unmigrated_apps = set()
|
self.unmigrated_apps = set()
|
||||||
self.migrated_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
|
# Get the migrations module directory
|
||||||
app_label = app.__name__.split(".")[-2]
|
module_name = self.migrations_module(app_config.label)
|
||||||
module_name = self.migrations_module(app_label)
|
|
||||||
was_loaded = module_name in sys.modules
|
was_loaded = module_name in sys.modules
|
||||||
try:
|
try:
|
||||||
module = import_module(module_name)
|
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.
|
# I hate doing this, but I don't want to squash other import errors.
|
||||||
# Might be better to try a directory check directly.
|
# Might be better to try a directory check directly.
|
||||||
if "No module named" in str(e) and "migrations" in str(e):
|
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
|
continue
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
@ -79,7 +78,7 @@ class MigrationLoader(object):
|
|||||||
# Force a reload if it's already loaded (tests need this)
|
# Force a reload if it's already loaded (tests need this)
|
||||||
if was_loaded:
|
if was_loaded:
|
||||||
six.moves.reload_module(module)
|
six.moves.reload_module(module)
|
||||||
self.migrated_apps.add(app_label)
|
self.migrated_apps.add(app_config.label)
|
||||||
directory = os.path.dirname(module.__file__)
|
directory = os.path.dirname(module.__file__)
|
||||||
# Scan for .py[c|o] files
|
# Scan for .py[c|o] files
|
||||||
migration_names = set()
|
migration_names = set()
|
||||||
@ -100,14 +99,14 @@ class MigrationLoader(object):
|
|||||||
break
|
break
|
||||||
raise
|
raise
|
||||||
if not hasattr(migration_module, "Migration"):
|
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
|
# Ignore South-style migrations
|
||||||
if hasattr(migration_module.Migration, "forwards"):
|
if hasattr(migration_module.Migration, "forwards"):
|
||||||
south_style_migrations = True
|
south_style_migrations = True
|
||||||
break
|
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:
|
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):
|
def get_migration(self, app_label, name_prefix):
|
||||||
"Gets the migration exactly named, or raises KeyError"
|
"Gets the migration exactly named, or raises KeyError"
|
||||||
|
@ -244,8 +244,8 @@ class DjangoTestSuiteRunner(runner.DiscoverRunner):
|
|||||||
app = app_cache.get_app(label)
|
app = app_cache.get_app(label)
|
||||||
suite.addTest(build_suite(app))
|
suite.addTest(build_suite(app))
|
||||||
else:
|
else:
|
||||||
for app in app_cache.get_apps():
|
for app_config in app_cache.get_app_configs():
|
||||||
suite.addTest(build_suite(app))
|
suite.addTest(build_suite(app_config.models_module))
|
||||||
|
|
||||||
if extra_tests:
|
if extra_tests:
|
||||||
for test in extra_tests:
|
for test in extra_tests:
|
||||||
|
@ -81,7 +81,7 @@ def get_test_modules():
|
|||||||
|
|
||||||
def get_installed():
|
def get_installed():
|
||||||
from django.apps import app_cache
|
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):
|
def setup(verbosity, test_labels):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user