summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Koziel <arthur@arthurkoziel.com>2010-06-22 21:19:39 +0000
committerArthur Koziel <arthur@arthurkoziel.com>2010-06-22 21:19:39 +0000
commitab037f2b8df241a1ae3b31542cf1f58e2a50daf2 (patch)
tree90ee7c461c07be27a7f4a1261c4052604e7fdcc7
parent2b50fd810a0987475f6621e062dc956553f9d32c (diff)
added dummy App class and track instances
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/app-loading@13388 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/core/apps.py9
-rw-r--r--django/db/models/loading.py5
-rw-r--r--tests/appcachetests.py2
3 files changed, 16 insertions, 0 deletions
diff --git a/django/core/apps.py b/django/core/apps.py
new file mode 100644
index 0000000000..5c2844e036
--- /dev/null
+++ b/django/core/apps.py
@@ -0,0 +1,9 @@
+class App(object):
+ def __init__(self, name, models):
+ # fully qualified name (e.g. 'django.contrib.auth')
+ self.name = name
+ self.label = name.split('.')[-1]
+ self.models = models
+
+ def __repr__(self):
+ return '<App: %s>' % self.name
diff --git a/django/db/models/loading.py b/django/db/models/loading.py
index 620cebc25c..d01e33b411 100644
--- a/django/db/models/loading.py
+++ b/django/db/models/loading.py
@@ -5,6 +5,7 @@ from django.core.exceptions import ImproperlyConfigured
from django.utils.datastructures import SortedDict
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule
+from django.core.apps import App
import imp
import sys
@@ -22,6 +23,9 @@ class AppCache(object):
# Use the Borg pattern to share state between all instances. Details at
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531.
__shared_state = dict(
+ # List of App instances
+ app_instances = [],
+
# Keys of app_store are the model modules for each application.
app_store = SortedDict(),
@@ -99,6 +103,7 @@ class AppCache(object):
self.nesting_level -= 1
if models not in self.app_store:
self.app_store[models] = len(self.app_store)
+ self.app_instances.append(App(app_name, models))
return models
def app_cache_ready(self):
diff --git a/tests/appcachetests.py b/tests/appcachetests.py
index b285d16094..5ac09a9178 100644
--- a/tests/appcachetests.py
+++ b/tests/appcachetests.py
@@ -195,6 +195,8 @@ class RegisterModelsTests(AppCacheTestCase):
cache.register_models('foo', *(FlatPage, Site,))
self.assertFalse(cache.app_cache_ready())
rv = cache.get_models()
+ # we have 4 models since the above import will trigger the
+ # ModelBase.__new__, which will call the register_models function
self.assertEqual(len(rv), 4)
self.assertEqual(rv[0], Site)
self.assertEqual(rv[1], FlatPage)