Author: arthurk
Date: 2010-08-09 20:01:14 -0500 (Mon, 09 Aug 2010)
New Revision: 13568
Modified:
django/branches/soc2010/app-loading/django/core/apps.py
django/branches/soc2010/app-loading/django/db/models/loading.py
django/branches/soc2010/app-loading/tests/appcachetests/runtests.py
Log:
[soc2010/app-loading] use app label instead of fqn
Modified: django/branches/soc2010/app-loading/django/core/apps.py
===================================================================
--- django/branches/soc2010/app-loading/django/core/apps.py 2010-08-09
22:59:55 UTC (rev 13567)
+++ django/branches/soc2010/app-loading/django/core/apps.py 2010-08-10
01:01:14 UTC (rev 13568)
@@ -22,10 +22,6 @@
"""
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 @@
# 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 @@
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 @@
"""
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 @@
model_dict[model_name] = model
app_instance.models.append(model)
self._get_models_cache.clear()
+
+cache = AppCache()
Modified: django/branches/soc2010/app-loading/django/db/models/loading.py
===================================================================
--- django/branches/soc2010/app-loading/django/db/models/loading.py
2010-08-09 22:59:55 UTC (rev 13567)
+++ django/branches/soc2010/app-loading/django/db/models/loading.py
2010-08-10 01:01:14 UTC (rev 13568)
@@ -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 @@
__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
Modified: django/branches/soc2010/app-loading/tests/appcachetests/runtests.py
===================================================================
--- django/branches/soc2010/app-loading/tests/appcachetests/runtests.py
2010-08-09 22:59:55 UTC (rev 13567)
+++ django/branches/soc2010/app-loading/tests/appcachetests/runtests.py
2010-08-10 01:01:14 UTC (rev 13568)
@@ -282,15 +282,6 @@
self.assertEqual(app.name, 'model_app')
self.assertEqual(app.models[0].__name__, 'Person')
- def test_multiple_apps_with_same_label(self):
- """
- Test that an exception is raised when the function gets passed an
- app label but there are multiple app instances with that label
- """
- cache.load_app('model_app')
- self.assertRaises(MultipleInstancesReturned, cache.load_app,
- 'same_label.model_app')
-
if __name__ == '__main__':
unittest.main()
--
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.