Skip to content

Commit

Permalink
rename global AppCache instance from cache to app_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ptone committed Aug 28, 2012
1 parent 838f002 commit 6295185
Show file tree
Hide file tree
Showing 43 changed files with 278 additions and 278 deletions.
2 changes: 1 addition & 1 deletion django/apps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.apps.base import App
from django.apps.cache import AppCache

cache = AppCache()
app_cache = AppCache()
4 changes: 2 additions & 2 deletions django/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def from_name(cls, name):
return type(cls_name[0].upper()+cls_name[1:], (cls,), {'_name': name})

def add_parent_models(self, installed=False):
from django.apps import cache
from django.apps import app_cache
parents = [p for p in self.__class__.mro()
if hasattr(p, '_meta')]
for parent in reversed(parents):
parent_models = cache.app_models.get(parent._meta.label, {})
parent_models = app_cache.app_models.get(parent._meta.label, {})
# update app_label and installed attribute of parent models
for model in parent_models.itervalues():
model._meta.app_label = self._meta.label
Expand Down
4 changes: 2 additions & 2 deletions django/contrib/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ACTION_CHECKBOX_NAME is unused, but should stay since its import from here
# has been referenced in documentation.
from django.apps import cache
from django.apps import app_cache
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL
from django.contrib.admin.options import StackedInline, TabularInline
Expand All @@ -21,7 +21,7 @@ def autodiscover():
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule

for app in cache.loaded_apps:
for app in app_cache.loaded_apps:
# Attempt to import the app's admin module.
try:
before_import_registry = copy.copy(site._registry)
Expand Down
12 changes: 6 additions & 6 deletions django/contrib/admin/options.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import update_wrapper, partial
from django import forms
from django.apps import cache
from django.apps import app_cache
from django.conf import settings
from django.forms.formsets import all_valid
from django.forms.models import (modelform_factory, modelformset_factory,
Expand Down Expand Up @@ -1002,7 +1002,7 @@ def add_view(self, request, form_url='', extra_context=None):
'media': media,
'inline_admin_formsets': inline_admin_formsets,
'errors': helpers.AdminErrorList(form, formsets),
'app_label': cache.get_app_instance(opts.app_label)._meta.verbose_name,
'app_label': app_cache.get_app_instance(opts.app_label)._meta.verbose_name,
}
context.update(extra_context or {})
return self.render_change_form(request, context, form_url=form_url, add=True)
Expand Down Expand Up @@ -1094,7 +1094,7 @@ def change_view(self, request, object_id, form_url='', extra_context=None):
'media': media,
'inline_admin_formsets': inline_admin_formsets,
'errors': helpers.AdminErrorList(form, formsets),
'app_label': cache.get_app_instance(opts.app_label)._meta.verbose_name,
'app_label': app_cache.get_app_instance(opts.app_label)._meta.verbose_name,
}
context.update(extra_context or {})
return self.render_change_form(request, context, change=True, obj=obj, form_url=form_url)
Expand Down Expand Up @@ -1237,7 +1237,7 @@ def changelist_view(self, request, extra_context=None):
'cl': cl,
'media': media,
'has_add_permission': self.has_add_permission(request),
'app_label': cache.get_app_instance(app_label)._meta.verbose_name,
'app_label': app_cache.get_app_instance(app_label)._meta.verbose_name,
'action_form': action_form,
'actions_on_top': self.actions_on_top,
'actions_on_bottom': self.actions_on_bottom,
Expand Down Expand Up @@ -1304,7 +1304,7 @@ def delete_view(self, request, object_id, extra_context=None):
"perms_lacking": perms_needed,
"protected": protected,
"opts": opts,
"app_label": cache.get_app_instance(app_label)._meta.verbose_name,
"app_label": app_cache.get_app_instance(app_label)._meta.verbose_name,
}
context.update(extra_context or {})

