summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorArthur Koziel <arthur@arthurkoziel.com>2010-08-10 01:01:14 +0000
committerArthur Koziel <arthur@arthurkoziel.com>2010-08-10 01:01:14 +0000
commit9f8478ff31298d6f77b47aafd5cd654f856798e6 (patch)
treeefd3eeb2378692b3df4a703ce886189097ad4858 /django
parent56d7859e2588b31e9083f014a894993d6d99cd2b (diff)
downloaddjango-9f8478ff31298d6f77b47aafd5cd654f856798e6.tar.gz
[soc2010/app-loading] use app label instead of fqn
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/app-loading@13568 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/core/apps.py27
-rw-r--r--django/db/models/loading.py4
2 files changed, 11 insertions, 20 deletions
diff --git a/django/core/apps.py b/django/core/apps.py
index 15d5e17946..850621fc85 100644
--- a/django/core/apps.py
+++ b/django/core/apps.py
@@ -22,10 +22,6 @@ class App(object):
"""
def __init__(self, name):
self.name = name
- try:
- self.label = name.rsplit('.', 1)[1]
- except IndexError:
- self.label = name
# errors raised when trying to import the app
self.errors = []
self.models = []
@@ -109,7 +105,11 @@ class AppCache(object):
# check if an app instance with that name already exists
app_instance = self.find_app(app_name)
if not app_instance:
- app_instance = app_class(app_name)
+ if '.' in app_name:
+ app_instance_name = app_name.rsplit('.', 1)[1]
+ else:
+ app_instance_name = app_name
+ app_instance = app_class(app_instance_name)
self.app_instances.append(app_instance)
try:
@@ -142,6 +142,8 @@ class AppCache(object):
def find_app(self, name):
"Returns the App instance that matches name"
+ if '.' in name:
+ name = name.rsplit('.', 1)[1]
for app in self.app_instances:
if app.name == name:
return app
@@ -259,18 +261,7 @@ class AppCache(object):
"""
Register a set of models as belonging to an app.
"""
- # Check if there is an existing app instance
- # If there are more than one app instance with the
- # app_label, an MultipleInstancesReturned is raised
- app_instances = [app for app in self.app_instances\
- if app.label == app_label]
- if len(app_instances) > 1:
- raise MultipleInstancesReturned
- else:
- try:
- app_instance = app_instances[0]
- except IndexError:
- app_instance = None
+ app_instance = self.find_app(app_label)
# Create a new App instance if the ModelBase tries to register
# an app that isn't listed in INSTALLED_APPS
@@ -297,3 +288,5 @@ class AppCache(object):
model_dict[model_name] = model
app_instance.models.append(model)
self._get_models_cache.clear()
+
+cache = AppCache()
diff --git a/django/db/models/loading.py b/django/db/models/loading.py
index 48e5236905..1dadb2280f 100644
--- a/django/db/models/loading.py
+++ b/django/db/models/loading.py
@@ -1,6 +1,7 @@
"Utilities for loading models and the modules that contain them."
from django.conf import settings
+from django.core.apps import AppCache, cache
from django.core.exceptions import ImproperlyConfigured
from django.utils.datastructures import SortedDict
from django.utils.importlib import import_module
@@ -15,9 +16,6 @@ import threading
__all__ = ('get_apps', 'get_app', 'get_models', 'get_model', 'register_models',
'load_app', 'app_cache_ready')
-from django.core.apps import AppCache
-cache = AppCache()
-
# These methods were always module level, so are kept that way for backwards
# compatibility.
get_apps = cache.get_apps