Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/django/apps
Commit message (Collapse)AuthorAgeFilesLines
...
* Added AppConfig.get_models().Aymeric Augustin2013-12-291-0/+26
|
* Removed the only_installed argument of Apps.get_models.Aymeric Augustin2013-12-281-25/+7
| | | | Refs #15903, #15866, #15850.
* Changed get_model to raise an exception on errors.Aymeric Augustin2013-12-281-8/+9
| | | | | | | | | | | | Returning None on errors required unpythonic error checking and was inconsistent with get_app_config. get_model was a private API until the previous commit, but given that it was certainly used in third party software, the change is explained in the release notes. Applied the same change to get_registered_model, which is a new private API introduced during the recent refactoring.
* Simplified Apps.get_model and added AppConfig.get_model.Aymeric Augustin2013-12-282-14/+31
| | | | Documented them as public APIs.
* Populated non-master app registries.Aymeric Augustin2013-12-282-9/+11
| | | | | | | | This removes the gap between the master app registry and ad-hoc app registries created by the migration framework, specifically in terms of behavior of the get_model[s] methods. This commit contains a stealth feature that I'd rather not describe.
* Simplified the implementation of register_model.Aymeric Augustin2013-12-281-13/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | register_model is called exactly once in the entire Django code base, at the bottom of ModelBase.__new__: new_class._meta.apps.register_model(new_class._meta.app_label, new_class) ModelBase.__new__ exits prematurely 120 lines earlier (sigh) if a model with the same name is already registered: if new_class._meta.apps.get_registered_model(new_class._meta.app_label, name): return (This isn't the exact code, but it's equivalent.) apps.register_model and apps.get_registered_model are essentially a setter and a getter for apps.all_models, and apps.register_model is the only setter. As a consequence, new_class._meta.apps.all_models cannot change in-between. Considering that name == new_class.__name__, we can conclude that register_model(app_label, model) is always called with such arguments that get_registered_model(app_label, model.__name__) returns None. Considering that model._meta.model_name == model.__name__.lower(), and looking at the implementation of register_model and get_registered_model, this proves that self.all_models[app_label] doesn't contain model._meta.model_name in register_model, allowing us to simplify the implementation.
* Avoided %r formatting on possibly unicode strings.Aymeric Augustin2013-12-272-5/+5
| | | | The u prefix looks bad on Python 2.
* Normalized exceptions raised by AppConfig.create.Aymeric Augustin2013-12-261-5/+16
| | | | | | | | | It raises ImportError whenever an entry in INSTALLED_APPS points (directly or indirectly via AppConfig.name) to a non-existing module and ImproperlyConfigured in all other cases. Catching ImportError and re-raising ImproperlyConfigured tends to make circular imports more difficult to diagnose.
* Made the AppConfig API marginally more consistent.Aymeric Augustin2013-12-261-7/+10
| | | | Eliminated the app_ prefix that was more confusing than useful.
* Made unset_installed_apps reset the app registry state.Aymeric Augustin2013-12-261-2/+2
| | | | | | Previously the _apps/models_loaded flags could remain set to False if set_installed_apps exited with an exception, which is going to happen as soon as we add tests for invalid values of INSTALLED_APPS.
* Turned apps.ready into a property. Added tests.Aymeric Augustin2013-12-261-3/+4
|
* Beefed up the comments for AppConfig.all_models.Aymeric Augustin2013-12-262-6/+11
|
* Documented the Apps and AppConfig APIs.Aymeric Augustin2013-12-241-2/+2
|
* Renamed AppCache to Apps.Aymeric Augustin2013-12-243-20/+27
| | | | | | Also renamed app_cache to apps and "app cache" to "app registry". Deprecated AppCache.app_cache_ready() in favor of Apps.ready().
* Invalidated get_models cache in a few more places.Aymeric Augustin2013-12-241-0/+4
|
* Replaced ad-hoc caching of get_models with lru_cache.Aymeric Augustin2013-12-241-10/+7
| | | | | Invalidate properly the cache whenever all_models or app_configs change. This fixes some isolation issues in the test suite.
* Fixed override_settings when set_available_apps raises ↵Aymeric Augustin2013-12-241-11/+14
| | | | | | | an exception. Previously, this would corrupt the settings, because __exit__ isn't called when __enter__raises an exception.
* Avoided loading repeatedly the same models module.Aymeric Augustin2013-12-231-0/+3
|
* Dropped AppCache._empty, _with_app and _without_app.Aymeric Augustin2013-12-231-56/+0
| | | | | It's now easier to achieve the same effect with modify_settings or override_settings.
* Refactored INSTALLED_APPS overrides.Aymeric Augustin2013-12-232-46/+46
| | | | | | | | | | * Introduced [un]set_installed_apps to handle changes to the INSTALLED_APPS setting. * Refactored [un]set_available_apps to share its implementation with [un]set_installed_apps. * Implemented a receiver to clear some app-related caches. * Removed test_missing_app as it is basically impossible to reproduce this situation with public methods of the new app cache.
* Syntax error.Aymeric Augustin2013-12-221-1/+1
|
* Renamed has_model to get_registered_models.Aymeric Augustin2013-12-221-1/+1
| | | | That matches its return type better.
* Changed has_app to return a boolean.Aymeric Augustin2013-12-221-4/+4
| | | | That matches its name ad its purpose better.
* Made AppConfig importable from django.apps.Aymeric Augustin2013-12-221-0/+1
| | | | It is a public API.
* Moved apps back in the toplevel django namespace.Aymeric Augustin2013-12-223-0/+605
| | | | Reverted 4a56a93cc458e9ab4dcab95d9f5067d4975dd1a2.
* Moved the new app cache inside core.Aymeric Augustin2013-12-173-464/+0
|
* Inlined trivial method that was used only once.Aymeric Augustin2013-12-171-8/+1
|
* Fixed incorrect decrementation of nesting_level.Aymeric Augustin2013-12-171-3/+2
| | | | Thanks Florian for catching this mistake.
* Made it possible to create apps without a models module.Aymeric Augustin2013-12-172-9/+22
| | | | | | | This commit reverts f44c4a5d0f and 39bbd165. django.test.simple will be updated in a separate commit as it requires invasive changes.
* Deprecated get_app().Aymeric Augustin2013-12-171-13/+16
|
* Deprecated get_apps().Aymeric Augustin2013-12-171-6/+9
|
* Removed the _-prefix for populate().Aymeric Augustin2013-12-171-7/+7
| | | | | | Several parts of Django call get_apps() with a comment along this lines of "this has the side effect of calling _populate()". I fail to see how this is better than just calling populate()!
* Simplified register_models.Aymeric Augustin2013-12-172-27/+32
| | | | | Since it's never called with more than one model at a time the current signature is needlessly complicated.
* Simplified handling of available_apps slightly.Aymeric Augustin2013-12-171-10/+17
| | | | | It feels more natural for self.available_apps to contain app names (like INSTALLED_APPS) than app labels, and this is easy to implement now.
* Deprecated get_app_package, get_app_path and get_app_paths.Aymeric Augustin2013-12-171-30/+43
|
* Added get_app_configs() to iterate on app_config instances.Aymeric Augustin2013-12-171-9/+16
| | | | | | Refactored get_apps() to rely on that method. This commit is fully backwards-compatible.
* Added get_app_config() to look up app configs by label.Aymeric Augustin2013-12-171-16/+25
| | | | | | | | | | | | | | | | | | | | | | | Refactored get_app() to rely on that method. get_app() starts by calling _populate(), which goes through INSTALLED_APPS and, for each app, imports the app module and attempts to import the models module. At this point, no further imports are necessary to return the models module for a given app. Therefore, the implementation of get_app() can be simplified and the safeguards for race conditions can be removed. Besides, the emptyOK parameter isn't used anywhere in Django. It was introduced in d6c95e93 but not actually used nor documented, and it has just been carried around since then. Since it's an obscure private API, it's acceptable to stop supporting it without a deprecation path. This branch aims at providing first-class support for applications without a models module eventually. For backwards-compatibility, get_app() still raises ImproperlyConfigured when an app isn't found, even though LookupError is technically more correct. I haven't gone as far as to preserve the exact error messages. I've adjusted a few tests instead.
* Fleshed out AppConfig objects.Aymeric Augustin2013-12-172-15/+34
| | | | Marginally improved creation of AppConfig stubs for non-installed apps.
* Moved list of models inside AppConfig instances.Aymeric Augustin2013-12-172-24/+48
| | | | | | | | | | | | | | | | | | | | | | | This commit is a refactoring with no change of functionality, according to the following invariants: - An app_label that was in app_configs and app_models stays in app_config and has its 'installed' attribute set to True. - An app_label that was in app_models but not in app_configs is added to app_configs and has its 'installed' attribute set to True. As a consequence, all the code that iterated on app_configs is modified to check for the 'installed' attribute. Code that iterated on app_models is rewritten in terms of app_configs. Many tests that stored and restored the state of the app cache were updated. In the long term, we should reconsider the usefulness of allowing importing models from non-installed applications. This doesn't sound particularly useful, can be a trap in some circumstances, and causes significant complexity in sensitive areas of Django.
* Removed unused attribute app_errors of the app cache.Aymeric Augustin2013-12-171-8/+0
| | | | | get_app_errors() always returned an empty dictionary; this behavior is preserved in django.db.models.loading until that module is deprecated.
* Stored AppConfig objects instead of models modules in ↵Aymeric Augustin2013-12-172-13/+27
| | | | | | the app cache. This is a step towards allowing applications without a models module.
* Removed module-level functions for the app cache.Aymeric Augustin2013-12-172-18/+2
| | | | | | | | | | | | | | | Since the original ones in django.db.models.loading were kept only for backwards compatibility, there's no need to recreate them. However, many internals of Django still relied on them. They were also imported in django.db.models. They never appear in the documentation, except a quick mention of get_models and get_app in the 1.2 release notes to document an edge case in GIS. I don't think that makes them a public API. This commit doesn't change the overall amount of global state but clarifies that it's tied to the app_cache object instead of hiding it behind half a dozen functions.
* Removed ModelDict.Aymeric Augustin2013-12-171-15/+4
| | | | | | Its only difference with OrderedDict is that it didn't deepcopy its keys. However it wasn't used anywhere with models modules as keys, only as values. So this commit doesn't result in any change in functionality.
* Removed BaseAppCache.app_store.Aymeric Augustin2013-12-171-19/+13
| | | | | It was only storing redundant information. This is part of the effort to allow applications without a models module.
* Moved django.db.models.loading to django.apps.cache.Aymeric Augustin2013-12-172-0/+396
This commit doesn't contain any code changes; it's purely a refactoring.