Ticket #3591: app_labels.8.diff
File app_labels.8.diff, 35.1 KB (added by , 17 years ago) |
---|
-
django/test/simple.py
64 64 suite.addTest(test_module.suite()) 65 65 else: 66 66 suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(test_module)) 67 try: 67 try: 68 68 suite.addTest(doctest.DocTestSuite(test_module, 69 69 checker=doctestOutputChecker, 70 70 runner=DocTestRunner)) … … 130 130 suite.addTest(build_test(label)) 131 131 else: 132 132 app = get_app(label) 133 suite.addTest(build_suite(app)) 133 mod = app.models_module 134 if mod: 135 suite.addTest(build_suite(mod)) 134 136 else: 135 137 for app in get_apps(): 136 suite.addTest(build_suite(app)) 138 mod = app.models_module 139 if mod: 140 suite.addTest(build_suite(mod)) 137 141 138 142 for test in extra_tests: 139 143 suite.addTest(test) -
django/test/client.py
2 2 import sys 3 3 from cStringIO import StringIO 4 4 from urlparse import urlparse 5 from django.conf import settings 5 from django.conf import settings, get_installed_app_paths 6 6 from django.contrib.auth import authenticate, login 7 7 from django.core.handlers.base import BaseHandler 8 8 from django.core.handlers.wsgi import WSGIRequest … … 129 129 130 130 def _session(self): 131 131 "Obtain the current session variables" 132 if 'django.contrib.sessions' in settings.INSTALLED_APPS:132 if 'django.contrib.sessions' in get_installed_app_paths(): 133 133 engine = __import__(settings.SESSION_ENGINE, {}, {}, ['']) 134 134 cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None) 135 135 if cookie: … … 245 245 not available. 246 246 """ 247 247 user = authenticate(**credentials) 248 if user and user.is_active and 'django.contrib.sessions' in settings.INSTALLED_APPS:248 if user and user.is_active and 'django.contrib.sessions' in get_installed_app_paths(): 249 249 engine = __import__(settings.SESSION_ENGINE, {}, {}, ['']) 250 250 251 251 # Create a fake request to store login details -
django/db/models/base.py
8 8 from django.db.models.options import Options, AdminOptions 9 9 from django.db import connection, transaction 10 10 from django.db.models import signals 11 from django.db.models.loading import register_models, get_model 11 from django.db.models.loading import register_models, get_model, get_app_label 12 12 from django.dispatch import dispatcher 13 13 from django.utils.datastructures import SortedDict 14 14 from django.utils.functional import curry … … 43 43 new_class._meta.parents.append(base) 44 44 new_class._meta.parents.extend(base._meta.parents) 45 45 46 47 46 if getattr(new_class._meta, 'app_label', None) is None: 48 # Figure out the app_label by looking one level up. 49 # For 'django.contrib.sites.models', this would be 'sites'. 50 model_module = sys.modules[new_class.__module__] 51 new_class._meta.app_label = model_module.__name__.split('.')[-2] 47 # Figure out the app_label. 48 new_class._meta.app_label = get_app_label(new_class) 52 49 53 50 # Bail out early if we have already created this class. 54 51 m = get_model(new_class._meta.app_label, name, False) -
django/db/models/options.py
1 from django.conf import settings 1 from django.conf import settings, get_installed_app_paths 2 2 from django.db.models.related import RelatedObject 3 3 from django.db.models.fields.related import ManyToManyRel 4 4 from django.db.models.fields import AutoField, FieldDoesNotExist … … 39 39 40 40 def contribute_to_class(self, cls, name): 41 41 cls._meta = self 42 self.installed = re.sub('\.models$', '', cls.__module__) in settings.INSTALLED_APPS42 self.installed = re.sub('\.models$', '', cls.__module__) in get_installed_app_paths() 43 43 # First, construct the default values for these options. 44 44 self.object_name = cls.__name__ 45 45 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 import sys 6 6 import os 7 7 import threading 8 8 9 9 __all__ = ('get_apps', 'get_app', 'get_models', 'get_model', 'register_models', 10 'load_app', 'app_cache_ready' )10 'load_app', 'app_cache_ready', 'find_app') 11 11 12 12 class AppCache(object): 13 13 """ … … 18 18 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531. 19 19 __shared_state = dict( 20 20 # Keys of app_store are the model modules for each application. 21 # Values are integers indicating the order of loading. 21 22 app_store = {}, 22 23 23 24 # Mapping of app_labels to a dictionary of model names to model code. … … 26 27 # Mapping of app_labels to errors raised when trying to import the app. 27 28 app_errors = {}, 28 29 30 31 # Mapping of app_labels to app instances. 32 app_map = {}, 33 34 # Mapping of app module names to app instances. 35 mod_map = {}, 36 37 # List of app instances. 38 app_instances = [], 39 29 40 # -- Everything below here is only used when populating the cache -- 30 41 loaded = False, 31 42 handled = {}, … … 49 60 try: 50 61 if self.loaded: 51 62 return 52 for app_name in settings.INSTALLED_APPS: 63 # We first loop through, setting up the app instances and 64 # the relevant maps so that we can find the instances by app_label 65 # or app module name. These need to be ready because we need to be 66 # able to get the app_label e.g. for applying to model classes. 67 # If a model class is loaded indirectly without being in an 68 # installed app, the app_label used will be what it is now - the 69 # last part of the app module name. 70 # Note that app_map and mod_map will contain entries even 71 # when an app cannot be loaded by load_app. 72 for app_entry in settings.INSTALLED_APPS: 73 if isinstance(app_entry, basestring): 74 the_app = app(app_entry) 75 else: 76 the_app = app_entry 77 self.app_map[the_app.label] = the_app 78 self.mod_map[the_app.path] = the_app 79 80 for app_entry in settings.INSTALLED_APPS: 81 if isinstance(app_entry, basestring): 82 the_app = self.mod_map[app_entry] 83 else: 84 the_app = app_entry 85 app_name = the_app.path 53 86 if app_name in self.handled: 54 87 continue 55 self.load_app(app_name, True) 88 try: 89 self.load_app(app_name, True) 90 self.app_instances.append(the_app) 91 except Exception, e: 92 # Problem importing the app 93 self.app_errors[app_name] = e 56 94 if not self.nesting_level: 57 95 for app_name in self.postponed: 96 the_app = self.mod_map[app_name] 58 97 self.load_app(app_name) 98 self.app_instances.append(the_app) 59 99 self.loaded = True 60 100 finally: 61 101 self.write_lock.release() … … 69 109 self.nesting_level += 1 70 110 mod = __import__(app_name, {}, {}, ['models']) 71 111 self.nesting_level -= 1 112 if app_name in self.mod_map: 113 the_app = self.mod_map[app_name] 114 else: 115 # An app can be loaded by load_app even before get_apps is 116 # called. In this case, we just make a new app and add it to the maps. 117 the_app = app(app_name) 118 self.app_map[the_app.label] = the_app 119 self.mod_map[app_name] = the_app 120 self.app_instances.append(the_app) 121 the_app.app_module = mod 72 122 if not hasattr(mod, 'models'): 73 123 if can_postpone: 74 124 # Either the app has no models, or the package is still being … … 76 126 # We will check again once all the recursion has finished (in 77 127 # populate). 78 128 self.postponed.append(app_name) 79 return None 80 if mod.models not in self.app_store: 81 self.app_store[mod.models] = len(self.app_store) 82 return mod.models 129 rv = None 130 else: 131 rv = mod.models 132 if rv not in self.app_store: 133 self.app_store[rv] = len(self.app_store) 134 the_app.models_module = rv 135 return rv 83 136 84 137 def app_cache_ready(self): 85 138 """ … … 99 152 # list page, for example. 100 153 apps = [(v, k) for k, v in self.app_store.items()] 101 154 apps.sort() 102 return [elt[1] for elt in apps] 155 #return [elt[1] for elt in apps] 156 return self.app_instances 103 157 158 def get_app_label(self, model_class): 159 "Returns the app label to be used for a model class." 160 key = model_class.__module__ 161 i = key.rfind('.') 162 assert i > 0, "Model class must be defined in a package sub-module" 163 key = key[:i] 164 if key in self.mod_map: 165 rv = self.mod_map[key].label 166 else: 167 i = key.rfind('.') 168 if i < 0: 169 rv = key 170 else: 171 rv = key[i + 1:] 172 return rv 173 174 def find_app(self, app_path): 175 "Find an app instance, given the application path." 176 self._populate() 177 return self.mod_map[app_path] 178 104 179 def get_app(self, app_label, emptyOK=False): 105 180 """ 106 Returns the module containing the modelsfor the given app_label. If181 Returns the app instance for the given app_label. If 107 182 the app has no models in it and 'emptyOK' is True, returns None. 108 183 """ 109 184 self._populate() 110 self.write_lock.acquire() 111 try: 112 for app_name in settings.INSTALLED_APPS: 113 if app_label == app_name.split('.')[-1]: 114 mod = self.load_app(app_name, False) 115 if mod is None: 116 if emptyOK: 117 return None 118 else: 119 return mod 120 raise ImproperlyConfigured, "App with label %s could not be found" % app_label 121 finally: 122 self.write_lock.release() 185 if app_label not in self.app_map: 186 rv = None 187 else: 188 rv = self.app_map[app_label] 189 if emptyOK or rv is not None: 190 return rv 191 raise ImproperlyConfigured, "App with label %s could not be found" % app_label 123 192 124 193 def get_app_errors(self): 125 194 "Returns the map of known problems with the INSTALLED_APPS." 126 195 self._populate() 127 196 return self.app_errors 128 197 129 def get_models(self, app_mod=None):198 def get_models(self, the_app=None): 130 199 """ 131 Given a module containing models, returns a list of themodels.200 Given an app instance, returns a list of its models. 132 201 Otherwise returns a list of all installed models. 133 202 """ 134 203 self._populate() 135 if app_mod:136 return self.app_models.get( app_mod.__name__.split('.')[-2], {}).values()204 if the_app: 205 return self.app_models.get(the_app.label, {}).values() 137 206 else: 138 207 model_list = [] 139 for app_entry in self.app_models.itervalues():140 model_list.extend( app_entry.values())208 for the_app in self.app_instances: 209 model_list.extend(get_models(the_app)) 141 210 return model_list 142 211 143 212 def get_model(self, app_label, model_name, seed_cache=True): … … 185 254 register_models = cache.register_models 186 255 load_app = cache.load_app 187 256 app_cache_ready = cache.app_cache_ready 257 find_app = cache.find_app 258 get_app_label = cache.get_app_label -
django/db/models/__init__.py
2 2 from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured 3 3 from django.core import validators 4 4 from django.db import connection 5 from django.db.models.loading import get_apps, get_app, get_models, get_model, register_models 5 from django.db.models.loading import get_apps, get_app, get_models, get_model, register_models, find_app 6 6 from django.db.models.query import Q 7 7 from django.db.models.manager import Manager 8 8 from django.db.models.base import Model, AdminOptions -
django/conf/__init__.py
99 99 # of all those apps. 100 100 new_installed_apps = [] 101 101 for app in self.INSTALLED_APPS: 102 if app.endswith('.*'): 102 if not isinstance(app, basestring) or not app.endswith('.*'): 103 new_installed_apps.append(app) 104 else: 103 105 appdir = os.path.dirname(__import__(app[:-2], {}, {}, ['']).__file__) 104 106 for d in os.listdir(appdir): 105 107 if d.isalpha() and os.path.isdir(os.path.join(appdir, d)): 106 108 new_installed_apps.append('%s.%s' % (app[:-2], d)) 107 else:108 new_installed_apps.append(app)109 109 self.INSTALLED_APPS = new_installed_apps 110 110 111 111 if hasattr(time, 'tzset'): … … 140 140 141 141 settings = LazySettings() 142 142 143 class app(object): 144 """Configuration directive for specifying an app.""" 145 def __init__(self, path, app_label=None, verbose_name=None): 146 self.path = path 147 # if name isn't specified, get the last part of the Python dotted path 148 self.label = app_label or path.split('.')[-1] 149 self.verbose_name = verbose_name or self.label 150 self.app_module = None # will be filled in by loading.py 151 self.models_module = None # will be filled in by loading.py 152 153 def __repr__(self): 154 return "<app: %s>" % self.path 155 156 def get_installed_app_paths(): 157 "Return the paths of all entries in settings.INSTALLED_APPS." 158 rv = [] 159 for a in settings.INSTALLED_APPS: 160 if isinstance(a, basestring): 161 rv.append(a) 162 else: 163 rv.append(a.path) 164 return rv -
django/core/management/commands/loaddata.py
45 45 transaction.enter_transaction_management() 46 46 transaction.managed(True) 47 47 48 app_fixtures = [os.path.join(os.path.dirname(app. __file__), 'fixtures') for app in get_apps()]48 app_fixtures = [os.path.join(os.path.dirname(app.models_module.__file__), 'fixtures') for app in get_apps() if app.models_module] 49 49 for fixture_label in fixture_labels: 50 50 parts = fixture_label.split('.') 51 51 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 … … 25 26 26 27 # Import the 'management' module within each installed app, to register 27 28 # dispatcher events. 28 for app_name in settings.INSTALLED_APPS:29 for app_name in get_installed_app_paths(): 29 30 try: 30 31 __import__(app_name + '.management', {}, {}, ['']) 31 32 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 … … 30 31 31 32 # Import the 'management' module within each installed app, to register 32 33 # dispatcher events. 33 for app_name in settings.INSTALLED_APPS:34 for app_name in get_installed_app_paths(): 34 35 try: 35 36 __import__(app_name + '.management', {}, {}, ['']) 36 37 except ImportError: … … 53 54 54 55 # Create the tables for each model 55 56 for app in models.get_apps(): 56 app_name = app. __name__.split('.')[-2]57 app_name = app.label 57 58 model_list = models.get_models(app) 58 59 for model in model_list: 59 60 # Create the model's database table, if it doesn't already exist. … … 76 77 # Create the m2m tables. This must be done after all tables have been created 77 78 # to ensure that all referred tables will exist. 78 79 for app in models.get_apps(): 79 app_name = app. __name__.split('.')[-2]80 app_name = app.label 80 81 model_list = models.get_models(app) 81 82 for model in model_list: 82 83 if model in created_models: … … 96 97 # Install custom SQL for the app (but only if this 97 98 # is a model we've just created) 98 99 for app in models.get_apps(): 99 app_name = app. __name__.split('.')[-2]100 app_name = app.label 100 101 for model in models.get_models(app): 101 102 if model in created_models: 102 103 custom_sql = custom_sql_for_model(model) … … 115 116 116 117 # Install SQL indicies for all newly created models 117 118 for app in models.get_apps(): 118 app_name = app. __name__.split('.')[-2]119 app_name = app.label 119 120 for model in models.get_models(app): 120 121 if model in created_models: 121 122 index_sql = sql_indexes_for_model(model, self.style) -
django/core/management/__init__.py
4 4 from imp import find_module 5 5 6 6 import django 7 from django.conf import get_installed_app_paths 7 8 from django.core.management.base import BaseCommand, CommandError, handle_default_options 8 9 9 10 # For backwards compatibility: get_version() used to be in this module. … … 83 84 if load_user_commands: 84 85 # Get commands from all installed apps. 85 86 from django.conf import settings 86 for app_name in settings.INSTALLED_APPS:87 for app_name in get_installed_app_paths(): 87 88 try: 88 89 path = find_management_module(app_name) 89 90 _commands.update(dict([(name, app_name) -
django/core/management/sql.py
398 398 from django.conf import settings 399 399 400 400 opts = model._meta 401 app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label). __file__), 'sql'))401 app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).models_module.__file__), 'sql')) 402 402 output = [] 403 403 404 404 # Some backends can't execute more than one SQL statement at a time, … … 449 449 from django.dispatch import dispatcher 450 450 # Emit the post_sync signal for every application. 451 451 for app in models.get_apps(): 452 app_name = app. __name__.split('.')[-2]452 app_name = app.label 453 453 if verbosity >= 2: 454 454 print "Running post-sync handlers for application", app_name 455 455 dispatcher.send(signal=models.signals.post_syncdb, sender=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 … … 110 110 packages = ['django.conf'] 111 111 if type(packages) in (str, unicode): 112 112 packages = packages.split('+') 113 packages = [p for p in packages if p == 'django.conf' or p in settings.INSTALLED_APPS]113 packages = [p for p in packages if p == 'django.conf' or p in get_installed_app_paths()] 114 114 default_locale = to_locale(settings.LANGUAGE_CODE) 115 115 locale = to_locale(get_language()) 116 116 t = {} -
django/contrib/sites/management.py
3 3 """ 4 4 5 5 from django.dispatch import dispatcher 6 from django.db.models import signals 6 from django.db.models import signals, find_app 7 7 from django.contrib.sites.models import Site 8 from django.contrib.sites import models as site_app9 8 10 9 def create_default_site(app, created_models, verbosity): 11 10 if Site in created_models: … … 14 13 s = Site(domain="example.com", name="example.com") 15 14 s.save() 16 15 17 dispatcher.connect(create_default_site, sender= site_app, signal=signals.post_syncdb)16 dispatcher.connect(create_default_site, sender=find_app('django.contrib.sites'), signal=signals.post_syncdb) -
django/contrib/admin/templatetags/adminapplist.py
19 19 app_models = get_models(app) 20 20 if not app_models: 21 21 continue 22 app_label = app _models[0]._meta.app_label22 app_label = app.label 23 23 24 24 has_module_perms = user.has_module_perms(app_label) 25 25 … … 50 50 model_list = [x for key, x in decorated] 51 51 52 52 app_list.append({ 53 'name': app_label.title(),53 'name': _(app.verbose_name).title(), 54 54 'has_module_perms': has_module_perms, 55 55 'models': model_list, 56 56 }) … … 63 63 has at least one permission. 64 64 65 65 Syntax:: 66 66 67 67 {% get_admin_app_list as [context_var_containing_app_list] %} 68 68 69 69 Example usage:: -
django/contrib/admin/views/doc.py
160 160 161 161 # Get the model class. 162 162 try: 163 app _mod= models.get_app(app_label)163 app = models.get_app(app_label) 164 164 except ImproperlyConfigured: 165 165 raise Http404, _("App %r not found") % app_label 166 166 model = None 167 for m in models.get_models(app _mod):167 for m in models.get_models(app): 168 168 if m._meta.object_name.lower() == model_name: 169 169 model = m 170 170 break -
django/contrib/contenttypes/management.py
9 9 entries that no longer have a matching model class. 10 10 """ 11 11 ContentType.objects.clear_cache() 12 content_types = list(ContentType.objects.filter(app_label=app. __name__.split('.')[-2]))12 content_types = list(ContentType.objects.filter(app_label=app.label)) 13 13 app_models = get_models(app) 14 14 if not app_models: 15 15 return -
django/contrib/auth/management.py
3 3 """ 4 4 5 5 from django.dispatch import dispatcher 6 from django.db.models import get_models, signals 7 from django.contrib.auth import models as auth_app 6 from django.db.models import get_models, signals, find_app 8 7 9 8 def _get_permission_codename(action, opts): 10 9 return u'%s_%s' % (action, opts.object_name.lower()) … … 46 45 break 47 46 48 47 dispatcher.connect(create_permissions, signal=signals.post_syncdb) 49 dispatcher.connect(create_superuser, sender= auth_app, signal=signals.post_syncdb)48 dispatcher.connect(create_superuser, sender=find_app('django.contrib.auth'), signal=signals.post_syncdb) -
django/contrib/auth/models.py
303 303 raise SiteProfileNotAvailable 304 304 return self._profile_cache 305 305 306 def __getattribute__(self, attrname): 307 if attrname == '_profile_cache': 308 return models.Model.__getattribute__(self, attrname) 309 try: 310 rv = models.Model.__getattribute__(self, attrname) 311 except AttributeError, e: 312 if not settings.AUTH_PROFILE_MODULE: 313 raise 314 try: 315 profile = self.get_profile() 316 rv = getattr(profile, attrname) 317 except SiteProfileNotAvailable: 318 raise e 319 return rv 320 306 321 class Message(models.Model): 307 322 """ 308 323 The message system is a lightweight way to queue messages for given -
django/utils/translation/trans_real.py
122 122 if t is not None: 123 123 return t 124 124 125 from django.conf import settings 125 from django.conf import settings, get_installed_app_paths 126 126 127 127 # set up the right translation class 128 128 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/bin/make-messages.py
139 139 print "errors happened while running msguniq" 140 140 print errors 141 141 sys.exit(8) 142 # Try importing the local settings. This will work if you're 143 # in the project directory 144 sys.path.insert(0, '.') 145 try: 146 import settings 147 apps = settings.INSTALLED_APPS 148 except (ImportError, AttributeError): 149 apps = [] 150 del sys.path[0] 151 # Now look for all applications which have a verbose name 152 # which is different from the default. If different, add 153 # an internationalization string. 154 for app in apps: 155 if (not isinstance(app, basestring)) and (app.verbose_name != app.path.split('.')[-1]): 156 s = '\nmsgid "%s"\nmsgstr ""\n' % app.verbose_name 157 msgs += s 142 158 open(potfile, 'w').write(msgs) 143 159 if os.path.exists(pofile): 144 160 (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 'b') -
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), 'egg:%s:%s ' % (app, pkg_name)).decode(settings.FILE_CHARSET) 22 22 except: -
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:])) -
docs/settings.txt
501 501 502 502 Default: ``()`` (Empty tuple) 503 503 504 A tuple of strings designating all applications that are enabled in this Django 505 installation. Each string should be a full Python path to a Python package that 506 contains a Django application, as created by `django-admin.py startapp`_. 504 A tuple of entries designating all applications that are enabled in this Django 505 installation. Each entry should be one of the following: 507 506 507 * A string which is a full Python path to a Python package that contains a 508 Django application, as created by `django-admin.py startapp`_. 509 * A string which is a full Python path to a Python package which contains 510 multiple applications, with an appended ``.*``. This entry is replaced 511 by entries for the contained applications. For example, a wildcard 512 entry of the form ``django.contrib.*`` would be replaced by 513 multiple entries for ``django.contrib.admin``, ``django.contrib.auth`` 514 etc. 515 * An ``app`` configuration directive (to use it, you need to add 516 ``from django.conf import app`` to your ``settings`` file). This takes 517 the form ``app(path, label=None, verbose_name=None)``. The ``path`` 518 argument must specify the full Python path to a Python package that 519 contains a Django application. The ``label`` argument, if specified, 520 provides a unique application label (used to disambiguate different 521 third-party applications with conflicting default label values). If this 522 value is not specified, the last portion of the application path is used 523 as the default label. The ``verbose_name`` argument, if specified, is 524 used to provide a descriptive name for the application in the admin 525 screens. If this value is not specified, the last portion of the 526 application path is used as the default value. 527 508 528 .. _django-admin.py startapp: ../django-admin/#startapp-appname 509 529 510 530 INTERNAL_IPS