1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Removed module-level functions for the app cache.

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.
This commit is contained in:
Aymeric Augustin
2013-12-11 23:31:34 +01:00
parent 334551339d
commit 8662654d6d
55 changed files with 226 additions and 220 deletions

View File

@@ -3,6 +3,7 @@ Module for abstract serializer/unserializer base classes.
"""
import warnings
from django.apps import app_cache
from django.db import models
from django.utils import six
@@ -139,7 +140,7 @@ class Deserializer(six.Iterator):
# hack to make sure that the models have all been loaded before
# deserialization starts (otherwise subclass calls to get_model()
# and friends might fail...)
models.get_apps()
app_cache.get_apps()
def __iter__(self):
return self

View File

@@ -5,6 +5,7 @@ other serializers.
"""
from __future__ import unicode_literals
from django.apps import app_cache
from django.conf import settings
from django.core.serializers import base
from django.db import models, DEFAULT_DB_ALIAS
@@ -87,7 +88,7 @@ def Deserializer(object_list, **options):
db = options.pop('using', DEFAULT_DB_ALIAS)
ignore = options.pop('ignorenonexistent', False)
models.get_apps()
app_cache.get_apps()
for d in object_list:
# Look up the model and starting build a dict of data for it.
Model = _get_model(d["model"])
@@ -153,7 +154,7 @@ def _get_model(model_identifier):
Helper to look up a model from an "app_label.model_name" string.
"""
try:
Model = models.get_model(*model_identifier.split("."))
Model = app_cache.get_model(*model_identifier.split("."))
except TypeError:
Model = None
if Model is None:

View File

@@ -4,6 +4,7 @@ XML serializer.
from __future__ import unicode_literals
from django.apps import app_cache
from django.conf import settings
from django.core.serializers import base
from django.db import models, DEFAULT_DB_ALIAS
@@ -276,7 +277,7 @@ class Deserializer(base.Deserializer):
"<%s> node is missing the required '%s' attribute"
% (node.nodeName, attr))
try:
Model = models.get_model(*model_identifier.split("."))
Model = app_cache.get_model(*model_identifier.split("."))
except TypeError:
Model = None
if Model is None: