8000 added dummy App class and track instances · alex-python/django@ab037f2 · GitHub
[go: up one dir, main page]

Skip to content
< 8000 /div>

Commit ab037f2

Browse files
committed
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
1 parent 2b50fd8 commit ab037f2

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

django/core/apps.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class App(object):
2+
def __init__(self, name, models):
3+
# fully qualified name (e.g. 'django.contrib.auth')
4+
self.name = name
5+
self.label = name.split('.')[-1]
6+
self.models = models
7+
8+
def __repr__(self):
9+
return '<App: %s>' % self.name

django/db/models/loading.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django.utils.datastructures import SortedDict
66
from django.utils.importlib import import_module
77
from django.utils.module_loading import module_has_submodule
8+
from django.core.apps import App
89

910
import imp
1011
import sys
@@ -22,6 +23,9 @@ class AppCache(object):
2223
# Use the Borg pattern to share state between all instances. Details at
2324
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531.
2425
__shared_state = dict(
26+
# List of App instances
27+
app_instances = [],
28+
2529
# Keys of app_store are the model modules for each application.
2630
app_store = SortedDict(),
2731

@@ -99,6 +103,7 @@ def load_app(self, app_name, can_postpone=False):
99103
self.nesting_level -= 1
100104
if models not in self.app_store:
101105
self.app_store[models] = len(self.app_store)
106+
self.app_instances.append(App(app_name, models))
102107
return models
103108

104109
def app_cache_ready(self):

tests/appcachetests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ def test_register_models(self):
195195
cache.register_models('foo', *(FlatPage, Site,))
196196
self.assertFalse(cache.app_cache_ready())
197197
rv = cache.get_models()
198+
# we have 4 models since the above import will trigger the
199+
# ModelBase.__new__, which will call the register_models function
198200
self.assertEqual(len(rv), 4)
199201
self.assertEqual(rv[0], Site)
200202
self.assertEqual(rv[1], FlatPage)

0 commit comments

Comments
 (0)
0