mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
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
This commit is contained in:
parent
2b50fd810a
commit
ab037f2b8d
9
django/core/apps.py
Normal file
9
django/core/apps.py
Normal file
@ -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
|
@ -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):
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user