Skip to content

Commit

Permalink
[soc2010/app-loading] added verbose_name to app instance and modified…
Browse files Browse the repository at this point in the history
… admin to use it

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/app-loading@13592 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
arthurk committed Aug 15, 2010
1 parent 773d6db commit 6b62efd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
7 changes: 4 additions & 3 deletions django/contrib/admin/__init__.py
Expand Up @@ -2,7 +2,7 @@
from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL
from django.contrib.admin.options import StackedInline, TabularInline
from django.contrib.admin.sites import AdminSite, site

from django.core.apps import cache

def autodiscover():
"""
Expand All @@ -16,8 +16,9 @@ def autodiscover():
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule

for app in settings.INSTALLED_APPS:
mod = import_module(app)
for app in cache.installed_apps:
app_instance = cache.find_app(app)
mod = app_instance.module
# Attempt to import the app's admin module.
try:
before_import_registry = copy.copy(site._registry)
Expand Down
11 changes: 6 additions & 5 deletions django/contrib/admin/options.py
Expand Up @@ -8,6 +8,7 @@
from django.contrib.admin.util import unquote, flatten_fieldsets, get_deleted_objects, model_ngettext, model_format_dict
from django.contrib import messages
from django.views.decorators.csrf import csrf_protect
from django.core.apps import cache
from django.core.exceptions import PermissionDenied, ValidationError
from django.db import models, transaction
from django.db.models.fields import BLANK_CHOICE_DASH
Expand Down Expand Up @@ -845,7 +846,7 @@ def add_view(self, request, form_url='', extra_context=None):
'inline_admin_formsets': inline_admin_formsets,
'errors': helpers.AdminErrorList(form, formsets),
'root_path': self.admin_site.root_path,
'app_label': opts.app_label,
'app_label': cache.find_app(opts.app_label).verbose_name,
}
context.update(extra_context or {})
return self.render_change_form(request, context, form_url=form_url, add=True)
Expand Down Expand Up @@ -937,7 +938,7 @@ def change_view(self, request, object_id, extra_context=None):
'inline_admin_formsets': inline_admin_formsets,
'errors': helpers.AdminErrorList(form, formsets),
'root_path': self.admin_site.root_path,
'app_label': opts.app_label,
'app_label': cache.find_app(opts.app_label).verbose_name,
}
context.update(extra_context or {})
return self.render_change_form(request, context, change=True, obj=obj)
Expand Down Expand Up @@ -1076,7 +1077,7 @@ def changelist_view(self, request, extra_context=None):
'media': media,
'has_add_permission': self.has_add_permission(request),
'root_path': self.admin_site.root_path,
'app_label': app_label,
'app_label': cache.find_app(app_label).verbose_name,
'action_form': action_form,
'actions_on_top': self.actions_on_top,
'actions_on_bottom': self.actions_on_bottom,
Expand Down Expand Up @@ -1129,7 +1130,7 @@ def delete_view(self, request, object_id, extra_context=None):
"perms_lacking": perms_needed,
"opts": opts,
"root_path": self.admin_site.root_path,
"app_label": app_label,
"app_label": cache.find_app(app_label).verbose_name,
}
context.update(extra_context or {})
context_instance = template.RequestContext(request, current_app=self.admin_site.name)
Expand Down Expand Up @@ -1157,7 +1158,7 @@ def history_view(self, request, object_id, extra_context=None):
'module_name': capfirst(force_unicode(opts.verbose_name_plural)),
'object': obj,
'root_path': self.admin_site.root_path,
'app_label': app_label,
'app_label': cache.find_app(app_label).verbose_name,
}
context.update(extra_context or {})
context_instance = template.RequestContext(request, current_app=self.admin_site.name)
Expand Down
8 changes: 5 additions & 3 deletions django/contrib/admin/sites.py
Expand Up @@ -5,6 +5,7 @@
from django.contrib.auth import authenticate, login
from django.views.decorators.csrf import csrf_protect
from django.db.models.base import ModelBase
from django.core.apps import cache
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response
Expand Down Expand Up @@ -371,7 +372,7 @@ def index(self, request, extra_context=None):
app_dict[app_label]['models'].append(model_dict)
else:
app_dict[app_label] = {
'name': app_label.title(),
'name': cache.find_app(app_label).verbose_name,
'app_url': app_label + '/',
'has_module_perms': has_module_perms,
'models': [model_dict],
Expand Down Expand Up @@ -415,6 +416,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_instance = cache.find_app(app_label)
for model, model_admin in self._registry.items():
if app_label == model._meta.app_label:
if has_module_perms:
Expand All @@ -435,7 +437,7 @@ def app_index(self, request, app_label, extra_context=None):
# something to display, add in the necessary meta
# information.
app_dict = {
'name': app_label.title(),
'name': app_instance.verbose_name,
'app_url': '',
'has_module_perms': has_module_perms,
'models': [model_dict],
Expand All @@ -445,7 +447,7 @@ def app_index(self, request, app_label, extra_context=None):
# Sort the models alphabetically within each app.
app_dict['models'].sort(lambda x, y: cmp(x['name'], y['name']))
context = {
'title': _('%s administration') % capfirst(app_label),
'title': _('%s administration') % app_instance.verbose_name,
'app_list': [app_dict],
'root_path': self.root_path,
}
Expand Down
9 changes: 8 additions & 1 deletion django/core/apps.py
Expand Up @@ -3,6 +3,7 @@
from django.utils.datastructures import SortedDict
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule
from django.utils.translation import ugettext as _

import imp
import sys
Expand All @@ -22,9 +23,14 @@ class App(object):
"""
def __init__(self, name):
self.name = name
# errors raised when trying to import the app
self.verbose_name = _(name.title())
self.verbose_name_plural = _(name.title())
self.errors = []
self.models = []
self.module = None

def __str__(self):
return self.name

def __repr__(self):
return '<App: %s>' % self.name
Expand Down Expand Up @@ -127,6 +133,7 @@ def load_app(self, app_name, can_postpone=False):
else:
app_instance_name = app_name
app_instance = app_class(app_instance_name)
app_instance.module = app_module
self.app_instances.append(app_instance)
self.installed_apps.append(app_name)

Expand Down
3 changes: 2 additions & 1 deletion django/core/management/commands/syncdb.py
Expand Up @@ -2,6 +2,7 @@
import sys

from django.conf import settings
from django.core.apps import cache
from django.core.management.base import NoArgsCommand
from django.core.management.color import no_style
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
Expand Down Expand Up @@ -30,7 +31,7 @@ def handle_noargs(self, **options):

# Import the 'management' module within each installed app, to register
# dispatcher events.
for app_name in settings.INSTALLED_APPS:
for app_name in cache.installed_apps:
try:
import_module('.management', app_name)
except ImportError, exc:
Expand Down
9 changes: 4 additions & 5 deletions django/template/loaders/app_directories.py
Expand Up @@ -8,6 +8,7 @@

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.apps import cache
from django.template import TemplateDoesNotExist
from django.template.loader import BaseLoader
from django.utils._os import safe_join
Expand All @@ -16,11 +17,9 @@
# At compile time, cache the directories to search.
fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
app_template_dirs = []
for app in settings.INSTALLED_APPS:
try:
mod = import_module(app)
except ImportError, e:
raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))
for app in cache.installed_apps:
app_instance = cache.find_app(app)
mod = app_instance.module
template_dir = os.path.join(os.path.dirname(mod.__file__), 'templates')
if os.path.isdir(template_dir):
app_template_dirs.append(template_dir.decode(fs_encoding))
Expand Down

0 comments on commit 6b62efd

Please sign in to comment.