Expand All @@ -1331,7 +1331,7 @@ def history_view(self, request, object_id, extra_context=None):
'action_list': action_list,
'module_name': capfirst(force_text(opts.verbose_name_plural)),
'object': obj,
'app_label': cache.get_app_instance(app_label)._meta.verbose_name,
'app_label': app_cache.get_app_instance(app_label)._meta.verbose_name,
'opts': opts,
}
context.update(extra_context or {})
Expand Down
6 changes: 3 additions & 3 deletions django/contrib/admin/sites.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import update_wrapper

from django.apps import cache
from django.apps import app_cache
from django.http import Http404, HttpResponseRedirect
from django.contrib.admin import ModelAdmin, actions
from django.contrib.admin.forms import AdminAuthenticationForm
Expand Down Expand Up @@ -366,7 +366,7 @@ def index(self, request, extra_context=None):
app_dict[app_label]['models'].append(model_dict)
else:
app_dict[app_label] = {
'name': cache.get_app_instance(app_label)._meta.verbose_name,
'name': app_cache.get_app_instance(app_label)._meta.verbose_name,
'app_url': reverse('admin:app_list', kwargs={'app_label': app_label}, current_app=self.name),
'has_module_perms': has_module_perms,
'models': [model_dict],
Expand All @@ -393,7 +393,7 @@ def app_index(self, request, app_label, extra_context=None):
user = request.user
has_module_perms = user.has_module_perms(app_label)
app_dict = {}
app = cache.get_app_instance(app_label)
app = app_cache.get_app_instance(app_label)
for model, model_admin in self._registry.items():
if app_label == model._meta.app_label:
if has_module_perms:
Expand Down
4 changes: 2 additions & 2 deletions django/contrib/admin/validation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.apps import cache
from django.apps import app_cache
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.db.models.fields import FieldDoesNotExist
Expand All @@ -20,7 +20,7 @@ def validate(cls, model):
"""
# Before we can introspect models, they need to be fully loaded so that
# inter-relations are set up correctly. We force that here.
cache._populate()
app_cache._populate()

opts = model._meta
validate_base(cls, model)
Expand Down
6 changes: 3 additions & 3 deletions django/contrib/contenttypes/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from functools import partial
from operator import attrgetter

from django.apps import cache
from django.apps import app_cache
from django.core.exceptions import ObjectDoesNotExist
from django.db import connection
from django.db.models import signals
Expand Down Expand Up @@ -54,7 +54,7 @@ def instance_pre_init(self, signal, sender, args, kwargs, **_kwargs):
def get_content_type(self, obj=None, id=None, using=None):
# Convenience function using get_model avoids a circular import when
# using this model
ContentType = cache.get_model("contenttypes", "contenttype")
ContentType = app_cache.get_model("contenttypes", "contenttype")
if obj:
return ContentType.objects.db_manager(obj._state.db).get_for_model(obj)
elif id:
Expand Down Expand Up @@ -216,7 +216,7 @@ def extra_filters(self, pieces, pos, negate):
"""
if negate:
return []
ContentType = cache.get_model("contenttypes", "contenttype")
ContentType = app_cache.get_model("contenttypes", "contenttype")
content_type = ContentType.objects.get_for_model(self.model)
prefix = "__".join(pieces[:pos + 1])
return [("%s__%s" % (prefix, self.content_type_field_name),
Expand Down
8 changes: 4 additions & 4 deletions django/contrib/contenttypes/management.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.apps import cache
from django.apps import app_cache
from django.contrib.contenttypes.models import ContentType
from django.utils.encoding import smart_text
from django.utils import six
Expand All @@ -9,9 +9,9 @@ def update_contenttypes(app, created_models, verbosity=2, **kwargs):
Creates content types for models in the given app, removing any model
entries that no longer have a matching model class.
"""
app_cls = cache.find_app_by_models_module(app)
app_cls = app_cache.find_app_by_models_module(app)
ContentType.objects.clear_cache()
app_models = cache.get_models(app)
app_models = app_cache.get_models(app)
if not app_models:
return
# They all have the same app_label, get the first one.
Expand Down Expand Up @@ -74,7 +74,7 @@ def update_contenttypes(app, created_models, verbosity=2, **kwargs):
print("Stale content types remain.")

def update_all_contenttypes(verbosity=2, **kwargs):
for app in cache.get_models_modules():
for app in app_cache.get_models_modules():
update_contenttypes(app, None, verbosity, **kwargs)

signals.post_syncdb.connect(update_contenttypes)
Expand Down
4 changes: 2 additions & 2 deletions django/contrib/gis/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def geodjango_suite(apps=True):
Returns a TestSuite consisting only of GeoDjango tests that can be run.
"""
import sys
from django.apps import cache
from django.apps import app_cache

suite = unittest.TestSuite()

Expand All @@ -76,7 +76,7 @@ def geodjango_suite(apps=True):
# Finally, adding the suites for each of the GeoDjango test apps.
if apps:
for app_name in geo_apps(namespace=False):
suite.addTest(build_suite(cache.get_models_module(app_name)))
suite.addTest(build_suite(app_cache.get_models_module(app_name)))

return suite

Expand Down
4 changes: 2 additions & 2 deletions django/contrib/staticfiles/finders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from django.apps import cache
from django.apps import app_cache
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.files.storage import default_storage, Storage, FileSystemStorage
Expand Down Expand Up @@ -120,7 +120,7 @@ def __init__(self, *args, **kwargs):
self.apps = []
# Mapping of app module paths to storage instances
self.storages = SortedDict()
for app in cache.loaded_apps:
for app in app_cache.loaded_apps:
app_storage = self.storage_class(app)
if os.path.isdir(app_storage.location):
self.storages[app] = app_storage
Expand Down
14 changes: 7 additions & 7 deletions django/core/management/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import imp
import warnings

from django.apps import cache
from django.apps import app_cache
from django.core.management.base import BaseCommand, CommandError, handle_default_options
from django.core.management.color import color_style
from django.utils.importlib import import_module
Expand Down Expand Up @@ -104,9 +104,9 @@ def get_commands():

# Find the installed apps
try:
from django.apps import cache
cache._populate()
apps = cache.loaded_apps
from django.apps import app_cache
app_cache._populate()
apps = app_cache.loaded_apps
except (AttributeError, EnvironmentError, ImportError):
apps = []

Expand Down Expand Up @@ -323,7 +323,7 @@ def autocomplete(self):
try:
from django.conf import settings
# Get the last part of the dotted path as the app name.
options += [(app._meta.label, 0) for app in cache.loaded_apps]
options += [(app._meta.label, 0) for app in app_cache.loaded_apps]
except ImportError:
# Fail silently if DJANGO_SETTINGS_MODULE isn't set. The
# user will find out once they execute the command.
Expand Down Expand Up @@ -441,8 +441,8 @@ def setup_environ(settings_mod, original_settings_path=None):
sys.path.pop()

# Initialize the appcache and look for errors
from django.apps import cache
for (app_name, error) in cache.get_app_errors().items():
from django.apps import app_cache
for (app_name, error) in app_cache.get_app_errors().items():
sys.stderr.write("%s: %s" % (app_name, error))
sys.exit(1)

Expand Down
4 changes: 2 additions & 2 deletions django/core/management/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import traceback

import django
from django.apps import cache
from django.apps import app_cache
from django.core.exceptions import ImproperlyConfigured
from django.core.management.color import color_style
from django.utils.encoding import smart_str
Expand Down Expand Up @@ -308,7 +308,7 @@ def handle(self, *app_labels, **options):
if not app_labels:
raise CommandError('Enter at least one appname.')
try:
app_list = [cache.get_models_module(app_label) for app_label in app_labels]
app_list = [app_cache.get_models_module(app_label) for app_label in app_labels]
except (ImproperlyConfigured, ImportError) as e:
raise CommandError("%s. Are you sure your INSTALLED_APPS setting is correct?" % e)
output = []
Expand Down
10 changes: 5 additions & 5 deletions django/core/management/commands/dumpdata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.apps import cache
from django.apps import app_cache
from django.core.exceptions import ImproperlyConfigured
from django.core.management.base import BaseCommand, CommandError
from django.core import serializers
Expand Down Expand Up @@ -50,20 +50,20 @@ def handle(self, *app_labels, **options):
excluded_models.add(model_obj)
else:
try:
app_obj = cache.get_models_module(exclude)
app_obj = app_cache.get_models_module(exclude)
excluded_apps.add(app_obj)
except ImproperlyConfigured:
raise CommandError('Unknown app in excludes: %s' % exclude)

if len(app_labels) == 0:
app_list = SortedDict((app, None) for app in cache.get_models_modules() if app not in excluded_apps)
app_list = SortedDict((app, None) for app in app_cache.get_models_modules() if app not in excluded_apps)
else:
app_list = SortedDict()
for label in app_labels:
try:
app_label, model_label = label.split('.')
try:
app = cache.get_models_module(app_label)
app = app_cache.get_models_module(app_label)
except ImproperlyConfigured:
raise CommandError("Unknown application: %s" % app_label)
if app in excluded_apps:
Expand All @@ -81,7 +81,7 @@ def handle(self, *app_labels, **options):
# This is just an app - no model qualifier
app_label = label
try:
app = cache.get_models_module(app_label)
app = app_cache.get_models_module(app_label)
except ImproperlyConfigured:
raise CommandError("Unknown application: %s" % app_label)
if app in excluded_apps:
Expand Down
6 changes: 3 additions & 3 deletions django/core/management/commands/flush.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from optparse import make_option

from django.apps import cache
from django.apps import app_cache
from django.conf import settings
from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS
from django.core.management import call_command
Expand Down Expand Up @@ -38,7 +38,7 @@ def handle_noargs(self, **options):

# Import the 'management' module within each installed app, to register
# dispatcher events.
for app in cache.loaded_apps:
for app in app_cache.loaded_apps:
try:
import_module('%s.management' % app._meta.name)
except ImportError:
Expand Down Expand Up @@ -75,7 +75,7 @@ def handle_noargs(self, **options):
# applications to respond as if the database had been
# sync'd from scratch.
all_models = []
for app in cache.get_models_modules():
for app in app_cache.get_models_modules():
all_models.extend([
m for m in models.get_models(app, include_auto_created=True)
if router.allow_syncdb(db, m)
Expand Down
4 changes: 2 additions & 2 deletions django/core/management/commands/loaddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from optparse import make_option
import traceback

from django.apps import cache
from django.apps import app_cache
from django.conf import settings
from django.core import serializers
from django.core.management.base import BaseCommand, CommandError
Expand Down Expand Up @@ -92,7 +92,7 @@ def read(self):
compression_types['bz2'] = bz2.BZ2File

app_module_paths = []
for app in cache.get_models_modules():
for app in app_cache.get_models_modules():
if hasattr(app, '__path__'):
# It's a 'models/' subpackage
for path in app.__path__:
Expand Down
4 changes: 2 additions & 2 deletions django/core/management/commands/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def run_shell(self, shell=None):
def handle_noargs(self, **options):
# XXX: (Temporary) workaround for ticket #1796: force early loading of all
# models from installed apps.
from django.apps import cache
cache._populate()
from django.apps import app_cache
app_cache._populate()

use_plain = options.get('plain', False)
interface = options.get('interface', None)
Expand Down
6 changes: 3 additions & 3 deletions django/core/management/commands/syncdb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from optparse import make_option
import traceback

from django.apps import cache
from django.apps import app_cache
from django.conf import settings
from django.core.management import call_command
from django.core.management.base import NoArgsCommand
Expand Down Expand Up @@ -35,7 +35,7 @@ def handle_noargs(self, **options):

# Import the 'management' module within each installed app, to register
# dispatcher events.
for app in cache.loaded_apps:
for app in app_cache.loaded_apps:
try:
import_module('.management', app._meta.name)
except ImportError, exc:
Expand Down Expand Up @@ -68,7 +68,7 @@ def handle_noargs(self, **options):
[m for m in models.get_models(app._meta.models_module,
include_auto_created=True)
if app._meta.models_module and router.allow_syncdb(db, m)])
for app in cache.loaded_apps
for app in app_cache.loaded_apps
]
def model_installed(model):
opts = model._meta
Expand Down
Loading

0 comments on commit 6295185

Please sign in to comment.