Author: arthurk
Date: 2010-06-22 16:19:39 -0500 (Tue, 22 Jun 2010)
New Revision: 13388

Added:
   django/branches/soc2010/app-loading/django/core/apps.py
Modified:
   django/branches/soc2010/app-loading/django/db/models/loading.py
   django/branches/soc2010/app-loading/tests/appcachetests.py
Log:
added dummy App class and track instances

Added: django/branches/soc2010/app-loading/django/core/apps.py
===================================================================
--- django/branches/soc2010/app-loading/django/core/apps.py                     
        (rev 0)
+++ django/branches/soc2010/app-loading/django/core/apps.py     2010-06-22 
21:19:39 UTC (rev 13388)
@@ -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

Modified: django/branches/soc2010/app-loading/django/db/models/loading.py
===================================================================
--- django/branches/soc2010/app-loading/django/db/models/loading.py     
2010-06-22 21:19:14 UTC (rev 13387)
+++ django/branches/soc2010/app-loading/django/db/models/loading.py     
2010-06-22 21:19:39 UTC (rev 13388)
@@ -5,6 +5,7 @@
 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 @@
     # 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 @@
         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):

Modified: django/branches/soc2010/app-loading/tests/appcachetests.py
===================================================================
--- django/branches/soc2010/app-loading/tests/appcachetests.py  2010-06-22 
21:19:14 UTC (rev 13387)
+++ django/branches/soc2010/app-loading/tests/appcachetests.py  2010-06-22 
21:19:39 UTC (rev 13388)
@@ -195,6 +195,8 @@
         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)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to