Renamed AppCache to Apps.

Also renamed app_cache to apps and "app cache" to "app registry".

Deprecated AppCache.app_cache_ready() in favor of Apps.ready().
This commit is contained in:
Aymeric Augustin 2013-12-24 12:25:17 +01:00
parent e9e522a8e7
commit 1716b7ce5a
92 changed files with 491 additions and 487 deletions

View file

@ -1,4 +1,4 @@
from django.apps.cache import AppCache
from django.apps.registry import Apps
from django.db import models
from django.db.models.options import DEFAULT_NAMES, normalize_unique_together
from django.utils import six
@ -18,7 +18,7 @@ class ProjectState(object):
def __init__(self, models=None):
self.models = models or {}
self.app_cache = None
self.apps = None
def add_model_state(self, model_state):
self.models[(model_state.app_label, model_state.name.lower())] = model_state
@ -30,9 +30,9 @@ class ProjectState(object):
)
def render(self):
"Turns the project state into actual models in a new AppCache"
if self.app_cache is None:
self.app_cache = AppCache()
"Turns the project state into actual models in a new Apps"
if self.apps is None:
self.apps = Apps()
# We keep trying to render the models in a loop, ignoring invalid
# base errors, until the size of the unrendered models doesn't
# decrease by at least one, meaning there's a base dependency loop/
@ -42,19 +42,19 @@ class ProjectState(object):
new_unrendered_models = []
for model in unrendered_models:
try:
model.render(self.app_cache)
model.render(self.apps)
except InvalidBasesError:
new_unrendered_models.append(model)
if len(new_unrendered_models) == len(unrendered_models):
raise InvalidBasesError("Cannot resolve bases for %r" % new_unrendered_models)
unrendered_models = new_unrendered_models
return self.app_cache
return self.apps
@classmethod
def from_app_cache(cls, app_cache):
"Takes in an AppCache and returns a ProjectState matching it"
def from_apps(cls, apps):
"Takes in an Apps and returns a ProjectState matching it"
app_models = {}
for model in app_cache.get_models():
for model in apps.get_models():
model_state = ModelState.from_model(model)
app_models[(model_state.app_label, model_state.name.lower())] = model_state
return cls(app_models)
@ -123,7 +123,7 @@ class ModelState(object):
options = {}
for name in DEFAULT_NAMES:
# Ignore some special options
if name in ["app_cache", "app_label"]:
if name in ["apps", "app_label"]:
continue
elif name in model._meta.original_attrs:
if name == "unique_together":
@ -164,17 +164,17 @@ class ModelState(object):
bases=self.bases,
)
def render(self, app_cache):
"Creates a Model object from our current state into the given app_cache"
def render(self, apps):
"Creates a Model object from our current state into the given apps"
# First, make a Meta object
meta_contents = {'app_label': self.app_label, "app_cache": app_cache}
meta_contents = {'app_label': self.app_label, "apps": apps}
meta_contents.update(self.options)
if "unique_together" in meta_contents:
meta_contents["unique_together"] = list(meta_contents["unique_together"])
meta = type("Meta", tuple(), meta_contents)
# Then, work out our bases
bases = tuple(
(app_cache.get_model(*base.split(".", 1)) if isinstance(base, six.string_types) else base)
(apps.get_model(*base.split(".", 1)) if isinstance(base, six.string_types) else base)
for base in self.bases
)
if None in bases: