Commits

art...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed f7ca49b

[soc2010/app-loading] use app label instead of fqn

  • Participants
  • Parent commits 081943a
  • Branches soc2010/app-loading

Comments (0)

Files changed (3)

File django/core/apps.py

     """
     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 = []
         # 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:
 
     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
         """
         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
             model_dict[model_name] = model
             app_instance.models.append(model)
         self._get_models_cache.clear()
+
+cache = AppCache()

File django/db/models/loading.py

 "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
 __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

File tests/appcachetests/runtests.py

         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()