Ticket #3591: app_labels.12.diff
File app_labels.12.diff, 37.5 KB (added by , 16 years ago) |
---|
-
django/conf/__init__.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/conf/__init__.py
a b 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/contrib/admin/__init__.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/contrib/admin/__init__.py
a b 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/admin/options.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/contrib/admin/options.py
a b 8 8 from django.contrib.admin.util import quote, unquote, flatten_fieldsets, get_deleted_objects 9 9 from django.core.exceptions import PermissionDenied 10 10 from django.db import models, transaction 11 from django.db.models.loading import get_app 11 12 from django.http import Http404, HttpResponse, HttpResponseRedirect 12 13 from django.shortcuts import get_object_or_404, render_to_response 13 14 from django.utils.html import escape … … 533 534 'inline_admin_formsets': inline_admin_formsets, 534 535 'errors': helpers.AdminErrorList(form, formsets), 535 536 'root_path': self.admin_site.root_path, 536 'app_label': opts.app_label,537 'app_label': get_app(opts.app_label).verbose_name, 537 538 } 538 539 context.update(extra_context or {}) 539 540 return self.render_change_form(request, context, add=True) … … 612 613 'inline_admin_formsets': inline_admin_formsets, 613 614 'errors': helpers.AdminErrorList(form, formsets), 614 615 'root_path': self.admin_site.root_path, 615 'app_label': opts.app_label,616 'app_label': get_app(opts.app_label).verbose_name, 616 617 } 617 618 context.update(extra_context or {}) 618 619 return self.render_change_form(request, context, change=True, obj=obj) … … 644 645 'cl': cl, 645 646 'has_add_permission': self.has_add_permission(request), 646 647 'root_path': self.admin_site.root_path, 647 'app_label': app_label,648 'app_label': get_app(app_label).verbose_name, 648 649 } 649 650 context.update(extra_context or {}) 650 651 return render_to_response(self.change_list_template or [ … … 699 700 "perms_lacking": perms_needed, 700 701 "opts": opts, 701 702 "root_path": self.admin_site.root_path, 702 "app_label": app_label,703 "app_label": get_app(app_label).verbose_name, 703 704 } 704 705 context.update(extra_context or {}) 705 706 return render_to_response(self.delete_confirmation_template or [ … … 726 727 'module_name': capfirst(force_unicode(opts.verbose_name_plural)), 727 728 'object': obj, 728 729 'root_path': self.admin_site.root_path, 729 'app_label': app_label,730 'app_label': get_app(app_label).verbose_name, 730 731 } 731 732 context.update(extra_context or {}) 732 733 return render_to_response(self.object_history_template or [ -
django/contrib/admin/sites.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/contrib/admin/sites.py
a b 4 4 from django.contrib.admin import ModelAdmin 5 5 from django.contrib.auth import authenticate, login 6 6 from django.db.models.base import ModelBase 7 from django.db.models.loading import get_app 7 8 from django.core.exceptions import ImproperlyConfigured 8 9 from django.shortcuts import render_to_response 9 10 from django.utils.safestring import mark_safe … … 294 295 app_dict[app_label]['models'].append(model_dict) 295 296 else: 296 297 app_dict[app_label] = { 297 'name': app_label.title(),298 'name': get_app(app_label).verbose_name, 298 299 'app_url': app_label + '/', 299 300 'has_module_perms': has_module_perms, 300 301 'models': [model_dict], … … 359 360 # something to display, add in the necessary meta 360 361 # information. 361 362 app_dict = { 362 'name': app_label.title(),363 'name': get_app(app_label).verbose_name, 363 364 'app_url': '', 364 365 'has_module_perms': has_module_perms, 365 366 'models': [model_dict], … … 369 370 # Sort the models alphabetically within each app. 370 371 app_dict['models'].sort(lambda x, y: cmp(x['name'], y['name'])) 371 372 context = { 372 'title': _('%s administration') % capfirst(app_label),373 'title': _('%s administration') % get_app(app_label).verbose_name, 373 374 'app_list': [app_dict], 374 375 'root_path': self.root_path, 375 376 } -
django/contrib/auth/management/__init__.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/contrib/auth/management/__init__.py
a b 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/contrib/comments/__init__.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/contrib/comments/__init__.py
a b 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/contenttypes/management.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/contrib/contenttypes/management.py
a b 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/sites/management.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/contrib/sites/management.py
a b 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/core/management/__init__.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/core/management/__init__.py
a b 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/commands/flush.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/core/management/commands/flush.py
a b 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/loaddata.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/core/management/commands/loaddata.py
a b 51 51 transaction.enter_transaction_management() 52 52 transaction.managed(True) 53 53 54 app_fixtures = [os.path.join(os.path.dirname(app. __file__), 'fixtures') for app in get_apps()]54 app_fixtures = [os.path.join(os.path.dirname(app.app_module.__file__), 'fixtures') for app in get_apps() if app.app_module] 55 55 for fixture_label in fixture_labels: 56 56 parts = fixture_label.split('.') 57 57 if len(parts) == 1: -
django/core/management/commands/syncdb.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/core/management/commands/syncdb.py
a b 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/sql.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/core/management/sql.py
a b 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/db/models/__init__.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/db/models/__init__.py
a b 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/db/models/base.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/db/models/base.py
a b 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/loading.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/db/models/loading.py
a b 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 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] 105 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/options.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/db/models/options.py
a b 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/template/loaders/app_directories.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/template/loaders/app_directories.py
a b 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 … … 14 14 # At compile time, cache the directories to search. 15 15 fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding() 16 16 app_template_dirs = [] 17 for app in settings.INSTALLED_APPS:17 for app in get_installed_app_paths(): 18 18 i = app.rfind('.') 19 19 if i == -1: 20 20 m, a = app, None -
django/template/loaders/eggs.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/template/loaders/eggs.py
a b 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: -
django/templatetags/__init__.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/templatetags/__init__.py
a b 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/test/client.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/test/client.py
a b 7 7 except ImportError: 8 8 from StringIO import StringIO 9 9 10 from django.conf import settings 10 from django.conf import settings, get_installed_app_paths 11 11 from django.contrib.auth import authenticate, login 12 12 from django.core.handlers.base import BaseHandler 13 13 from django.core.handlers.wsgi import WSGIRequest … … 171 171 """ 172 172 Obtains the current session variables. 173 173 """ 174 if 'django.contrib.sessions' in settings.INSTALLED_APPS:174 if 'django.contrib.sessions' in get_installed_app_paths(): 175 175 engine = __import__(settings.SESSION_ENGINE, {}, {}, ['']) 176 176 cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None) 177 177 if cookie: … … 373 373 """ 374 374 user = authenticate(**credentials) 375 375 if user and user.is_active \ 376 and 'django.contrib.sessions' in settings.INSTALLED_APPS:376 and 'django.contrib.sessions' in get_installed_app_paths(): 377 377 engine = __import__(settings.SESSION_ENGINE, {}, {}, ['']) 378 378 379 379 # Create a fake request to store login details. -
django/test/simple.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/test/simple.py
a b 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/utils/translation/trans_real.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/utils/translation/trans_real.py
a b 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/views/i18n.py
diff -r 70f49cf7534d -r 2a82e03ad70a django/views/i18n.py
a b 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 = {} -
tests/regressiontests/admin_scripts/tests.py
diff -r 70f49cf7534d -r 2a82e03ad70a tests/regressiontests/admin_scripts/tests.py
a b 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
diff -r 70f49cf7534d -r 2a82e03ad70a tests/runtests.py
a b 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:]))