diff options
Diffstat (limited to 'django/core')
| -rw-r--r-- | django/core/checks/compatibility/django_1_6_0.py | 4 | ||||
| -rw-r--r-- | django/core/management/__init__.py | 20 | ||||
| -rw-r--r-- | django/core/management/base.py | 6 | ||||
| -rw-r--r-- | django/core/management/commands/dumpdata.py | 20 | ||||
| -rw-r--r-- | django/core/management/commands/flush.py | 6 | ||||
| -rw-r--r-- | django/core/management/commands/loaddata.py | 4 | ||||
| -rw-r--r-- | django/core/management/commands/makemigrations.py | 6 | ||||
| -rw-r--r-- | django/core/management/commands/migrate.py | 34 | ||||
| -rw-r--r-- | django/core/management/commands/shell.py | 4 | ||||
| -rw-r--r-- | django/core/management/commands/sqlsequencereset.py | 4 | ||||
| -rw-r--r-- | django/core/management/sql.py | 10 | ||||
| -rw-r--r-- | django/core/management/validation.py | 12 | ||||
| -rw-r--r-- | django/core/serializers/base.py | 6 | ||||
| -rw-r--r-- | django/core/serializers/python.py | 6 | ||||
| -rw-r--r-- | django/core/serializers/xml_serializer.py | 4 |
15 files changed, 73 insertions, 73 deletions
diff --git a/django/core/checks/compatibility/django_1_6_0.py b/django/core/checks/compatibility/django_1_6_0.py index a42249de60..1be727f70d 100644 --- a/django/core/checks/compatibility/django_1_6_0.py +++ b/django/core/checks/compatibility/django_1_6_0.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals -from django.apps import app_cache +from django.apps import apps from django.db import models @@ -32,7 +32,7 @@ def check_boolean_field_default_value(): warns the user that the default has changed from False to Null. """ fields = [] - for cls in app_cache.get_models(): + for cls in apps.get_models(): opts = cls._meta for f in opts.local_fields: if isinstance(f, models.BooleanField) and not f.has_default(): diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index bc81b8f9d2..019837b35c 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -112,17 +112,17 @@ def get_commands(): except ImproperlyConfigured: # Still useful for commands that do not require functional # settings, like startproject or help. - apps = [] + app_names = [] else: - # Populate the app cache outside of the try/except block to avoid - # catching ImproperlyConfigured errors that aren't caused by the - # absence of a settings module. - from django.apps import app_cache - app_configs = app_cache.get_app_configs() - apps = [app_config.name for app_config in app_configs] + # Populate the app registry outside of the try/except block to + # avoid catching ImproperlyConfigured errors that aren't caused + # by the absence of a settings module. + from django.apps import apps + app_configs = apps.get_app_configs() + app_names = [app_config.name for app_config in app_configs] # Find and load the management module for each installed app. - for app_name in apps: + for app_name in app_names: try: path = find_management_module(app_name) _commands.update(dict((name, app_name) for name in find_commands(path))) @@ -346,8 +346,8 @@ class ManagementUtility(object): elif cwords[0] in ('dumpdata', 'sql', 'sqlall', 'sqlclear', 'sqlcustom', 'sqlindexes', 'sqlsequencereset', 'test'): try: - from django.apps import app_cache - app_configs = app_cache.get_app_configs() + from django.apps import apps + app_configs = apps.get_app_configs() # Get the last part of the dotted path as the app name. options += [(app_config.label, 0) for app_config in app_configs] except ImportError: diff --git a/django/core/management/base.py b/django/core/management/base.py index 101a486b40..5c3a1a6c8c 100644 --- a/django/core/management/base.py +++ b/django/core/management/base.py @@ -341,16 +341,16 @@ class AppCommand(BaseCommand): args = '<appname appname ...>' def handle(self, *app_labels, **options): - from django.apps import app_cache + from django.apps import apps if not app_labels: raise CommandError('Enter at least one appname.') # Populate models and don't use only_with_models_module=True when # calling get_app_config() to tell apart missing apps from apps # without a model module -- which can't be supported with the legacy # API since it passes the models module to handle_app(). - app_cache.populate_models() + apps.populate_models() try: - app_configs = [app_cache.get_app_config(app_label) for app_label in app_labels] + app_configs = [apps.get_app_config(app_label) for app_label in app_labels] except (LookupError, ImportError) as e: raise CommandError("%s. Are you sure your INSTALLED_APPS setting is correct?" % e) output = [] diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py index 9aebb6c7d6..f6b9e7a4c8 100644 --- a/django/core/management/commands/dumpdata.py +++ b/django/core/management/commands/dumpdata.py @@ -37,7 +37,7 @@ class Command(BaseCommand): args = '[appname appname.ModelName ...]' def handle(self, *app_labels, **options): - from django.apps import app_cache + from django.apps import apps format = options.get('format') indent = options.get('indent') @@ -63,13 +63,13 @@ class Command(BaseCommand): for exclude in excludes: if '.' in exclude: app_label, model_name = exclude.split('.', 1) - model_obj = app_cache.get_model(app_label, model_name) + model_obj = apps.get_model(app_label, model_name) if not model_obj: raise CommandError('Unknown model in excludes: %s' % exclude) excluded_models.add(model_obj) else: try: - app_obj = app_cache.get_app_config(exclude).models_module + app_obj = apps.get_app_config(exclude).models_module if app_obj is not None: excluded_apps.add(app_obj) except LookupError: @@ -79,7 +79,7 @@ class Command(BaseCommand): if primary_keys: raise CommandError("You can only use --pks option with one model") app_list = OrderedDict((app_config.models_module, None) - for app_config in app_cache.get_app_configs(only_with_models_module=True) + for app_config in apps.get_app_configs(only_with_models_module=True) if app_config.models_module not in excluded_apps) else: if len(app_labels) > 1 and primary_keys: @@ -89,12 +89,12 @@ class Command(BaseCommand): try: app_label, model_label = label.split('.') try: - app = app_cache.get_app_config(app_label).models_module + app = apps.get_app_config(app_label).models_module except LookupError: raise CommandError("Unknown application: %s" % app_label) if app is None or app in excluded_apps: continue - model = app_cache.get_model(app_label, model_label) + model = apps.get_model(app_label, model_label) if model is None: raise CommandError("Unknown model: %s.%s" % (app_label, model_label)) @@ -109,7 +109,7 @@ class Command(BaseCommand): # This is just an app - no model qualifier app_label = label try: - app = app_cache.get_app_config(app_label).models_module + app = apps.get_app_config(app_label).models_module except LookupError: raise CommandError("Unknown application: %s" % app_label) if app is None or app in excluded_apps: @@ -162,13 +162,13 @@ def sort_dependencies(app_list): is serialized before a normal model, and any model with a natural key dependency has it's dependencies serialized first. """ - from django.apps import app_cache + from django.apps import apps # Process the list of models, and get the list of dependencies model_dependencies = [] models = set() for app, model_list in app_list: if model_list is None: - model_list = app_cache.get_models(app) + model_list = apps.get_models(app) for model in model_list: models.add(model) @@ -176,7 +176,7 @@ def sort_dependencies(app_list): if hasattr(model, 'natural_key'): deps = getattr(model.natural_key, 'dependencies', []) if deps: - deps = [app_cache.get_model(*d.split('.')) for d in deps] + deps = [apps.get_model(*d.split('.')) for d in deps] else: deps = [] diff --git a/django/core/management/commands/flush.py b/django/core/management/commands/flush.py index 49007bf0a2..619df9536c 100644 --- a/django/core/management/commands/flush.py +++ b/django/core/management/commands/flush.py @@ -2,7 +2,7 @@ import sys from importlib import import_module from optparse import make_option -from django.apps import app_cache +from django.apps import apps from django.db import connections, router, transaction, DEFAULT_DB_ALIAS from django.core.management import call_command from django.core.management.base import NoArgsCommand, CommandError @@ -41,7 +41,7 @@ class Command(NoArgsCommand): # Import the 'management' module within each installed app, to register # dispatcher events. - for app_config in app_cache.get_app_configs(): + for app_config in apps.get_app_configs(): try: import_module('.management', app_config.name) except ImportError: @@ -93,6 +93,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_config in app_cache.get_app_configs(only_with_models_module=True): + for app_config in apps.get_app_configs(only_with_models_module=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) diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py index bfeba68aa6..65bc96ba99 100644 --- a/django/core/management/commands/loaddata.py +++ b/django/core/management/commands/loaddata.py @@ -7,7 +7,7 @@ import warnings import zipfile from optparse import make_option -from django.apps import app_cache +from django.apps import apps from django.conf import settings from django.core import serializers from django.core.management.base import BaseCommand, CommandError @@ -230,7 +230,7 @@ class Command(BaseCommand): current directory. """ dirs = [] - for app_config in app_cache.get_app_configs(): + for app_config in apps.get_app_configs(): d = os.path.join(app_config.path, 'fixtures') if os.path.isdir(d): dirs.append(d) diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py index aaf0270840..411aec42b3 100644 --- a/django/core/management/commands/makemigrations.py +++ b/django/core/management/commands/makemigrations.py @@ -3,7 +3,7 @@ import os import operator from optparse import make_option -from django.apps import app_cache +from django.apps import apps from django.core.management.base import BaseCommand, CommandError from django.db import connections, DEFAULT_DB_ALIAS, migrations from django.db.migrations.loader import MigrationLoader @@ -37,7 +37,7 @@ class Command(BaseCommand): bad_app_labels = set() for app_label in app_labels: try: - app_cache.get_app_config(app_label) + apps.get_app_config(app_label) except LookupError: bad_app_labels.add(app_label) if bad_app_labels: @@ -72,7 +72,7 @@ class Command(BaseCommand): # Detect changes autodetector = MigrationAutodetector( loader.graph.project_state(), - ProjectState.from_app_cache(app_cache), + ProjectState.from_apps(apps), InteractiveMigrationQuestioner(specified_apps=app_labels), ) changes = autodetector.changes(graph=loader.graph, trim_to_apps=app_labels or None) diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py index 05b4a62e87..1f5e9619c7 100644 --- a/django/core/management/commands/migrate.py +++ b/django/core/management/commands/migrate.py @@ -6,7 +6,7 @@ from importlib import import_module import itertools import traceback -from django.apps import app_cache +from django.apps import apps from django.core.management import call_command from django.core.management.base import BaseCommand, CommandError from django.core.management.color import no_style @@ -46,7 +46,7 @@ class Command(BaseCommand): # Import the 'management' module within each installed app, to register # dispatcher events. - for app_config in app_cache.get_app_configs(): + for app_config in apps.get_app_configs(): if module_has_submodule(app_config.app_module, "management"): import_module('.management', app_config.name) @@ -135,7 +135,7 @@ class Command(BaseCommand): # If there's changes that aren't in migrations yet, tell them how to fix it. autodetector = MigrationAutodetector( executor.loader.graph.project_state(), - ProjectState.from_app_cache(app_cache), + ProjectState.from_apps(apps), ) changes = autodetector.changes(graph=executor.loader.graph) if changes: @@ -167,8 +167,8 @@ class Command(BaseCommand): else: self.stdout.write(self.style.MIGRATE_SUCCESS(" OK")) - def sync_apps(self, connection, apps): - "Runs the old syncdb-style operation on a list of apps." + def sync_apps(self, connection, app_labels): + "Runs the old syncdb-style operation on a list of app_labels." cursor = connection.cursor() # Get a list of already installed *models* so that references work right. @@ -181,8 +181,8 @@ class Command(BaseCommand): all_models = [ (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(only_with_models_module=True) - if app_config.label in apps + for app_config in apps.get_app_configs(only_with_models_module=True) + if app_config.label in app_labels ] def model_installed(model): @@ -277,7 +277,7 @@ class Command(BaseCommand): return created_models - def show_migration_list(self, connection, apps=None): + def show_migration_list(self, connection, app_names=None): """ Shows a list of all migrations on the system, or only those of some named apps. @@ -286,24 +286,24 @@ class Command(BaseCommand): loader = MigrationLoader(connection) graph = loader.graph # If we were passed a list of apps, validate it - if apps: + if app_names: invalid_apps = [] - for app in apps: - if app not in loader.migrated_apps: - invalid_apps.append(app) + for app_name in app_names: + if app_name not in loader.migrated_apps: + invalid_apps.append(app_name) if invalid_apps: raise CommandError("No migrations present for: %s" % (", ".join(invalid_apps))) # Otherwise, show all apps in alphabetic order else: - apps = sorted(loader.migrated_apps) + app_names = sorted(loader.migrated_apps) # For each app, print its migrations in order from oldest (roots) to # newest (leaves). - for app in apps: - self.stdout.write(app, self.style.MIGRATE_LABEL) + for app_name in app_names: + self.stdout.write(app_name, self.style.MIGRATE_LABEL) shown = set() - for node in graph.leaf_nodes(app): + for node in graph.leaf_nodes(app_name): for plan_node in graph.forwards_plan(node): - if plan_node not in shown and plan_node[0] == app: + if plan_node not in shown and plan_node[0] == app_name: # Give it a nice title if it's a squashed one title = plan_node[1] if graph.nodes[plan_node].replaces: diff --git a/django/core/management/commands/shell.py b/django/core/management/commands/shell.py index 12af814161..149b9edd89 100644 --- a/django/core/management/commands/shell.py +++ b/django/core/management/commands/shell.py @@ -66,8 +66,8 @@ class Command(NoArgsCommand): def handle_noargs(self, **options): # XXX: (Temporary) workaround for ticket #1796: force early loading of all # models from installed apps. - from django.apps import app_cache - app_cache.get_models() + from django.apps import apps + apps.get_models() use_plain = options.get('plain', False) no_startup = options.get('no_startup', False) diff --git a/django/core/management/commands/sqlsequencereset.py b/django/core/management/commands/sqlsequencereset.py index 24ec25e8ed..58f171e87b 100644 --- a/django/core/management/commands/sqlsequencereset.py +++ b/django/core/management/commands/sqlsequencereset.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals from optparse import make_option -from django.apps import app_cache +from django.apps import apps from django.core.management.base import AppCommand from django.db import connections, DEFAULT_DB_ALIAS @@ -21,4 +21,4 @@ class Command(AppCommand): def handle_app(self, app, **options): connection = connections[options.get('database')] - return '\n'.join(connection.ops.sequence_reset_sql(self.style, app_cache.get_models(app, include_auto_created=True))) + return '\n'.join(connection.ops.sequence_reset_sql(self.style, apps.get_models(app, include_auto_created=True))) diff --git a/django/core/management/sql.py b/django/core/management/sql.py index b2500d3787..35ce693e3b 100644 --- a/django/core/management/sql.py +++ b/django/core/management/sql.py @@ -5,7 +5,7 @@ import os import re import warnings -from django.apps import app_cache +from django.apps import apps from django.conf import settings from django.core.management.base import CommandError from django.db import models, router @@ -25,7 +25,7 @@ def sql_create(app, style, connection): # We trim models from the current app so that the sqlreset command does not # generate invalid SQL (leaving models out of known_models is harmless, so # we can be conservative). - app_models = app_cache.get_models(app, include_auto_created=True) + app_models = apps.get_models(app, include_auto_created=True) final_output = [] tables = connection.introspection.table_names() known_models = set(model for model in connection.introspection.installed_models(tables) if model not in app_models) @@ -169,7 +169,7 @@ def _split_statements(content): def custom_sql_for_model(model, style, connection): opts = model._meta app_dirs = [] - app_dir = app_cache.get_app_config(model._meta.app_label).path + app_dir = apps.get_app_config(model._meta.app_label).path app_dirs.append(os.path.normpath(os.path.join(app_dir, 'sql'))) # Deprecated location -- remove in Django 1.9 @@ -207,7 +207,7 @@ 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_config in app_cache.get_app_configs(only_with_models_module=True): + for app_config in apps.get_app_configs(only_with_models_module=True): if verbosity >= 2: print("Running pre-migrate handlers for application %s" % app_config.label) models.signals.pre_migrate.send( @@ -221,7 +221,7 @@ 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_config in app_cache.get_app_configs(only_with_models_module=True): + for app_config in apps.get_app_configs(only_with_models_module=True): if verbosity >= 2: print("Running post-migrate handlers for application %s" % app_config.label) models.signals.post_migrate.send( diff --git a/django/core/management/validation.py b/django/core/management/validation.py index 2b27a7edce..c3b55770ce 100644 --- a/django/core/management/validation.py +++ b/django/core/management/validation.py @@ -26,13 +26,13 @@ def get_validation_errors(outfile, app=None): validates all models of all installed apps. Writes errors, if any, to outfile. Returns number of errors. """ - from django.apps import app_cache + from django.apps import apps from django.db import connection, models from django.db.models.deletion import SET_NULL, SET_DEFAULT e = ModelErrorCollection(outfile) - for cls in app_cache.get_models(app, include_swapped=True): + for cls in apps.get_models(app, include_swapped=True): opts = cls._meta # Check swappable attribute. @@ -42,7 +42,7 @@ def get_validation_errors(outfile, app=None): except ValueError: e.add(opts, "%s is not of the form 'app_label.app_name'." % opts.swappable) continue - if not app_cache.get_model(app_label, model_name): + if not apps.get_model(app_label, model_name): e.add(opts, "Model has been swapped out for '%s' which has not been installed or is abstract." % opts.swapped) # No need to perform any other validation checks on a swapped model. continue @@ -152,7 +152,7 @@ def get_validation_errors(outfile, app=None): # Check to see if the related field will clash with any existing # fields, m2m fields, m2m related objects or related objects if f.rel: - if f.rel.to not in app_cache.get_models(): + if f.rel.to not in apps.get_models(): # If the related model is swapped, provide a hint; # otherwise, the model just hasn't been installed. if not isinstance(f.rel.to, six.string_types) and f.rel.to._meta.swapped: @@ -207,7 +207,7 @@ def get_validation_errors(outfile, app=None): # Check to see if the related m2m field will clash with any # existing fields, m2m fields, m2m related objects or related # objects - if f.rel.to not in app_cache.get_models(): + if f.rel.to not in apps.get_models(): # If the related model is swapped, provide a hint; # otherwise, the model just hasn't been installed. if not isinstance(f.rel.to, six.string_types) and f.rel.to._meta.swapped: @@ -265,7 +265,7 @@ def get_validation_errors(outfile, app=None): ) else: seen_to = True - if f.rel.through not in app_cache.get_models(include_auto_created=True): + if f.rel.through not in apps.get_models(include_auto_created=True): e.add(opts, "'%s' specifies an m2m relation through model " "%s, which has not been installed." % (f.name, f.rel.through)) signature = (f.rel.to, cls, f.rel.through) diff --git a/django/core/serializers/base.py b/django/core/serializers/base.py index d516656a69..70bc651f82 100644 --- a/django/core/serializers/base.py +++ b/django/core/serializers/base.py @@ -3,7 +3,7 @@ Module for abstract serializer/unserializer base classes. """ import warnings -from django.apps import app_cache +from django.apps import apps from django.db import models from django.utils import six @@ -137,9 +137,9 @@ class Deserializer(six.Iterator): self.stream = six.StringIO(stream_or_string) else: self.stream = stream_or_string - # Make sure the app cache is loaded before deserialization starts + # Make sure the app registy is loaded before deserialization starts # (otherwise subclass calls to get_model() and friends might fail...) - app_cache.populate_models() + apps.populate_models() def __iter__(self): return self diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py index c8a2b7eff2..a46adeef7a 100644 --- a/django/core/serializers/python.py +++ b/django/core/serializers/python.py @@ -5,7 +5,7 @@ other serializers. """ from __future__ import unicode_literals -from django.apps import app_cache +from django.apps import apps from django.conf import settings from django.core.serializers import base from django.db import models, DEFAULT_DB_ALIAS @@ -88,7 +88,7 @@ def Deserializer(object_list, **options): db = options.pop('using', DEFAULT_DB_ALIAS) ignore = options.pop('ignorenonexistent', False) - app_cache.populate_models() + apps.populate_models() for d in object_list: # Look up the model and starting build a dict of data for it. @@ -155,7 +155,7 @@ def _get_model(model_identifier): Helper to look up a model from an "app_label.model_name" string. """ try: - Model = app_cache.get_model(*model_identifier.split(".")) + Model = apps.get_model(*model_identifier.split(".")) except TypeError: Model = None if Model is None: diff --git a/django/core/serializers/xml_serializer.py b/django/core/serializers/xml_serializer.py index e9bea84bb1..81e41f8a32 100644 --- a/django/core/serializers/xml_serializer.py +++ b/django/core/serializers/xml_serializer.py @@ -4,7 +4,7 @@ XML serializer. from __future__ import unicode_literals -from django.apps import app_cache +from django.apps import apps from django.conf import settings from django.core.serializers import base from django.db import models, DEFAULT_DB_ALIAS @@ -277,7 +277,7 @@ class Deserializer(base.Deserializer): "<%s> node is missing the required '%s' attribute" % (node.nodeName, attr)) try: - Model = app_cache.get_model(*model_identifier.split(".")) + Model = apps.get_model(*model_identifier.split(".")) except TypeError: Model = None if Model is None: |
