8000 [soc2010/app-loading] added verbose_name to app instance and modified… · ddriddle/django@a357ed1 · GitHub
[go: up one dir, main page]

Skip to content

Commit a357ed1

Browse files
committed
[soc2010/app-loading] added verbose_name to app instance and modified admin to use it
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/app-loading@13592 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 3da601b commit a357ed1

File tree

6 files changed

+29
-18
lines changed

6 files changed

+29
-18
lines changed

django/contrib/admin/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL
33
from django.contrib.admin.options import StackedInline, TabularInline
44
from django.contrib.admin.sites import AdminSite, site
5-
5+
from django.core.apps import cache
66

77
def autodiscover():
88
"""
@@ -16,8 +16,9 @@ def autodiscover():
1616
from django.utils.importlib import import_module
1717
from django.utils.module_loading import module_has_submodule
1818

19-
for app in settings.INSTALLED_APPS:
20-
mod = import_module(app)
19+
for app in cache.installed_apps:
20+
app_instance = cache.find_app(app)
21+
mod = app_instance.module
2122
# Attempt to import the app's admin module.
2223
try:
2324
before_import_registry = copy.copy(site._registry)

django/contrib/admin/options.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from django.contrib.admin.util import unquote, flatten_fieldsets, get_deleted_objects, model_ngettext, model_format_dict
99
from django.contrib import messages
1010
from django.views.decorators.csrf import csrf_protect
11+
from django.core.apps import cache
1112
from django.core.exceptions import PermissionDenied, ValidationError
1213
from django.db import models, transaction
1314
from django.db.models.fields import BLANK_CHOICE_DASH
@@ -845,7 +846,7 @@ def add_view(self, request, form_url='', extra_context=None):
845846
'inline_admin_formsets': inline_admin_formsets,
846847
'errors': helpers.AdminErrorList(form, formsets),
847848
'root_path': self.admin_site.root_path,
848-
'app_label': opts.app_label,
849+
'app_label': cache.find_app(opts.app_label).verbose_name,
849850
}
850851
context.update(extra_context or {})
851852
return self.render_change_form(request, context, form_url=form_url, add=True)
@@ -937,7 +938,7 @@ def change_view(self, request, object_id, extra_context=None):
937938
'inline_admin_formsets': inline_admin_formsets,
938939
'errors': helpers.AdminErrorList(form, formsets),
939940
'root_path': self.admin_site.root_path,
940-
'app_label': opts.app_label,
941+
'app_label': cache.find_app(opts.app_label).verbose_name,
941942
}
942943
context.update(extra_context or {})
943944
return self.render_change_form(request, context, change=True, obj=obj)
@@ -1076,7 +1077,7 @@ def changelist_view(self, request, extra_context=None):
10761077
'media': media,
10771078
'has_add_permission': self.has_add_permission(request),
10781079
'root_path': self.admin_site.root_path,
1079-
'app_label': app_label,
1080+
'app_label': cache.find_app(app_label).verbose_name,
10801081
'action_form': action_form,
10811082
'actions_on_top': self.actions_on_top,
10821083
'actions_on_bottom': self.actions_on_bottom,
@@ -1129,7 +1130,7 @@ def delete_view(self, request, object_id, extra_context=None):
11291130
"perms_lacking": perms_needed,
11301131
"opts": opts,
11311132
"root_path": self.admin_site.root_path,
1132-
"app_label": app_label,
1133+
"app_label": cache.find_app(app_label).verbose_name,
11331134
}
11341135
context.update(extra_context or {})
11351136
context_instance = template.RequestContext(request, current_app=self.admin_site.name)
@@ -1157,7 +1158,7 @@ def history_view(self, request, object_id, extra_context=None):
11571158
'module_name': capfirst(force_unicode(opts.verbose_name_plural)),
11581159
'object': obj,
11591160
'root_path': self.admin_site.root_path,
1160-
'app_label': app_label,
1161+
'app_label': cache.find_app(app_label).verbose_name,
11611162
}
11621163
context.update(extra_context or {})
11631164
context_instance = template.RequestContext(request, current_app=self.admin_site.name)

django/contrib/admin/sites.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django.contrib.auth import authenticate, login
66
from django.views.decorators.csrf import csrf_protect
77
from django.db.models.base import ModelBase
8+
from django.core.apps import cache
89
from django.core.exceptions import ImproperlyConfigured
910
from django.core.urlresolvers import reverse
1011
from django.shortcuts import render_to_response
@@ -371,7 +372,7 @@ def index(self, request, extra_context=None):
371372
app_dict[app_label]['models'].append(model_dict)
372373
else:
373374
app_dict[app_label] = {
374-
'name': app_label.title(),
375+
'name': cache.find_app(app_label).verbose_name,
375376
'app_url': app_label + '/',
376377
'has_module_perms': has_module_perms,
377378
'models': [model_dict],
@@ -415,6 +416,7 @@ def app_index(self, request, app_label, extra_context=None):
415416
user = request.user
416417
has_module_perms = user.has_module_perms(app_label)
417418
app_dict = {}
419+
app_instance = cache.find_app(app_label)
418420
for model, model_admin in self._registry.items():
419421
if app_label == model._meta.app_label:
420422
if has_module_perms:
@@ -435,7 +437,7 @@ def app_index(self, request, app_label, extra_context=None):
435437
# something to display, add in the necessary meta
436438
# information.
437439
app_dict = {
438-
'name': app_label.title(),
440+
'name': app_instance.verbose_name,
439441
'app_url': '',
440442
F438 'has_module_perms': has_module_perms,
441443
'models': [model_dict],
@@ -445,7 +447,7 @@ def app_index(self, request, app_label, extra_context=None):
445447
# Sort the models alphabetically within each app.
446448
app_dict['models'].sort(lambda x, y: cmp(x['name'], y['name']))
447449
context = {
448-
'title': _('%s administration') % capfirst(app_label),
450+
'title': _('%s administration') % app_instance.verbose_name,
449451
'app_list': [app_dict],
450452
'root_path': self.root_path,
451453
}

django/core/apps.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.utils.datastructures import SortedDict
44
from django.utils.importlib import import_module
55
from django.utils.module_loading import module_has_submodule
6+
from django.utils.translation import ugettext as _
67

78
import imp
89
import sys
@@ -22,9 +23,14 @@ class App(object):
2223
"""
2324
def __init__(self, name):
2425
self.name = name
25-
# errors raised when trying to import the app
26+
self.verbose_name = _(name.title())
27+
self.verbose_name_plural = _(name.title())
2628
self.errors = []
2729
self.models = []
30+
self.module = None
31+
32+
def __str__(self):
33+
return self.name
2834

2935
def __repr__(self):
3036
return '<App: %s>' % self.name
@@ -127,6 +133,7 @@ def load_app(self, app_name, can_postpone=False):
127133
else:
128134
app_instance_name = app_name
129135
app_in 10000 stance = app_class(app_instance_name)
136+
app_instance.module = app_module
130137
self.app_instances.append(app_instance)
131138
self.installed_apps.append(app_name)
132139

django/core/management/commands/syncdb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33

44
from django.conf import settings
5+
from django.core.apps import cache
56
from django.core.management.base import NoArgsCommand
67
from django.core.management.color import no_style
78
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
@@ -30,7 +31,7 @@ def handle_noargs(self, **options):
3031

3132
# Import the 'management' module within each installed app, to register
3233
# dispatcher events.
33-
for app_name in settings.INSTALLED_APPS:
34+
for app_name in cache.installed_apps:
3435
try:
3536
import_module('.management', app_name)
3637
except ImportError, exc:

django/template/loaders/app_directories.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

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

0 commit comments

Comments
 (0)
0