Django

Code

Ticket #3591: app_labels.8.diff

File app_labels.8.diff, 35.1 kB (added by brosner, 8 months ago)

updated to apply cleanly against r6635

  • django/test/simple.py

    old new  
    6464            suite.addTest(test_module.suite()) 
    6565        else: 
    6666            suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(test_module)) 
    67             try:             
     67            try: 
    6868                suite.addTest(doctest.DocTestSuite(test_module,  
    6969                                                   checker=doctestOutputChecker, 
    7070                                                   runner=DocTestRunner)) 
     
    130130                suite.addTest(build_test(label)) 
    131131            else: 
    132132                app = get_app(label) 
    133                 suite.addTest(build_suite(app)) 
     133                mod = app.models_module 
     134                if mod: 
     135                  suite.addTest(build_suite(mod)) 
    134136    else: 
    135137        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)) 
    137141     
    138142    for test in extra_tests: 
    139143        suite.addTest(test) 
  • django/test/client.py

    old new  
    22import sys 
    33from cStringIO import StringIO 
    44from urlparse import urlparse 
    5 from django.conf import settings 
     5from django.conf import settings, get_installed_app_paths 
    66from django.contrib.auth import authenticate, login 
    77from django.core.handlers.base import BaseHandler 
    88from django.core.handlers.wsgi import WSGIRequest 
     
    129129 
    130130    def _session(self): 
    131131        "Obtain the current session variables" 
    132         if 'django.contrib.sessions' in settings.INSTALLED_APPS
     132        if 'django.contrib.sessions' in get_installed_app_paths()
    133133            engine = __import__(settings.SESSION_ENGINE, {}, {}, ['']) 
    134134            cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None) 
    135135            if cookie: 
     
    245245        not available. 
    246246        """ 
    247247        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()
    249249            engine = __import__(settings.SESSION_ENGINE, {}, {}, ['']) 
    250250 
    251251            # Create a fake request to store login details 
  • django/db/models/base.py

    old new  
    88from django.db.models.options import Options, AdminOptions 
    99from django.db import connection, transaction 
    1010from django.db.models import signals 
    11 from django.db.models.loading import register_models, get_model 
     11from django.db.models.loading import register_models, get_model, get_app_label 
    1212from django.dispatch import dispatcher 
    1313from django.utils.datastructures import SortedDict 
    1414from django.utils.functional import curry 
     
    4343                new_class._meta.parents.append(base) 
    4444                new_class._meta.parents.extend(base._meta.parents) 
    4545 
    46  
    4746        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) 
    5249 
    5350        # Bail out early if we have already created this class. 
    5451        m = get_model(new_class._meta.app_label, name, False) 
  • django/db/models/options.py

    old new  
    1 from django.conf import settings 
     1from django.conf import settings, get_installed_app_paths 
    22from django.db.models.related import RelatedObject 
    33from django.db.models.fields.related import ManyToManyRel 
    44from django.db.models.fields import AutoField, FieldDoesNotExist 
     
    3939 
    4040    def contribute_to_class(self, cls, name): 
    4141        cls._meta = self 
    42         self.installed = re.sub('\.models$', '', cls.__module__) in settings.INSTALLED_APPS 
     42        self.installed = re.sub('\.models$', '', cls.__module__) in get_installed_app_paths() 
    4343        # First, construct the default values for these options. 
    4444        self.object_name = cls.__name__ 
    4545        self.module_name = self.object_name.lower() 
  • django/db/models/loading.py

    old new  
    11"Utilities for loading models and the modules that contain them." 
    22 
    3 from django.conf import settings 
     3from django.conf import settings, app 
    44from django.core.exceptions import ImproperlyConfigured 
    55import sys 
    66import os 
    77import threading 
    88 
    99__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'
    1111 
    1212class AppCache(object): 
    1313    """ 
     
    1818    # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531. 
    1919    __shared_state = dict( 
    2020        # Keys of app_store are the model modules for each application. 
     21        # Values are integers indicating the order of loading. 
    2122        app_store = {}, 
    2223 
    2324        # Mapping of app_labels to a dictionary of model names to model code. 
     
    2627        # Mapping of app_labels to errors raised when trying to import the app. 
    2728        app_errors = {}, 
    2829 
     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 
    2940        # -- Everything below here is only used when populating the cache -- 
    3041        loaded = False, 
    3142        handled = {}, 
     
    4960        try: 
    5061            if self.loaded: 
    5162                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 
    5386                if app_name in self.handled: 
    5487                    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 
    5694            if not self.nesting_level: 
    5795                for app_name in self.postponed: 
     96                    the_app = self.mod_map[app_name] 
    5897                    self.load_app(app_name) 
     98                    self.app_instances.append(the_app)                     
    5999                self.loaded = True 
    60100        finally: 
    61101            self.write_lock.release() 
     
    69109        self.nesting_level += 1 
    70110        mod = __import__(app_name, {}, {}, ['models']) 
    71111        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 
    72122        if not hasattr(mod, 'models'): 
    73123            if can_postpone: 
    74124                # Either the app has no models, or the package is still being 
     
    76126                # We will check again once all the recursion has finished (in 
    77127                # populate). 
    78128                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 
    83136 
    84137    def app_cache_ready(self): 
    85138        """ 
     
    99152        # list page, for example. 
    100153        apps = [(v, k) for k, v in self.app_store.items()] 
    101154        apps.sort() 
    102         return [elt[1] for elt in apps] 
     155        #return [elt[1] for elt in apps] 
     156        return self.app_instances 
    103157 
     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         
    104179    def get_app(self, app_label, emptyOK=False): 
    105180        """ 
    106         Returns the module containing the models for the given app_label. If 
     181        Returns the app instance for the given app_label. If 
    107182        the app has no models in it and 'emptyOK' is True, returns None. 
    108183        """ 
    109184        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 
    123192 
    124193    def get_app_errors(self): 
    125194        "Returns the map of known problems with the INSTALLED_APPS." 
    126195        self._populate() 
    127196        return self.app_errors 
    128197 
    129     def get_models(self, app_mod=None): 
     198    def get_models(self, the_app=None): 
    130199        """ 
    131         Given a module containing models, returns a list of the models. 
     200        Given an app instance, returns a list of its models. 
    132201        Otherwise returns a list of all installed models. 
    133202        """ 
    134203        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() 
    137206        else: 
    138207            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)) 
    141210            return model_list 
    142211 
    143212    def get_model(self, app_label, model_name, seed_cache=True): 
     
    185254register_models = cache.register_models 
    186255load_app = cache.load_app 
    187256app_cache_ready = cache.app_cache_ready 
     257find_app = cache.find_app 
     258get_app_label = cache.get_app_label 
  • django/db/models/__init__.py

    old new  
    22from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured 
    33from django.core import validators 
    44from django.db import connection 
    5 from django.db.models.loading import get_apps, get_app, get_models, get_model, register_models 
     5from django.db.models.loading import get_apps, get_app, get_models, get_model, register_models, find_app 
    66from django.db.models.query import Q 
    77from django.db.models.manager import Manager 
    88from django.db.models.base import Model, AdminOptions 
  • django/conf/__init__.py

    old new  
    9999        # of all those apps. 
    100100        new_installed_apps = [] 
    101101        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: 
    103105                appdir = os.path.dirname(__import__(app[:-2], {}, {}, ['']).__file__) 
    104106                for d in os.listdir(appdir): 
    105107                    if d.isalpha() and os.path.isdir(os.path.join(appdir, d)): 
    106108                        new_installed_apps.append('%s.%s' % (app[:-2], d)) 
    107             else: 
    108                 new_installed_apps.append(app) 
    109109        self.INSTALLED_APPS = new_installed_apps 
    110110 
    111111        if hasattr(time, 'tzset'): 
     
    140140 
    141141settings = LazySettings() 
    142142 
     143class 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 
     156def 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

    old new  
    4545        transaction.enter_transaction_management() 
    4646        transaction.managed(True) 
    4747 
    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
    4949        for fixture_label in fixture_labels: 
    5050            parts = fixture_label.split('.') 
    5151            if len(parts) == 1: 
  • django/core/management/commands/flush.py

    old new  
     1from django.conf import get_installed_app_paths 
    12from django.core.management.base import NoArgsCommand, CommandError 
    23from django.core.management.color import no_style 
    34from optparse import make_option 
     
    2526 
    2627        # Import the 'management' module within each installed app, to register 
    2728        # dispatcher events. 
    28         for app_name in settings.INSTALLED_APPS
     29        for app_name in get_installed_app_paths()
    2930            try: 
    3031                __import__(app_name + '.management', {}, {}, ['']) 
    3132            except ImportError: 
  • django/core/management/commands/syncdb.py

    old new  
     1from django.conf import get_installed_app_paths 
    12from django.core.management.base import NoArgsCommand 
    23from django.core.management.color import no_style 
    34from optparse import make_option 
     
    3031 
    3132        # Import the 'management' module within each installed app, to register 
    3233        # dispatcher events. 
    33         for app_name in settings.INSTALLED_APPS
     34        for app_name in get_installed_app_paths()
    3435            try: 
    3536                __import__(app_name + '.management', {}, {}, ['']) 
    3637            except ImportError: 
     
    5354 
    5455        # Create the tables for each model 
    5556        for app in models.get_apps(): 
    56             app_name = app.__name__.split('.')[-2] 
     57            app_name = app.label 
    5758            model_list = models.get_models(app) 
    5859            for model in model_list: 
    5960                # Create the model's database table, if it doesn't already exist. 
     
    7677        # Create the m2m tables. This must be done after all tables have been created 
    7778        # to ensure that all referred tables will exist. 
    7879        for app in models.get_apps(): 
    79             app_name = app.__name__.split('.')[-2] 
     80            app_name = app.label 
    8081            model_list = models.get_models(app) 
    8182            for model in model_list: 
    8283                if model in created_models: 
     
    9697        # Install custom SQL for the app (but only if this 
    9798        # is a model we've just created) 
    9899        for app in models.get_apps(): 
    99             app_name = app.__name__.split('.')[-2] 
     100            app_name = app.label 
    100101            for model in models.get_models(app): 
    101102                if model in created_models: 
    102103                    custom_sql = custom_sql_for_model(model) 
     
    115116 
    116117        # Install SQL indicies for all newly created models 
    117118        for app in models.get_apps(): 
    118             app_name = app.__name__.split('.')[-2] 
     119            app_name = app.label 
    119120            for model in models.get_models(app): 
    120121                if model in created_models: 
    121122                    index_sql = sql_indexes_for_model(model, self.style) 
  • django/core/management/__init__.py

    old new  
    44from imp import find_module 
    55 
    66import django 
     7from django.conf import get_installed_app_paths 
    78from django.core.management.base import BaseCommand, CommandError, handle_default_options 
    89 
    910# For backwards compatibility: get_version() used to be in this module. 
     
    8384        if load_user_commands: 
    8485            # Get commands from all installed apps. 
    8586            from django.conf import settings 
    86             for app_name in settings.INSTALLED_APPS
     87            for app_name in get_installed_app_paths()
    8788                try: 
    8889                    path = find_management_module(app_name) 
    8990                    _commands.update(dict([(name, app_name) 
  • django/core/management/sql.py

    old new  
    398398    from django.conf import settings 
    399399 
    400400    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')) 
    402402    output = [] 
    403403 
    404404    # Some backends can't execute more than one SQL statement at a time, 
     
    449449    from django.dispatch import dispatcher 
    450450    # Emit the post_sync signal for every application. 
    451451    for app in models.get_apps(): 
    452         app_name = app.__name__.split('.')[-2] 
     452        app_name = app.label 
    453453        if verbosity >= 2: 
    454454            print "Running post-sync handlers for application", app_name 
    455455        dispatcher.send(signal=models.signals.post_syncdb, sender=app, 
  • django/templatetags/__init__.py

    old new  
    1 from django.conf import settings 
     1from django.conf import settings, get_installed_app_paths 
    22 
    3 for a in settings.INSTALLED_APPS
     3for a in get_installed_app_paths()
    44    try: 
    55        __path__.extend(__import__(a + '.templatetags', {}, {}, ['']).__path__) 
    66    except ImportError: 
  • django/views/i18n.py

    old new  
    11from django import http 
    22from django.utils.translation import check_for_language, activate, to_locale, get_language 
    33from django.utils.text import javascript_quote 
    4 from django.conf import settings 
     4from django.conf import settings, get_installed_app_paths 
    55import os 
    66import gettext as gettext_module 
    77 
     
    110110        packages = ['django.conf'] 
    111111    if type(packages) in (str, unicode): 
    112112        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()
    114114    default_locale = to_locale(settings.LANGUAGE_CODE) 
    115115    locale = to_locale(get_language()) 
    116116    t = {} 
  • django/contrib/sites/management.py

    old new  
    33""" 
    44 
    55from django.dispatch import dispatcher 
    6 from django.db.models import signals 
     6from django.db.models import signals, find_app 
    77from django.contrib.sites.models import Site 
    8 from django.contrib.sites import models as site_app 
    98 
    109def create_default_site(app, created_models, verbosity): 
    1110    if Site in created_models: 
     
    1413        s = Site(domain="example.com", name="example.com") 
    1514        s.save() 
    1615 
    17 dispatcher.connect(create_default_site, sender=site_app, signal=signals.post_syncdb) 
     16dispatcher.connect(create_default_site, sender=find_app('django.contrib.sites'), signal=signals.post_syncdb) 
  • django/contrib/admin/templatetags/adminapplist.py

    old new  
    1919            app_models = get_models(app) 
    2020            if not app_models: 
    2121                continue 
    22             app_label = app_models[0]._meta.app_label 
     22            app_label = app.label 
    2323 
    2424            has_module_perms = user.has_module_perms(app_label) 
    2525 
     
    5050                    model_list = [x for key, x in decorated] 
    5151 
    5252                    app_list.append({ 
    53                         'name': app_label.title(), 
     53                        'name': _(app.verbose_name).title(), 
    5454                        'has_module_perms': has_module_perms, 
    5555                        'models': model_list, 
    5656                    }) 
     
    6363    has at least one permission. 
    6464 
    6565    Syntax:: 
    66      
     66 
    6767        {% get_admin_app_list as [context_var_containing_app_list] %} 
    6868 
    6969    Example usage:: 
  • django/contrib/admin/views/doc.py

    old new  
    160160 
    161161    # Get the model class. 
    162162    try: 
    163         app_mod = models.get_app(app_label) 
     163        app = models.get_app(app_label) 
    164164    except ImproperlyConfigured: 
    165165        raise Http404, _("App %r not found") % app_label 
    166166    model = None 
    167     for m in models.get_models(app_mod): 
     167    for m in models.get_models(app): 
    168168        if m._meta.object_name.lower() == model_name: 
    169169            model = m 
    170170            break 
  • django/contrib/contenttypes/management.py

    old new  
    99    entries that no longer have a matching model class. 
    1010    """ 
    1111    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)) 
    1313    app_models = get_models(app) 
    1414    if not app_models: 
    1515        return 
  • django/contrib/auth/management.py

    old new  
    33""" 
    44 
    55from django.dispatch import dispatcher 
    6 from django.db.models import get_models, signals 
    7 from django.contrib.auth import models as auth_app 
     6from django.db.models import get_models, signals, find_app 
    87 
    98def _get_permission_codename(action, opts): 
    109    return u'%s_%s' % (action, opts.object_name.lower()) 
     
    4645            break 
    4746 
    4847dispatcher.connect(create_permissions, signal=signals.post_syncdb) 
    49 dispatcher.connect(create_superuser, sender=auth_app, signal=signals.post_syncdb) 
     48dispatcher.connect(create_superuser, sender=find_app('django.contrib.auth'), signal=signals.post_syncdb) 
  • django/contrib/auth/models.py

    old new  
    303303                raise SiteProfileNotAvailable 
    304304        return self._profile_cache 
    305305 
     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 
    306321class Message(models.Model): 
    307322    """ 
    308323    The message system is a lightweight way to queue messages for given 
  • django/utils/translation/trans_real.py

    old new  
    122122    if t is not None: 
    123123        return t 
    124124 
    125     from django.conf import settings 
     125    from django.conf import settings, get_installed_app_paths 
    126126 
    127127    # set up the right translation class 
    128128    klass = DjangoTranslation 
     
    175175        if projectpath and os.path.isdir(projectpath): 
    176176            res = _merge(projectpath) 
    177177 
    178         for appname in settings.INSTALLED_APPS
     178        for appname in get_installed_app_paths()
    179179            p = appname.rfind('.') 
    180180            if p >= 0: 
    181181                app = getattr(__import__(appname[:p], {}, {}, [appname[p+1:]]), appname[p+1:]) 
  • django/bin/make-messages.py

    old new  
    139139                print "errors happened while running msguniq" 
    140140                print errors 
    141141                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 
    142158            open(potfile, 'w').write(msgs) 
    143159            if os.path.exists(pofile): 
    144160                (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 'b') 
  • django/template/loaders/app_directories.py

    old new  
    55 
    66import os 
    77 
    8 from django.conf import settings 
     8from django.conf import settings, get_installed_app_paths 
    99from django.core.exceptions import ImproperlyConfigured 
    1010from django.template import TemplateDoesNotExist 
    1111from django.utils._os import safe_join 
    1212 
    1313# At compile time, cache the directories to search. 
    1414app_template_dirs = [] 
    15 for app in settings.INSTALLED_APPS
     15for app in get_installed_app_paths()
    1616    i = app.rfind('.') 
    1717    if i == -1: 
    1818        m, a = app, None 
  • django/template/loaders/eggs.py

    old new  
    66    resource_string = None 
    77 
    88from django.template import TemplateDoesNotExist 
    9 from django.conf import settings 
     9from django.conf import settings, get_installed_app_paths 
    1010 
    1111def load_template_source(template_name, template_dirs=None): 
    1212    """ 
     
    1616    """ 
    1717    if resource_string is not None: 
    1818        pkg_name = 'templates/' + template_name 
    19         for app in settings.INSTALLED_APPS
     19        for app in get_installed_app_paths()
    2020            try: 
    2121                return (resource_string(app, pkg_name), 'egg:%s:%s ' % (app, pkg_name)).decode(settings.FILE_CHARSET) 
    2222            except: 
  • tests/runtests.py

    old new  
    22 
    33import os, sys, traceback 
    44import unittest 
     5from django.conf import app, get_installed_app_paths 
    56 
    67import django.contrib as contrib 
    78 
     
    2324 
    2425ALWAYS_INSTALLED_APPS = [ 
    2526    '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'), 
    2729    'django.contrib.sites', 
    2830    'django.contrib.flatpages', 
    2931    'django.contrib.redirects', 
     
    5860 
    5961    def runTest(self): 
    6062        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 
    6264        from cStringIO import StringIO 
    6365 
    6466        try: 
    6567            module = load_app(self.model_label) 
     68            app = find_app(self.model_label) 
    6669        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)
    6871 
    6972        # Make sure sys.stdout is not a tty so that we get errors without 
    7073        # coloring attached (makes matching the results easier). We restore 
     
    7275        orig_stdout = sys.stdout 
    7376        s = StringIO() 
    7477        sys.stdout = s 
    75         count = get_validation_errors(s, module
     78        count = get_validation_errors(s, app
    7679        sys.stdout = orig_stdout 
    7780        s.seek(0) 
    7881        error_log = s.read() 
     
    129132                    print "Importing model %s" % model_name 
    130133                mod = load_app(model_label) 
    131134                if mod: 
    132                     if model_label not in settings.INSTALLED_APPS
     135                    if model_label not in get_installed_app_paths()
    133136                        settings.INSTALLED_APPS.append(model_label) 
    134137        except Exception, e: 
    135138            sys.stderr.write("Error while importing %s:" % model_name + ''.join(traceback.format_exception(*sys.exc_info())[1:])) 
  • docs/settings.txt

    old new  
    501501 
    502502Default: ``()`` (Empty tuple) 
    503503 
    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`_. 
     504A tuple of entries designating all applications that are enabled in this Django 
     505installation. Each entry should be one of the following: 
    507506 
     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 
    508528.. _django-admin.py startapp: ../django-admin/#startapp-appname 
    509529 
    510530INTERNAL_IPS