Ticket #3591: app_labels.11.diff
File app_labels.11.diff, 32.0 KB (added by , 16 years ago) |
---|
-
django/test/simple.py
63 63 suite.addTest(test_module.suite()) 64 64 else: 65 65 suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(test_module)) 66 try: 66 try: 67 67 suite.addTest(doctest.DocTestSuite(test_module, 68 68 checker=doctestOutputChecker, 69 69 runner=DocTestRunner)) … … 129 129 suite.addTest(build_test(label)) 130 130 else: 131 131 app = get_app(label) 132 suite.addTest(build_suite(app)) 132 mod = app.models_module 133 if mod: 134 suite.addTest(build_suite(mod)) 133 135 else: 134 136 for app in get_apps(): 135 suite.addTest(build_suite(app)) 137 mod = app.models_module 138 if mod: 139 suite.addTest(build_suite(mod)) 136 140 137 141 for test in extra_tests: 138 142 suite.addTest(test) -
django/test/client.py
6 6 except ImportError: 7 7 from StringIO import StringIO 8 8 9 from django.conf import settings 9 from django.conf import settings, get_installed_app_paths 10 10 from django.contrib.auth import authenticate, login 11 11 from django.core.handlers.base import BaseHandler 12 12 from django.core.handlers.wsgi import WSGIRequest … … 169 169 """ 170 170 Obtains the current session variables. 171 171 """ 172 if 'django.contrib.sessions' in settings.INSTALLED_APPS:172 if 'django.contrib.sessions' in get_installed_app_paths(): 173 173 engine = __import__(settings.SESSION_ENGINE, {}, {}, ['']) 174 174 cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None) 175 175 if cookie: … … 294 294 """ 295 295 user = authenticate(**credentials) 296 296 if user and user.is_active \ 297 and 'django.contrib.sessions' in settings.INSTALLED_APPS:297 and 'django.contrib.sessions' in get_installed_app_paths(): 298 298 engine = __import__(settings.SESSION_ENGINE, {}, {}, ['']) 299 299 300 300 # Create a fake request to store login details. -
django/conf/__init__.py
108 108 # of all those apps. 109 109 new_installed_apps = [] 110 110 for app in self.INSTALLED_APPS: 111 if app.endswith('.*'): 111 if not isinstance(app, basestring) or not app.endswith('.*'): 112 new_installed_apps.append(app) 113 else: 112 114 appdir = os.path.dirname(__import__(app[:-2], {}, {}, ['']).__file__) 113 115 app_subdirs = os.listdir(appdir) 114 116 app_subdirs.sort() 115 117 for d in app_subdirs: 116 118 if d.isalpha() and os.path.isdir(os.path.join(appdir, d)): 117 119 new_installed_apps.append('%s.%s' % (app[:-2], d)) 118 else:119 new_installed_apps.append(app)120 120 self.INSTALLED_APPS = new_installed_apps 121 121 122 122 if hasattr(time, 'tzset'): … … 151 151 152 152 settings = LazySettings() 153 153 154 class app(object): 155 """Configuration directive for specifying an app.""" 156 def __init__(self, path, app_label=None, verbose_name=None): 157 self.path = path 158 # if name isn't specified, get the last part of the Python dotted path 159 self.label = app_label or path.split('.')[-1] 160 self.verbose_name = verbose_name or self.label 161 self.app_module = None # will be filled in by loading.py 162 self.models_module = None # will be filled in by loading.py 163 164 def __repr__(self): 165 return "<app: %s>" % self.path 166 167 def get_installed_app_paths(): 168 "Return the paths of all entries in settings.INSTALLED_APPS." 169 rv = [] 170 for a in settings.INSTALLED_APPS: 171 if isinstance(a, basestring): 172 rv.append(a) 173 else: 174 rv.append(a.path) 175 return rv -
django/db/models/base.py
16 16 from django.db.models.options import Options 17 17 from django.db import connection, transaction, DatabaseError 18 18 from django.db.models import signals 19 from django.db.models.loading import register_models, get_model 19 from django.db.models.loading import register_models, get_model, get_app_label 20 20 from django.utils.functional import curry 21 21 from django.utils.encoding import smart_str, force_unicode, smart_unicode 22 22 from django.conf import settings … … 69 69 70 70 if getattr(new_class, '_default_manager', None): 71 71 new_class._default_manager = None 72 if getattr(new_class._meta, 'app_label', None) is None: 73 # Figure out the app_label. 74 new_class._meta.app_label = get_app_label(new_class) 72 75 73 76 # Bail out early if we have already created this class. 74 77 m = get_model(new_class._meta.app_label, name, False) -
django/db/models/options.py
5 5 except NameError: 6 6 from sets import Set as set # Python 2.3 fallback 7 7 8 from django.conf import settings 8 from django.conf import settings, get_installed_app_paths 9 9 from django.db.models.related import RelatedObject 10 10 from django.db.models.fields.related import ManyToManyRel 11 11 from django.db.models.fields import AutoField, FieldDoesNotExist … … 54 54 from django.db.backends.util import truncate_name 55 55 56 56 cls._meta = self 57 self.installed = re.sub('\.models$', '', cls.__module__) in settings.INSTALLED_APPS57 self.installed = re.sub('\.models$', '', cls.__module__) in get_installed_app_paths() 58 58 # First, construct the default values for these options. 59 59 self.object_name = cls.__name__ 60 60 self.module_name = self.object_name.lower() -
django/db/models/loading.py
1 1 "Utilities for loading models and the modules that contain them." 2 2 3 from django.conf import settings 3 from django.conf import settings, app 4 4 from django.core.exceptions import ImproperlyConfigured 5 5 from django.utils.datastructures import SortedDict 6 6 7 7 import sys 8 import os 8 import os, os.path 9 9 import threading 10 10 11 11 __all__ = ('get_apps', 'get_app', 'get_models', 'get_model', 'register_models', 12 'load_app', 'app_cache_ready' )12 'load_app', 'app_cache_ready', 'find_app') 13 13 14 14 class AppCache(object): 15 15 """ … … 28 28 # Mapping of app_labels to errors raised when trying to import the app. 29 29 app_errors = {}, 30 30 31 32 # Mapping of app_labels to app instances. 33 app_map = {}, 34 35 # Mapping of app module names to app instances. 36 mod_map = {}, 37 38 # List of app instances. 39 app_instances = [], 40 31 41 # -- Everything below here is only used when populating the cache -- 32 42 loaded = False, 33 43 handled = {}, … … 51 61 try: 52 62 if self.loaded: 53 63 return 54 for app_name in settings.INSTALLED_APPS: 64 # We first loop through, setting up the app instances and 65 # the relevant maps so that we can find the instances by app_label 66 # or app module name. These need to be ready because we need to be 67 # able to get the app_label e.g. for applying to model classes. 68 # If a model class is loaded indirectly without being in an 69 # installed app, the app_label used will be what it is now - the 70 # last part of the app module name. 71 # Note that app_map and mod_map will contain entries even 72 # when an app cannot be loaded by load_app. 73 for app_entry in settings.INSTALLED_APPS: 74 if isinstance(app_entry, basestring): 75 the_app = app(app_entry) 76 else: 77 the_app = app_entry 78 self.app_map[the_app.label] = the_app 79 self.mod_map[the_app.path] = the_app 80 81 for app_entry in settings.INSTALLED_APPS: 82 if isinstance(app_entry, basestring): 83 the_app = self.mod_map[app_entry] 84 else: 85 the_app = app_entry 86 app_name = the_app.path 55 87 if app_name in self.handled: 56 88 continue 57 self.load_app(app_name, True) 89 try: 90 self.load_app(app_name, True) 91 self.app_instances.append(the_app) 92 except Exception, e: 93 # Problem importing the app 94 self.app_errors[app_name] = e 58 95 if not self.nesting_level: 59 96 for app_name in self.postponed: 97 the_app = self.mod_map[app_name] 60 98 self.load_app(app_name) 99 self.app_instances.append(the_app) 61 100 self.loaded = True 62 101 finally: 63 102 self.write_lock.release() … … 71 110 self.nesting_level += 1 72 111 mod = __import__(app_name, {}, {}, ['models']) 73 112 self.nesting_level -= 1 113 if app_name in self.mod_map: 114 the_app = self.mod_map[app_name] 115 else: 116 # An app can be loaded by load_app even before get_apps is 117 # called. In this case, we just make a new app and add it to the maps. 118 the_app = app(app_name) 119 self.app_map[the_app.label] = the_app 120 self.mod_map[app_name] = the_app 121 self.app_instances.append(the_app) 122 the_app.app_module = mod 74 123 if not hasattr(mod, 'models'): 75 124 if can_postpone: 76 125 # Either the app has no models, or the package is still being … … 78 127 # We will check again once all the recursion has finished (in 79 128 # populate). 80 129 self.postponed.append(app_name) 81 return None 82 if mod.models not in self.app_store: 83 self.app_store[mod.models] = len(self.app_store) 84 return mod.models 130 rv = None 131 else: 132 rv = mod.models 133 if rv not in self.app_store: 134 self.app_store[rv] = len(self.app_store) 135 the_app.models_module = rv 136 return rv 85 137 86 138 def app_cache_ready(self): 87 139 """ … … 101 153 # list page, for example. 102 154 apps = [(v, k) for k, v in self.app_store.items()] 103 155 apps.sort() 104 return [elt[1] for elt in apps] 156 #return [elt[1] for elt in apps] 157 return self.app_instances 105 158 159 def get_app_label(self, model_class): 160 "Returns the app label to be used for a model class." 161 key = model_class.__module__ 162 i = key.rfind('.') 163 assert i > 0, "Model class must be defined in a package sub-module" 164 key = key[:i] 165 if key in self.mod_map: 166 rv = self.mod_map[key].label 167 else: 168 i = key.rfind('.') 169 if i < 0: 170 rv = key 171 else: 172 rv = key[i + 1:] 173 return rv 174 175 def find_app(self, app_path): 176 "Find an app instance, given the application path." 177 self._populate() 178 return self.mod_map[app_path] 179 106 180 def get_app(self, app_label, emptyOK=False): 107 181 """ 108 Returns the module containing the modelsfor the given app_label. If182 Returns the app instance for the given app_label. If 109 183 the app has no models in it and 'emptyOK' is True, returns None. 110 184 """ 111 185 self._populate() 112 self.write_lock.acquire() 113 try: 114 for app_name in settings.INSTALLED_APPS: 115 if app_label == app_name.split('.')[-1]: 116 mod = self.load_app(app_name, False) 117 if mod is None: 118 if emptyOK: 119 return None 120 else: 121 return mod 122 raise ImproperlyConfigured, "App with label %s could not be found" % app_label 123 finally: 124 self.write_lock.release() 186 if app_label not in self.app_map: 187 rv = None 188 else: 189 rv = self.app_map[app_label] 190 if emptyOK or rv is not None: 191 return rv 192 raise ImproperlyConfigured, "App with label %s could not be found" % app_label 125 193 126 194 def get_app_errors(self): 127 195 "Returns the map of known problems with the INSTALLED_APPS." 128 196 self._populate() 129 197 return self.app_errors 130 198 131 def get_models(self, app_mod=None):199 def get_models(self, the_app=None): 132 200 """ 133 Given a module containing models, returns a list of themodels.201 Given an app instance, returns a list of its models. 134 202 Otherwise returns a list of all installed models. 135 203 """ 136 204 self._populate() 137 if app_mod:138 return self.app_models.get( app_mod.__name__.split('.')[-2], SortedDict()).values()205 if the_app: 206 return self.app_models.get(the_app.label, SortedDict()).values() 139 207 else: 140 208 model_list = [] 141 for app_entry in self.app_models.itervalues():142 model_list.extend( app_entry.values())209 for the_app in self.app_instances: 210 model_list.extend(get_models(the_app)) 143 211 return model_list 144 212 145 213 def get_model(self, app_label, model_name, seed_cache=True): … … 187 255 register_models = cache.register_models 188 256 load_app = cache.load_app 189 257 app_cache_ready = cache.app_cache_ready 258 find_app = cache.find_app 259 get_app_label = cache.get_app_label -
django/db/models/__init__.py
1 1 from django.conf import settings 2 2 from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured 3 3 from django.db import connection 4 from django.db.models.loading import get_apps, get_app, get_models, get_model, register_models 4 from django.db.models.loading import get_apps, get_app, get_models, get_model, register_models, find_app 5 5 from django.db.models.query import Q 6 6 from django.db.models.manager import Manager 7 7 from django.db.models.base import Model -
django/core/management/commands/loaddata.py
52 52 transaction.enter_transaction_management() 53 53 transaction.managed(True) 54 54 55 app_fixtures = [os.path.join(os.path.dirname(app. __file__), 'fixtures') for app in get_apps()]55 app_fixtures = [os.path.join(os.path.dirname(app.app_module.__file__), 'fixtures') for app in get_apps() if app.app_module] 56 56 for fixture_label in fixture_labels: 57 57 parts = fixture_label.split('.') 58 58 if len(parts) == 1: -
django/core/management/commands/flush.py
1 from django.conf import get_installed_app_paths 1 2 from django.core.management.base import NoArgsCommand, CommandError 2 3 from django.core.management.color import no_style 3 4 from optparse import make_option … … 21 22 22 23 # Import the 'management' module within each installed app, to register 23 24 # dispatcher events. 24 for app_name in settings.INSTALLED_APPS:25 for app_name in get_installed_app_paths(): 25 26 try: 26 27 __import__(app_name + '.management', {}, {}, ['']) 27 28 except ImportError: -
django/core/management/commands/syncdb.py
1 from django.conf import get_installed_app_paths 1 2 from django.core.management.base import NoArgsCommand 2 3 from django.core.management.color import no_style 3 4 from optparse import make_option … … 28 29 29 30 # Import the 'management' module within each installed app, to register 30 31 # dispatcher events. 31 for app_name in settings.INSTALLED_APPS:32 for app_name in get_installed_app_paths(): 32 33 try: 33 34 __import__(app_name + '.management', {}, {}, ['']) 34 35 except ImportError, exc: … … 55 56 56 57 # Create the tables for each model 57 58 for app in models.get_apps(): 58 app_name = app. __name__.split('.')[-2]59 app_name = app.label 59 60 model_list = models.get_models(app) 60 61 for model in model_list: 61 62 # Create the model's database table, if it doesn't already exist. … … 80 81 # Create the m2m tables. This must be done after all tables have been created 81 82 # to ensure that all referred tables will exist. 82 83 for app in models.get_apps(): 83 app_name = app. __name__.split('.')[-2]84 app_name = app.label 84 85 model_list = models.get_models(app) 85 86 for model in model_list: 86 87 if model in created_models: … … 103 104 # Install custom SQL for the app (but only if this 104 105 # is a model we've just created) 105 106 for app in models.get_apps(): 106 app_name = app. __name__.split('.')[-2]107 app_name = app.label 107 108 for model in models.get_models(app): 108 109 if model in created_models: 109 110 custom_sql = custom_sql_for_model(model, self.style) … … 127 128 print "No custom SQL for %s.%s model" % (app_name, model._meta.object_name) 128 129 # Install SQL indicies for all newly created models 129 130 for app in models.get_apps(): 130 app_name = app. __name__.split('.')[-2]131 app_name = app.label 131 132 for model in models.get_models(app): 132 133 if model in created_models: 133 134 index_sql = connection.creation.sql_indexes_for_model(model, self.style) -
django/core/management/__init__.py
96 96 97 97 # Find the installed apps 98 98 try: 99 from django.conf import settings 100 apps = settings.INSTALLED_APPS99 from django.conf import settings, get_installed_app_paths 100 apps = get_installed_app_paths() 101 101 except (AttributeError, EnvironmentError, ImportError): 102 102 apps = [] 103 103 -
django/core/management/sql.py
137 137 output = [] 138 138 139 139 app_models = get_models(app) 140 app_dir = os.path.normpath(os.path.join(os.path.dirname(app. __file__), 'sql'))140 app_dir = os.path.normpath(os.path.join(os.path.dirname(app.app_module.__file__), 'sql')) 141 141 142 142 for model in app_models: 143 143 output.extend(custom_sql_for_model(model, style)) … … 161 161 from django.conf import settings 162 162 163 163 opts = model._meta 164 app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label). __file__), 'sql'))164 app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).app_module.__file__), 'sql')) 165 165 output = [] 166 166 167 167 # Post-creation SQL should come before any initial SQL data is loaded. … … 197 197 from django.dispatch import dispatcher 198 198 # Emit the post_sync signal for every application. 199 199 for app in models.get_apps(): 200 app_name = app. __name__.split('.')[-2]200 app_name = app.label 201 201 if verbosity >= 2: 202 202 print "Running post-sync handlers for application", app_name 203 203 models.signals.post_syncdb.send(sender=app, app=app, -
django/templatetags/__init__.py
1 from django.conf import settings 1 from django.conf import settings, get_installed_app_paths 2 2 3 for a in settings.INSTALLED_APPS:3 for a in get_installed_app_paths(): 4 4 try: 5 5 __path__.extend(__import__(a + '.templatetags', {}, {}, ['']).__path__) 6 6 except ImportError: -
django/views/i18n.py
1 1 from django import http 2 2 from django.utils.translation import check_for_language, activate, to_locale, get_language 3 3 from django.utils.text import javascript_quote 4 from django.conf import settings 4 from django.conf import settings, get_installed_app_paths 5 5 import os 6 6 import gettext as gettext_module 7 7 … … 121 121 packages = ['django.conf'] 122 122 if type(packages) in (str, unicode): 123 123 packages = packages.split('+') 124 packages = [p for p in packages if p == 'django.conf' or p in settings.INSTALLED_APPS]124 packages = [p for p in packages if p == 'django.conf' or p in get_installed_app_paths()] 125 125 default_locale = to_locale(settings.LANGUAGE_CODE) 126 126 locale = to_locale(get_language()) 127 127 t = {} -
django/utils/translation/trans_real.py
114 114 if t is not None: 115 115 return t 116 116 117 from django.conf import settings 117 from django.conf import settings, get_installed_app_paths 118 118 119 119 # set up the right translation class 120 120 klass = DjangoTranslation … … 175 175 if projectpath and os.path.isdir(projectpath): 176 176 res = _merge(projectpath) 177 177 178 for appname in settings.INSTALLED_APPS:178 for appname in get_installed_app_paths(): 179 179 p = appname.rfind('.') 180 180 if p >= 0: 181 181 app = getattr(__import__(appname[:p], {}, {}, [appname[p+1:]]), appname[p+1:]) -
django/contrib/comments/__init__.py
1 from django.conf import settings 1 from django.conf import settings, get_installed_app_paths 2 2 from django.core import urlresolvers 3 3 from django.core.exceptions import ImproperlyConfigured 4 4 … … 11 11 """ 12 12 # Make sure the app's in INSTALLED_APPS 13 13 comments_app = get_comment_app_name() 14 if comments_app not in settings.INSTALLED_APPS:14 if comments_app not in get_installed_app_paths(): 15 15 raise ImproperlyConfigured("The COMMENTS_APP (%r) "\ 16 16 "must be in INSTALLED_APPS" % settings.COMMENTS_APP) 17 17 -
django/contrib/sites/management.py
2 2 Creates the default Site object. 3 3 """ 4 4 5 from django.db.models import signals 5 from django.db.models import signals, find_app 6 6 from django.contrib.sites.models import Site 7 from django.contrib.sites import models as site_app8 7 9 8 def create_default_site(app, created_models, verbosity, **kwargs): 10 9 if Site in created_models: … … 14 13 s.save() 15 14 Site.objects.clear_cache() 16 15 17 signals.post_syncdb.connect(create_default_site, sender= site_app)16 signals.post_syncdb.connect(create_default_site, sender=find_app('django.contrib.sites')) -
django/contrib/admin/__init__.py
9 9 may want. 10 10 """ 11 11 import imp 12 from django.conf import settings 12 from django.conf import settings, get_installed_app_paths 13 13 14 for app in settings.INSTALLED_APPS:14 for app in get_installed_app_paths(): 15 15 # For each app, we need to look for an admin.py inside that app's 16 16 # package. We can't use os.path here -- recall that modules may be 17 17 # imported different ways (think zip files) -- so we need to get -
django/contrib/contenttypes/management.py
8 8 entries that no longer have a matching model class. 9 9 """ 10 10 ContentType.objects.clear_cache() 11 content_types = list(ContentType.objects.filter(app_label=app. __name__.split('.')[-2]))11 content_types = list(ContentType.objects.filter(app_label=app.label)) 12 12 app_models = get_models(app) 13 13 if not app_models: 14 14 return -
django/template/loaders/app_directories.py
5 5 6 6 import os 7 7 8 from django.conf import settings 8 from django.conf import settings, get_installed_app_paths 9 9 from django.core.exceptions import ImproperlyConfigured 10 10 from django.template import TemplateDoesNotExist 11 11 from django.utils._os import safe_join 12 12 13 13 # At compile time, cache the directories to search. 14 14 app_template_dirs = [] 15 for app in settings.INSTALLED_APPS:15 for app in get_installed_app_paths(): 16 16 i = app.rfind('.') 17 17 if i == -1: 18 18 m, a = app, None -
django/template/loaders/eggs.py
6 6 resource_string = None 7 7 8 8 from django.template import TemplateDoesNotExist 9 from django.conf import settings 9 from django.conf import settings, get_installed_app_paths 10 10 11 11 def load_template_source(template_name, template_dirs=None): 12 12 """ … … 16 16 """ 17 17 if resource_string is not None: 18 18 pkg_name = 'templates/' + template_name 19 for app in settings.INSTALLED_APPS:19 for app in get_installed_app_paths(): 20 20 try: 21 21 return (resource_string(app, pkg_name).decode(settings.FILE_CHARSET), 'egg:%s:%s' % (app, pkg_name)) 22 22 except: -
tests/regressiontests/admin_scripts/tests.py
969 969 args = ['app_command', 'auth'] 970 970 out, err = self.run_manage(args) 971 971 self.assertNoOutput(err) 972 self.assertOutput(out, "EXECUTE:AppCommand app=< module 'django.contrib.auth.models'")973 self.assertOutput(out, os.sep.join(['django','contrib','auth','models.py']))974 self.assertOutput(out, " '>, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")972 self.assertOutput(out, "EXECUTE:AppCommand app=<app: django.contrib.auth>") 973 #self.assertOutput(out, os.sep.join(['django','contrib','auth','models.py'])) 974 self.assertOutput(out, ">, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]") 975 975 976 976 def test_app_command_no_apps(self): 977 977 "User AppCommands raise an error when no app name is provided" … … 984 984 args = ['app_command','auth','contenttypes'] 985 985 out, err = self.run_manage(args) 986 986 self.assertNoOutput(err) 987 self.assertOutput(out, "EXECUTE:AppCommand app=< module 'django.contrib.auth.models'")988 self.assertOutput(out, os.sep.join(['django','contrib','auth','models.py']))989 self.assertOutput(out, " '>, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")990 self.assertOutput(out, "EXECUTE:AppCommand app=< module 'django.contrib.contenttypes.models'")991 self.assertOutput(out, os.sep.join(['django','contrib','contenttypes','models.py']))992 self.assertOutput(out, " '>, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")987 self.assertOutput(out, "EXECUTE:AppCommand app=<app: django.contrib.auth>") 988 #self.assertOutput(out, os.sep.join(['django','contrib','auth','models.py'])) 989 self.assertOutput(out, ">, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]") 990 self.assertOutput(out, "EXECUTE:AppCommand app=<app: django.contrib.contenttypes>") 991 #self.assertOutput(out, os.sep.join(['django','contrib','contenttypes','models.py'])) 992 self.assertOutput(out, ">, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]") 993 993 994 994 def test_app_command_invalid_appname(self): 995 995 "User AppCommands can execute when a single app name is provided" -
tests/runtests.py
2 2 3 3 import os, sys, traceback 4 4 import unittest 5 from django.conf import app, get_installed_app_paths 5 6 6 7 import django.contrib as contrib 7 8 … … 23 24 24 25 ALWAYS_INSTALLED_APPS = [ 25 26 'django.contrib.contenttypes', 26 'django.contrib.auth', 27 #We need to use the same app label, otherwise fixtures will break... 28 app('django.contrib.auth', 'auth', 'Authentication'), 27 29 'django.contrib.sites', 28 30 'django.contrib.flatpages', 29 31 'django.contrib.redirects', … … 58 60 59 61 def runTest(self): 60 62 from django.core.management.validation import get_validation_errors 61 from django.db.models.loading import load_app 63 from django.db.models.loading import load_app, find_app 62 64 from cStringIO import StringIO 63 65 64 66 try: 65 67 module = load_app(self.model_label) 68 app = find_app(self.model_label) 66 69 except Exception, e: 67 self.fail('Unable to load invalid model module')70 self.fail('Unable to load invalid application %s: %s' % (self.model_label, e)) 68 71 69 72 # Make sure sys.stdout is not a tty so that we get errors without 70 73 # coloring attached (makes matching the results easier). We restore … … 72 75 orig_stdout = sys.stdout 73 76 s = StringIO() 74 77 sys.stdout = s 75 count = get_validation_errors(s, module)78 count = get_validation_errors(s, app) 76 79 sys.stdout = orig_stdout 77 80 s.seek(0) 78 81 error_log = s.read() … … 129 132 print "Importing model %s" % model_name 130 133 mod = load_app(model_label) 131 134 if mod: 132 if model_label not in settings.INSTALLED_APPS:135 if model_label not in get_installed_app_paths(): 133 136 settings.INSTALLED_APPS.append(model_label) 134 137 except Exception, e: 135 138 sys.stderr.write("Error while importing %s:" % model_name + ''.join(traceback.format_exception(*sys.exc_info())[1:]))