Loading django/apps/cache.py +16 −13 Original line number Diff line number Diff line Loading @@ -189,19 +189,6 @@ class BaseAppCache(object): raise UnavailableApp("App with label %r isn't available." % app_label) return app_config def get_app(self, app_label): """ Returns the module containing the models for the given app_label. Raises UnavailableApp when set_available_apps() in in effect and doesn't include app_label. """ try: return self.get_app_config(app_label).models_module except LookupError as exc: # Change the exception type for backwards compatibility. raise ImproperlyConfigured(*exc.args) def get_models(self, app_mod=None, include_auto_created=False, include_deferred=False, only_installed=True, include_swapped=False): Loading Loading @@ -332,6 +319,22 @@ class BaseAppCache(object): ### DEPRECATED METHODS GO BELOW THIS LINE ### def get_app(self, app_label): """ Returns the module containing the models for the given app_label. Raises UnavailableApp when set_available_apps() in in effect and doesn't include app_label. """ warnings.warn( "get_app_config(app_label).models_module supersedes get_app(app_label).", PendingDeprecationWarning, stacklevel=2) try: return self.get_app_config(app_label).models_module except LookupError as exc: # Change the exception type for backwards compatibility. raise ImproperlyConfigured(*exc.args) def get_apps(self): """ Returns a list of all installed modules that contain models. Loading django/contrib/admindocs/views.py +6 −11 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ from django.conf import settings from django.contrib import admin from django.contrib.admin.views.decorators import staff_member_required from django.db import models from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist from django.core.exceptions import ViewDoesNotExist from django.http import Http404 from django.core import urlresolvers from django.contrib.admindocs import utils Loading Loading @@ -194,17 +194,12 @@ class ModelDetailView(BaseAdminDocsView): def get_context_data(self, **kwargs): # Get the model class. try: app_mod = app_cache.get_app(self.kwargs['app_label']) except ImproperlyConfigured: raise Http404(_("App %r not found") % self.kwargs['app_label']) model = None for m in app_cache.get_models(app_mod): if m._meta.model_name == self.kwargs['model_name']: model = m break app_cache.get_app_config(self.kwargs['app_label']) except LookupError: raise Http404(_("App %(app_label)r not found") % self.kwargs) model = app_cache.get_model(self.kwargs['app_label'], self.kwargs['model_name']) if model is None: raise Http404(_("Model %(model_name)r not found in app %(app_label)r") % { 'model_name': self.kwargs['model_name'], 'app_label': self.kwargs['app_label']}) raise Http404(_("Model %(model_name)r not found in app %(app_label)r") % self.kwargs) opts = model._meta Loading django/contrib/auth/tests/test_management.py +3 −3 Original line number Diff line number Diff line Loading @@ -184,21 +184,21 @@ class CustomUserModelValidationTestCase(TestCase): def test_required_fields_is_list(self): "REQUIRED_FIELDS should be a list." new_io = StringIO() get_validation_errors(new_io, app_cache.get_app('auth')) get_validation_errors(new_io, app_cache.get_app_config('auth').models_module) self.assertIn("The REQUIRED_FIELDS must be a list or tuple.", new_io.getvalue()) @override_settings(AUTH_USER_MODEL='auth.CustomUserBadRequiredFields') def test_username_not_in_required_fields(self): "USERNAME_FIELD should not appear in REQUIRED_FIELDS." new_io = StringIO() get_validation_errors(new_io, app_cache.get_app('auth')) get_validation_errors(new_io, app_cache.get_app_config('auth').models_module) self.assertIn("The field named as the USERNAME_FIELD should not be included in REQUIRED_FIELDS on a swappable User model.", new_io.getvalue()) @override_settings(AUTH_USER_MODEL='auth.CustomUserNonUniqueUsername') def test_username_non_unique(self): "A non-unique USERNAME_FIELD should raise a model validation error." new_io = StringIO() get_validation_errors(new_io, app_cache.get_app('auth')) get_validation_errors(new_io, app_cache.get_app_config('auth').models_module) self.assertIn("The USERNAME_FIELD must be unique. Add unique=True to the field parameters.", new_io.getvalue()) Loading django/core/management/base.py +2 −3 Original line number Diff line number Diff line Loading @@ -11,7 +11,6 @@ import sys from optparse import make_option, OptionParser import django from django.core.exceptions import ImproperlyConfigured from django.core.management.color import color_style, no_style from django.utils.encoding import force_str from django.utils.six import StringIO Loading Loading @@ -346,8 +345,8 @@ class AppCommand(BaseCommand): if not app_labels: raise CommandError('Enter at least one appname.') try: app_list = [app_cache.get_app(app_label) for app_label in app_labels] except (ImproperlyConfigured, ImportError) as e: app_list = [app_cache.get_app_config(app_label).models_module 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 = [] for app in app_list: Loading django/core/management/commands/dumpdata.py +6 −7 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ import warnings from collections import OrderedDict from optparse import make_option from django.core.exceptions import ImproperlyConfigured from django.core.management.base import BaseCommand, CommandError from django.core import serializers from django.db import router, DEFAULT_DB_ALIAS Loading Loading @@ -70,9 +69,9 @@ class Command(BaseCommand): excluded_models.add(model_obj) else: try: app_obj = app_cache.get_app(exclude) app_obj = app_cache.get_app_config(exclude).models_module excluded_apps.add(app_obj) except ImproperlyConfigured: except LookupError: raise CommandError('Unknown app in excludes: %s' % exclude) if len(app_labels) == 0: Loading @@ -89,8 +88,8 @@ class Command(BaseCommand): try: app_label, model_label = label.split('.') try: app = app_cache.get_app(app_label) except ImproperlyConfigured: app = app_cache.get_app_config(app_label).models_module except LookupError: raise CommandError("Unknown application: %s" % app_label) if app in excluded_apps: continue Loading @@ -109,8 +108,8 @@ class Command(BaseCommand): # This is just an app - no model qualifier app_label = label try: app = app_cache.get_app(app_label) except ImproperlyConfigured: app = app_cache.get_app_config(app_label).models_module except LookupError: raise CommandError("Unknown application: %s" % app_label) if app in excluded_apps: continue Loading Loading
django/apps/cache.py +16 −13 Original line number Diff line number Diff line Loading @@ -189,19 +189,6 @@ class BaseAppCache(object): raise UnavailableApp("App with label %r isn't available." % app_label) return app_config def get_app(self, app_label): """ Returns the module containing the models for the given app_label. Raises UnavailableApp when set_available_apps() in in effect and doesn't include app_label. """ try: return self.get_app_config(app_label).models_module except LookupError as exc: # Change the exception type for backwards compatibility. raise ImproperlyConfigured(*exc.args) def get_models(self, app_mod=None, include_auto_created=False, include_deferred=False, only_installed=True, include_swapped=False): Loading Loading @@ -332,6 +319,22 @@ class BaseAppCache(object): ### DEPRECATED METHODS GO BELOW THIS LINE ### def get_app(self, app_label): """ Returns the module containing the models for the given app_label. Raises UnavailableApp when set_available_apps() in in effect and doesn't include app_label. """ warnings.warn( "get_app_config(app_label).models_module supersedes get_app(app_label).", PendingDeprecationWarning, stacklevel=2) try: return self.get_app_config(app_label).models_module except LookupError as exc: # Change the exception type for backwards compatibility. raise ImproperlyConfigured(*exc.args) def get_apps(self): """ Returns a list of all installed modules that contain models. Loading
django/contrib/admindocs/views.py +6 −11 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ from django.conf import settings from django.contrib import admin from django.contrib.admin.views.decorators import staff_member_required from django.db import models from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist from django.core.exceptions import ViewDoesNotExist from django.http import Http404 from django.core import urlresolvers from django.contrib.admindocs import utils Loading Loading @@ -194,17 +194,12 @@ class ModelDetailView(BaseAdminDocsView): def get_context_data(self, **kwargs): # Get the model class. try: app_mod = app_cache.get_app(self.kwargs['app_label']) except ImproperlyConfigured: raise Http404(_("App %r not found") % self.kwargs['app_label']) model = None for m in app_cache.get_models(app_mod): if m._meta.model_name == self.kwargs['model_name']: model = m break app_cache.get_app_config(self.kwargs['app_label']) except LookupError: raise Http404(_("App %(app_label)r not found") % self.kwargs) model = app_cache.get_model(self.kwargs['app_label'], self.kwargs['model_name']) if model is None: raise Http404(_("Model %(model_name)r not found in app %(app_label)r") % { 'model_name': self.kwargs['model_name'], 'app_label': self.kwargs['app_label']}) raise Http404(_("Model %(model_name)r not found in app %(app_label)r") % self.kwargs) opts = model._meta Loading
django/contrib/auth/tests/test_management.py +3 −3 Original line number Diff line number Diff line Loading @@ -184,21 +184,21 @@ class CustomUserModelValidationTestCase(TestCase): def test_required_fields_is_list(self): "REQUIRED_FIELDS should be a list." new_io = StringIO() get_validation_errors(new_io, app_cache.get_app('auth')) get_validation_errors(new_io, app_cache.get_app_config('auth').models_module) self.assertIn("The REQUIRED_FIELDS must be a list or tuple.", new_io.getvalue()) @override_settings(AUTH_USER_MODEL='auth.CustomUserBadRequiredFields') def test_username_not_in_required_fields(self): "USERNAME_FIELD should not appear in REQUIRED_FIELDS." new_io = StringIO() get_validation_errors(new_io, app_cache.get_app('auth')) get_validation_errors(new_io, app_cache.get_app_config('auth').models_module) self.assertIn("The field named as the USERNAME_FIELD should not be included in REQUIRED_FIELDS on a swappable User model.", new_io.getvalue()) @override_settings(AUTH_USER_MODEL='auth.CustomUserNonUniqueUsername') def test_username_non_unique(self): "A non-unique USERNAME_FIELD should raise a model validation error." new_io = StringIO() get_validation_errors(new_io, app_cache.get_app('auth')) get_validation_errors(new_io, app_cache.get_app_config('auth').models_module) self.assertIn("The USERNAME_FIELD must be unique. Add unique=True to the field parameters.", new_io.getvalue()) Loading
django/core/management/base.py +2 −3 Original line number Diff line number Diff line Loading @@ -11,7 +11,6 @@ import sys from optparse import make_option, OptionParser import django from django.core.exceptions import ImproperlyConfigured from django.core.management.color import color_style, no_style from django.utils.encoding import force_str from django.utils.six import StringIO Loading Loading @@ -346,8 +345,8 @@ class AppCommand(BaseCommand): if not app_labels: raise CommandError('Enter at least one appname.') try: app_list = [app_cache.get_app(app_label) for app_label in app_labels] except (ImproperlyConfigured, ImportError) as e: app_list = [app_cache.get_app_config(app_label).models_module 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 = [] for app in app_list: Loading
django/core/management/commands/dumpdata.py +6 −7 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ import warnings from collections import OrderedDict from optparse import make_option from django.core.exceptions import ImproperlyConfigured from django.core.management.base import BaseCommand, CommandError from django.core import serializers from django.db import router, DEFAULT_DB_ALIAS Loading Loading @@ -70,9 +69,9 @@ class Command(BaseCommand): excluded_models.add(model_obj) else: try: app_obj = app_cache.get_app(exclude) app_obj = app_cache.get_app_config(exclude).models_module excluded_apps.add(app_obj) except ImproperlyConfigured: except LookupError: raise CommandError('Unknown app in excludes: %s' % exclude) if len(app_labels) == 0: Loading @@ -89,8 +88,8 @@ class Command(BaseCommand): try: app_label, model_label = label.split('.') try: app = app_cache.get_app(app_label) except ImproperlyConfigured: app = app_cache.get_app_config(app_label).models_module except LookupError: raise CommandError("Unknown application: %s" % app_label) if app in excluded_apps: continue Loading @@ -109,8 +108,8 @@ class Command(BaseCommand): # This is just an app - no model qualifier app_label = label try: app = app_cache.get_app(app_label) except ImproperlyConfigured: app = app_cache.get_app_config(app_label).models_module except LookupError: raise CommandError("Unknown application: %s" % app_label) if app in excluded_apps: continue Loading