Ticket #3591: app_labels.13.diff
File app_labels.13.diff, 36.9 KB (added by , 16 years ago) |
---|
-
django/test/simple.py
176 176 suite.addTest(build_test(label)) 177 177 else: 178 178 app = get_app(label) 179 suite.addTest(build_suite(app)) 179 mod = app.models_module 180 if mod: 181 suite.addTest(build_suite(mod)) 180 182 else: 181 183 for app in get_apps(): 182 suite.addTest(build_suite(app)) 183 184 mod = app.models_module 185 if mod: 186 suite.addTest(build_suite(mod)) 187 184 188 for test in extra_tests: 185 189 suite.addTest(test) 186 190 -
django/test/client.py
8 8 except ImportError: 9 9 from StringIO import StringIO 10 10 11 from django.conf import settings 11 from django.conf import settings, get_installed_app_paths 12 12 from django.contrib.auth import authenticate, login 13 13 from django.core.handlers.base import BaseHandler 14 14 from django.core.handlers.wsgi import WSGIRequest … … 177 177 """ 178 178 Obtains the current session variables. 179 179 """ 180 if 'django.contrib.sessions' in settings.INSTALLED_APPS:180 if 'django.contrib.sessions' in get_installed_app_paths(): 181 181 engine = import_module(settings.SESSION_ENGINE) 182 182 cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None) 183 183 if cookie: … … 406 406 """ 407 407 user = authenticate(**credentials) 408 408 if user and user.is_active \ 409 and 'django.contrib.sessions' in settings.INSTALLED_APPS:409 and 'django.contrib.sessions' in get_installed_app_paths(): 410 410 engine = import_module(settings.SESSION_ENGINE) 411 411 412 412 # Create a fake request to store login details. -
django/db/models/base.py
17 17 from django.db.models.options import Options 18 18 from django.db import connection, transaction, DatabaseError 19 19 from django.db.models import signals 20 from django.db.models.loading import register_models, get_model 20 from django.db.models.loading import register_models, get_model, get_app_label 21 21 from django.utils.functional import curry 22 22 from django.utils.encoding import smart_str, force_unicode, smart_unicode 23 23 from django.conf import settings … … 82 82 new_class._default_manager = new_class._default_manager._copy_to_model(new_class) 83 83 new_class._base_manager = new_class._base_manager._copy_to_model(new_class) 84 84 85 if getattr(new_class._meta, 'app_label', None) is None: 86 # Figure out the app_label. 87 new_class._meta.app_label = get_app_label(new_class) 88 85 89 # Bail out early if we have already created this class. 86 90 m = get_model(new_class._meta.app_label, name, False) 87 91 if m is not None: -
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 … … 58 58 from django.db.backends.util import truncate_name 59 59 60 60 cls._meta = self 61 self.installed = re.sub('\.models$', '', cls.__module__) in settings.INSTALLED_APPS61 self.installed = re.sub('\.models$', '', cls.__module__) in get_installed_app_paths() 62 62 # First, construct the default values for these options. 63 63 self.object_name = cls.__name__ 64 64 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 from django.utils.importlib import import_module 7 7 8 8 import sys 9 import os 9 import os, os.path 10 10 import threading 11 11 12 12 __all__ = ('get_apps', 'get_app', 'get_models', 'get_model', 'register_models', 13 'load_app', 'app_cache_ready' )13 'load_app', 'app_cache_ready', 'find_app') 14 14 15 15 class AppCache(object): 16 16 """ … … 29 29 # Mapping of app_labels to errors raised when trying to import the app. 30 30 app_errors = {}, 31 31 32 33 # Mapping of app_labels to app instances. 34 app_map = {}, 35 36 # Mapping of app module names to app instances. 37 mod_map = {}, 38 39 # List of app instances. 40 app_instances = [], 41 32 42 # -- Everything below here is only used when populating the cache -- 33 43 loaded = False, 34 44 handled = {}, … … 52 62 try: 53 63 if self.loaded: 54 64 return 55 for app_name in settings.INSTALLED_APPS: 65 # We first loop through, setting up the app instances and 66 # the relevant maps so that we can find the instances by app_label 67 # or app module name. These need to be ready because we need to be 68 # able to get the app_label e.g. for applying to model classes. 69 # If a model class is loaded indirectly without being in an 70 # installed app, the app_label used will be what it is now - the 71 # last part of the app module name. 72 # Note that app_map and mod_map will contain entries even 73 # when an app cannot be loaded by load_app. 74 for app_entry in settings.INSTALLED_APPS: 75 if isinstance(app_entry, basestring): 76 the_app = app(app_entry) 77 else: 78 the_app = app_entry 79 self.app_map[the_app.label] = the_app 80 self.mod_map[the_app.path] = the_app 81 82 for app_entry in settings.INSTALLED_APPS: 83 if isinstance(app_entry, basestring): 84 the_app = self.mod_map[app_entry] 85 else: 86 the_app = app_entry 87 app_name = the_app.path 56 88 if app_name in self.handled: 57 89 continue 58 self.load_app(app_name, True) 90 try: 91 self.load_app(app_name, True) 92 self.app_instances.append(the_app) 93 except Exception, e: 94 # Problem importing the app 95 self.app_errors[app_name] = e 59 96 if not self.nesting_level: 60 97 for app_name in self.postponed: 98 the_app = self.mod_map[app_name] 61 99 self.load_app(app_name) 100 self.app_instances.append(the_app) 62 101 self.loaded = True 63 102 finally: 64 103 self.write_lock.release() … … 70 109 """ 71 110 self.handled[app_name] = None 72 111 self.nesting_level += 1 112 mod = import_module(app_name) 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 73 123 try: 74 124 models = import_module('.models', app_name) 125 the_app.models_module = models 75 126 except ImportError: 76 127 self.nesting_level -= 1 77 128 if can_postpone: … … 104 155 # list page, for example. 105 156 apps = [(v, k) for k, v in self.app_store.items()] 106 157 apps.sort() 107 return [elt[1] for elt in apps] 158 #return [elt[1] for elt in apps] 159 return self.app_instances 108 160 161 def get_app_label(self, model_class): 162 "Returns the app label to be used for a model class." 163 key = model_class.__module__ 164 i = key.rfind('.') 165 assert i > 0, "Model class must be defined in a package sub-module" 166 key = key[:i] 167 if key in self.mod_map: 168 rv = self.mod_map[key].label 169 else: 170 i = key.rfind('.') 171 if i < 0: 172 rv = key 173 else: 174 rv = key[i + 1:] 175 return rv 176 177 def find_app(self, app_path): 178 "Find an app instance, given the application path." 179 self._populate() 180 return self.mod_map[app_path] 181 109 182 def get_app(self, app_label, emptyOK=False): 110 183 """ 111 Returns the module containing the modelsfor the given app_label. If184 Returns the app instance for the given app_label. If 112 185 the app has no models in it and 'emptyOK' is True, returns None. 113 186 """ 114 187 self._populate() 115 self.write_lock.acquire() 116 try: 117 for app_name in settings.INSTALLED_APPS: 118 if app_label == app_name.split('.')[-1]: 119 mod = self.load_app(app_name, False) 120 if mod is None: 121 if emptyOK: 122 return None 123 else: 124 return mod 125 raise ImproperlyConfigured, "App with label %s could not be found" % app_label 126 finally: 127 self.write_lock.release() 188 if app_label not in self.app_map: 189 rv = None 190 else: 191 rv = self.app_map[app_label] 192 if emptyOK or rv is not None: 193 return rv 194 raise ImproperlyConfigured, "App with label %s could not be found" % app_label 128 195 129 196 def get_app_errors(self): 130 197 "Returns the map of known problems with the INSTALLED_APPS." 131 198 self._populate() 132 199 return self.app_errors 133 200 134 def get_models(self, app_mod=None):201 def get_models(self, the_app=None): 135 202 """ 136 Given a module containing models, returns a list of themodels.203 Given an app instance, returns a list of its models. 137 204 Otherwise returns a list of all installed models. 138 205 """ 139 206 self._populate() 140 if app_mod:141 return self.app_models.get( app_mod.__name__.split('.')[-2], SortedDict()).values()207 if the_app: 208 return self.app_models.get(the_app.label, SortedDict()).values() 142 209 else: 143 210 model_list = [] 144 for app_entry in self.app_models.itervalues():145 model_list.extend( app_entry.values())211 for the_app in self.app_instances: 212 model_list.extend(get_models(the_app)) 146 213 return model_list 147 214 148 215 def get_model(self, app_label, model_name, seed_cache=True): … … 190 257 register_models = cache.register_models 191 258 load_app = cache.load_app 192 259 app_cache_ready = cache.app_cache_ready 260 find_app = cache.find_app 261 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.expressions import F 7 7 from django.db.models.manager import Manager -
django/conf/__init__.py
89 89 # of all those apps. 90 90 new_installed_apps = [] 91 91 for app in self.INSTALLED_APPS: 92 if app.endswith('.*'): 92 if not isinstance(app, basestring) or not app.endswith('.*'): 93 new_installed_apps.append(app) 94 else: 93 95 app_mod = importlib.import_module(app[:-2]) 94 96 appdir = os.path.dirname(app_mod.__file__) 95 97 app_subdirs = os.listdir(appdir) … … 98 100 for d in app_subdirs: 99 101 if name_pattern.match(d) and os.path.isdir(os.path.join(appdir, d)): 100 102 new_installed_apps.append('%s.%s' % (app[:-2], d)) 101 else:102 new_installed_apps.append(app)103 103 self.INSTALLED_APPS = new_installed_apps 104 104 105 105 if hasattr(time, 'tzset'): … … 134 134 135 135 settings = LazySettings() 136 136 137 class app(object): 138 """Configuration directive for specifying an app.""" 139 def __init__(self, path, app_label=None, verbose_name=None): 140 self.path = path 141 # if name isn't specified, get the last part of the Python dotted path 142 self.label = app_label or path.split('.')[-1] 143 self.verbose_name = verbose_name or self.label 144 self.app_module = None # will be filled in by loading.py 145 self.models_module = None # will be filled in by loading.py 146 147 def __repr__(self): 148 return "<app: %s>" % self.path 149 150 def get_installed_app_paths(): 151 "Return the paths of all entries in settings.INSTALLED_APPS." 152 rv = [] 153 for a in settings.INSTALLED_APPS: 154 if isinstance(a, basestring): 155 rv.append(a) 156 else: 157 rv.append(a.path) 158 return rv -
django/core/management/commands/loaddata.py
76 76 if has_bz2: 77 77 compression_types['bz2'] = bz2.BZ2File 78 78 79 app_fixtures = [os.path.join(os.path.dirname(app. __file__), 'fixtures') for app in get_apps()]79 app_fixtures = [os.path.join(os.path.dirname(app.app_module.__file__), 'fixtures') for app in get_apps() if app.app_module] 80 80 for fixture_label in fixture_labels: 81 81 parts = fixture_label.split('.') 82 82 -
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 django.utils.importlib import import_module … … 22 23 23 24 # Import the 'management' module within each installed app, to register 24 25 # dispatcher events. 25 for app_name in settings.INSTALLED_APPS:26 for app_name in get_installed_app_paths(): 26 27 try: 27 28 import_module('.management', app_name) 28 29 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 django.utils.importlib import import_module … … 29 30 30 31 # Import the 'management' module within each installed app, to register 31 32 # dispatcher events. 32 for app_name in settings.INSTALLED_APPS:33 for app_name in get_installed_app_paths(): 33 34 try: 34 35 import_module('.management', app_name) 35 36 except ImportError, exc: … … 56 57 57 58 # Create the tables for each model 58 59 for app in models.get_apps(): 59 app_name = app. __name__.split('.')[-2]60 app_name = app.label 60 61 model_list = models.get_models(app) 61 62 for model in model_list: 62 63 # Create the model's database table, if it doesn't already exist. … … 81 82 # Create the m2m tables. This must be done after all tables have been created 82 83 # to ensure that all referred tables will exist. 83 84 for app in models.get_apps(): 84 app_name = app. __name__.split('.')[-2]85 app_name = app.label 85 86 model_list = models.get_models(app) 86 87 for model in model_list: 87 88 if model in created_models: … … 104 105 # Install custom SQL for the app (but only if this 105 106 # is a model we've just created) 106 107 for app in models.get_apps(): 107 app_name = app. __name__.split('.')[-2]108 app_name = app.label 108 109 for model in models.get_models(app): 109 110 if model in created_models: 110 111 custom_sql = custom_sql_for_model(model, self.style) … … 128 129 print "No custom SQL for %s.%s model" % (app_name, model._meta.object_name) 129 130 # Install SQL indicies for all newly created models 130 131 for app in models.get_apps(): 131 app_name = app. __name__.split('.')[-2]132 app_name = app.label 132 133 for model in models.get_models(app): 133 134 if model in created_models: 134 135 index_sql = connection.creation.sql_indexes_for_model(model, self.style) -
django/core/management/__init__.py
97 97 98 98 # Find the installed apps 99 99 try: 100 from django.conf import settings 101 apps = settings.INSTALLED_APPS100 from django.conf import settings, get_installed_app_paths 101 apps = get_installed_app_paths() 102 102 except (AttributeError, EnvironmentError, ImportError): 103 103 apps = [] 104 104 -
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 from django.utils import importlib 3 3 4 for a in settings.INSTALLED_APPS:4 for a in get_installed_app_paths(): 5 5 try: 6 6 __path__.extend(importlib.import_module('.templatetags', a).__path__) 7 7 except ImportError: -
django/views/i18n.py
1 1 from django import http 2 from django.conf import settings 2 from django.conf import settings, get_installed_app_paths 3 3 from django.utils import importlib 4 4 from django.utils.translation import check_for_language, activate, to_locale, get_language 5 5 from django.utils.text import javascript_quote … … 122 122 packages = ['django.conf'] 123 123 if type(packages) in (str, unicode): 124 124 packages = packages.split('+') 125 packages = [p for p in packages if p == 'django.conf' or p in settings.INSTALLED_APPS]125 packages = [p for p in packages if p == 'django.conf' or p in get_installed_app_paths()] 126 126 default_locale = to_locale(settings.LANGUAGE_CODE) 127 127 locale = to_locale(get_language()) 128 128 t = {} -
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 from django.contrib.comments.models import Comment … … 13 13 """ 14 14 # Make sure the app's in INSTALLED_APPS 15 15 comments_app = get_comment_app_name() 16 if comments_app not in settings.INSTALLED_APPS:16 if comments_app not in get_installed_app_paths(): 17 17 raise ImproperlyConfigured("The COMMENTS_APP (%r) "\ 18 18 "must be in INSTALLED_APPS" % settings.COMMENTS_APP) 19 19 -
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/options.py
8 8 from django.contrib.admin.util import unquote, flatten_fieldsets, get_deleted_objects, model_ngettext, model_format_dict 9 9 from django.core.exceptions import PermissionDenied 10 10 from django.db import models, transaction 11 from django.db.models import get_app 11 12 from django.db.models.fields import BLANK_CHOICE_DASH 12 13 from django.http import Http404, HttpResponse, HttpResponseRedirect 13 14 from django.shortcuts import get_object_or_404, render_to_response … … 777 778 'inline_admin_formsets': inline_admin_formsets, 778 779 'errors': helpers.AdminErrorList(form, formsets), 779 780 'root_path': self.admin_site.root_path, 780 'app_label': opts.app_label,781 'app_label': get_app(opts.app_label).verbose_name, 781 782 } 782 783 context.update(extra_context or {}) 783 784 return self.render_change_form(request, context, form_url=form_url, add=True) … … 866 867 'inline_admin_formsets': inline_admin_formsets, 867 868 'errors': helpers.AdminErrorList(form, formsets), 868 869 'root_path': self.admin_site.root_path, 869 'app_label': opts.app_label,870 'app_label': get_app(opts.app_label).verbose_name, 870 871 } 871 872 context.update(extra_context or {}) 872 873 return self.render_change_form(request, context, change=True, obj=obj) … … 971 972 'media': media, 972 973 'has_add_permission': self.has_add_permission(request), 973 974 'root_path': self.admin_site.root_path, 974 'app_label': app_label,975 'app_label': get_app(app_label).verbose_name, 975 976 'action_form': action_form, 976 977 'actions_on_top': self.actions_on_top, 977 978 'actions_on_bottom': self.actions_on_bottom, … … 1029 1030 "perms_lacking": perms_needed, 1030 1031 "opts": opts, 1031 1032 "root_path": self.admin_site.root_path, 1032 "app_label": app_label,1033 "app_label": get_app(app_label).verbose_name, 1033 1034 } 1034 1035 context.update(extra_context or {}) 1035 1036 return render_to_response(self.delete_confirmation_template or [ … … 1056 1057 'module_name': capfirst(force_unicode(opts.verbose_name_plural)), 1057 1058 'object': obj, 1058 1059 'root_path': self.admin_site.root_path, 1059 'app_label': app_label,1060 'app_label': get_app(app_label).verbose_name, 1060 1061 } 1061 1062 context.update(extra_context or {}) 1062 1063 return render_to_response(self.object_history_template or [ -
django/contrib/admin/__init__.py
25 25 LOADING = True 26 26 27 27 import imp 28 from django.conf import settings 28 from django.conf import settings, get_installed_app_paths 29 29 30 for app in settings.INSTALLED_APPS:30 for app in get_installed_app_paths(): 31 31 # For each app, we need to look for an admin.py inside that app's 32 32 # package. We can't use os.path here -- recall that modules may be 33 33 # imported different ways (think zip files) -- so we need to get -
django/contrib/admin/sites.py
3 3 from django.contrib.admin import ModelAdmin 4 4 from django.contrib.admin import actions 5 5 from django.contrib.auth import authenticate, login 6 from django.db.models import get_app 6 7 from django.db.models.base import ModelBase 7 8 from django.core.exceptions import ImproperlyConfigured 8 9 from django.shortcuts import render_to_response … … 342 343 app_dict[app_label]['models'].append(model_dict) 343 344 else: 344 345 app_dict[app_label] = { 345 'name': app_label.title(),346 'name': get_app(app_label).verbose_name, 346 347 'app_url': app_label + '/', 347 348 'has_module_perms': has_module_perms, 348 349 'models': [model_dict], … … 404 405 # something to display, add in the necessary meta 405 406 # information. 406 407 app_dict = { 407 'name': app_label.title(),408 'name': get_app(app_label).verbose_name, 408 409 'app_url': '', 409 410 'has_module_perms': has_module_perms, 410 411 'models': [model_dict], … … 414 415 # Sort the models alphabetically within each app. 415 416 app_dict['models'].sort(lambda x, y: cmp(x['name'], y['name'])) 416 417 context = { 417 'title': _('%s administration') % capfirst(app_label),418 'title': _('%s administration') % get_app(app_label).verbose_name, 418 419 'app_list': [app_dict], 419 420 'root_path': self.root_path, 420 421 } -
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/contrib/auth/management/__init__.py
2 2 Creates permissions for all installed apps that need permissions. 3 3 """ 4 4 5 from django.db.models import get_models, signals 6 from django.contrib.auth import models as auth_app 5 from django.db.models import get_models, signals, find_app 7 6 8 7 def _get_permission_codename(action, opts): 9 8 return u'%s_%s' % (action, opts.object_name.lower()) … … 47 46 signals.post_syncdb.connect(create_permissions, 48 47 dispatch_uid = "django.contrib.auth.management.create_permissions") 49 48 signals.post_syncdb.connect(create_superuser, 50 sender=auth_app, dispatch_uid = "django.contrib.auth.management.create_superuser") 49 sender=find_app('django.contrib.auth'), 50 dispatch_uid = "django.contrib.auth.management.create_superuser") -
django/utils/translation/trans_real.py
115 115 if t is not None: 116 116 return t 117 117 118 from django.conf import settings 118 from django.conf import settings, get_installed_app_paths 119 119 120 120 # set up the right translation class 121 121 klass = DjangoTranslation … … 176 176 if projectpath and os.path.isdir(projectpath): 177 177 res = _merge(projectpath) 178 178 179 for appname in settings.INSTALLED_APPS:179 for appname in get_installed_app_paths(): 180 180 app = import_module(appname) 181 181 apppath = os.path.join(os.path.dirname(app.__file__), 'locale') 182 182 -
django/template/loaders/app_directories.py
6 6 import os 7 7 import sys 8 8 9 from django.conf import settings 9 from django.conf import settings, get_installed_app_paths 10 10 from django.core.exceptions import ImproperlyConfigured 11 11 from django.template import TemplateDoesNotExist 12 12 from django.utils._os import safe_join … … 15 15 # At compile time, cache the directories to search. 16 16 fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding() 17 17 app_template_dirs = [] 18 for app in settings.INSTALLED_APPS:18 for app in get_installed_app_paths(): 19 19 try: 20 20 mod = import_module(app) 21 21 except ImportError, e: -
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
1041 1041 args = ['app_command', 'auth'] 1042 1042 out, err = self.run_manage(args) 1043 1043 self.assertNoOutput(err) 1044 self.assertOutput(out, "EXECUTE:AppCommand app=< module 'django.contrib.auth.models'")1045 self.assertOutput(out, os.sep.join(['django','contrib','auth','models.py']))1046 self.assertOutput(out, " '>, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")1044 self.assertOutput(out, "EXECUTE:AppCommand app=<app: django.contrib.auth>") 1045 #self.assertOutput(out, os.sep.join(['django','contrib','auth','models.py'])) 1046 self.assertOutput(out, ">, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]") 1047 1047 1048 1048 def test_app_command_no_apps(self): 1049 1049 "User AppCommands raise an error when no app name is provided" … … 1056 1056 args = ['app_command','auth','contenttypes'] 1057 1057 out, err = self.run_manage(args) 1058 1058 self.assertNoOutput(err) 1059 self.assertOutput(out, "EXECUTE:AppCommand app=< module 'django.contrib.auth.models'")1060 self.assertOutput(out, os.sep.join(['django','contrib','auth','models.py']))1061 self.assertOutput(out, " '>, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")1062 self.assertOutput(out, "EXECUTE:AppCommand app=< module 'django.contrib.contenttypes.models'")1063 self.assertOutput(out, os.sep.join(['django','contrib','contenttypes','models.py']))1064 self.assertOutput(out, " '>, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")1059 self.assertOutput(out, "EXECUTE:AppCommand app=<app: django.contrib.auth>") 1060 #self.assertOutput(out, os.sep.join(['django','contrib','auth','models.py'])) 1061 self.assertOutput(out, ">, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]") 1062 self.assertOutput(out, "EXECUTE:AppCommand app=<app: django.contrib.contenttypes>") 1063 #self.assertOutput(out, os.sep.join(['django','contrib','contenttypes','models.py'])) 1064 self.assertOutput(out, ">, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]") 1065 1065 1066 1066 def test_app_command_invalid_appname(self): 1067 1067 "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() … … 133 136 print "Importing model %s" % model_name 134 137 mod = load_app(model_label) 135 138 if mod: 136 if model_label not in settings.INSTALLED_APPS:139 if model_label not in get_installed_app_paths(): 137 140 settings.INSTALLED_APPS.append(model_label) 138 141 except Exception, e: 139 142 sys.stderr.write("Error while importing %s:" % model_name + ''.join(traceback.format_exception(*sys.exc_info())[1:]))