Ticket #3591: app_labels.9.diff

File app_labels.9.diff, 34.0 KB (added by Vinay Sajip <vinay_sajip@…>, 16 years ago)

Updated to apply cleanly against r6920.

  • django/test/simple.py

     
    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

     
    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

     
    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
     
    4545                new_class._meta.parents.append(base)
    4646                new_class._meta.parents.extend(base._meta.parents)
    4747
    48 
    4948        if getattr(new_class._meta, 'app_label', None) is None:
    50             # Figure out the app_label by looking one level up.
    51             # For 'django.contrib.sites.models', this would be 'sites'.
    52             model_module = sys.modules[new_class.__module__]
    53             new_class._meta.app_label = model_module.__name__.split('.')[-2]
     49            # Figure out the app_label.
     50            new_class._meta.app_label = get_app_label(new_class)
    5451
    5552        # Bail out early if we have already created this class.
    5653        m = get_model(new_class._meta.app_label, name, False)
  • django/db/models/options.py

     
    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

     
    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

     
    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

     
    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

     
    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

     
     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

     
     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, exc:
     
    5455
    5556        # Create the tables for each model
    5657        for app in models.get_apps():
    57             app_name = app.__name__.split('.')[-2]
     58            app_name = app.label
    5859            model_list = models.get_models(app)
    5960            for model in model_list:
    6061                # Create the model's database table, if it doesn't already exist.
     
    7778        # Create the m2m tables. This must be done after all tables have been created
    7879        # to ensure that all referred tables will exist.
    7980        for app in models.get_apps():
    80             app_name = app.__name__.split('.')[-2]
     81            app_name = app.label
    8182            model_list = models.get_models(app)
    8283            for model in model_list:
    8384                if model in created_models:
     
    9798        # Install custom SQL for the app (but only if this
    9899        # is a model we've just created)
    99100        for app in models.get_apps():
    100             app_name = app.__name__.split('.')[-2]
     101            app_name = app.label
    101102            for model in models.get_models(app):
    102103                if model in created_models:
    103104                    custom_sql = custom_sql_for_model(model)
     
    116117
    117118        # Install SQL indicies for all newly created models
    118119        for app in models.get_apps():
    119             app_name = app.__name__.split('.')[-2]
     120            app_name = app.label
    120121            for model in models.get_models(app):
    121122                if model in created_models:
    122123                    index_sql = sql_indexes_for_model(model, self.style)
  • django/core/management/__init__.py

     
    8282
    8383        if load_user_commands:
    8484            # Get commands from all installed apps.
    85             from django.conf import settings
    86             for app_name in settings.INSTALLED_APPS:
     85            from django.conf import settings, get_installed_app_paths
     86            for app_name in get_installed_app_paths():
    8787                try:
    8888                    path = find_management_module(app_name)
    8989                    _commands.update(dict([(name, app_name) for name in find_commands(path)]))
  • django/core/management/sql.py

     
    427427    from django.conf import settings
    428428
    429429    opts = model._meta
    430     app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__), 'sql'))
     430    app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).models_module.__file__), 'sql'))
    431431    output = []
    432432
    433433    # Some backends can't execute more than one SQL statement at a time,
     
    478478    from django.dispatch import dispatcher
    479479    # Emit the post_sync signal for every application.
    480480    for app in models.get_apps():
    481         app_name = app.__name__.split('.')[-2]
     481        app_name = app.label
    482482        if verbosity >= 2:
    483483            print "Running post-sync handlers for application", app_name
    484484        dispatcher.send(signal=models.signals.post_syncdb, sender=app,
  • django/templatetags/__init__.py

     
    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

     
    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/utils/translation/trans_real.py

     
    123123    if t is not None:
    124124        return t
    125125
    126     from django.conf import settings
     126    from django.conf import settings, get_installed_app_paths
    127127
    128128    # set up the right translation class
    129129    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/contrib/sites/management.py

     
    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

     
    2020            app_models = get_models(app)
    2121            if not app_models:
    2222                continue
    23             app_label = app_models[0]._meta.app_label
     23            app_label = app.label
    2424
    2525            has_module_perms = user.has_module_perms(app_label)
    2626
     
    5151                    model_list = [x for key, x in decorated]
    5252
    5353                    app_list.append({
    54                         'name': app_label.title(),
     54                        'name': _(app.verbose_name).title(),
    5555                        'has_module_perms': has_module_perms,
    5656                        'models': model_list,
    5757                    })
     
    6464    has at least one permission.
    6565
    6666    Syntax::
    67    
     67
    6868        {% get_admin_app_list as [context_var_containing_app_list] %}
    6969
    7070    Example usage::
  • django/contrib/admin/views/doc.py

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

     
    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

     
    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/bin/make-messages.py

     
    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

     
    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

     
    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

     
    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()
     
    128131                    print "Importing model %s" % model_name
    129132                mod = load_app(model_label)
    130133                if mod:
    131                     if model_label not in settings.INSTALLED_APPS:
     134                    if model_label not in get_installed_app_paths():
    132135                        settings.INSTALLED_APPS.append(model_label)
    133136        except Exception, e:
    134137            sys.stderr.write("Error while importing %s:" % model_name + ''.join(traceback.format_exception(*sys.exc_info())[1:]))
  • docs/settings.txt

     
    542542
    543543Default: ``()`` (Empty tuple)
    544544
    545 A tuple of strings designating all applications that are enabled in this Django
    546 installation. Each string should be a full Python path to a Python package that
    547 contains a Django application, as created by `django-admin.py startapp`_.
     545A tuple of entries designating all applications that are enabled in this Django
     546installation. Each entry should be one of the following:
    548547
     548    * A string which is a full Python path to a Python package that contains a
     549      Django application, as created by `django-admin.py startapp`_.
     550    * A string which is a full Python path to a Python package which contains
     551      multiple applications, with an appended ``.*``. This entry is replaced
     552      by entries for the contained applications. For example, a wildcard
     553      entry of the form ``django.contrib.*`` would be replaced by
     554      multiple entries for ``django.contrib.admin``, ``django.contrib.auth``
     555      etc.
     556    * An ``app`` configuration directive (to use it, you need to add
     557      ``from django.conf import app`` to your ``settings`` file). This takes
     558      the form ``app(path, label=None, verbose_name=None)``. The ``path``
     559      argument must specify the full Python path to a Python package that
     560      contains a Django application. The ``label`` argument, if specified,
     561      provides a unique application label (used to disambiguate different
     562      third-party applications with conflicting default label values). If this
     563      value is not specified, the last portion of the application path is used
     564      as the default label. The ``verbose_name`` argument, if specified, is
     565      used to provide a descriptive name for the application in the admin
     566      screens. If this value is not specified, the last portion of the
     567      application path is used as the default value.
     568
    549569.. _django-admin.py startapp: ../django-admin/#startapp-appname
    550570
    551571INTERNAL_IPS
Back to Top