Commits

art...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed 27b224c

[soc2010/app-loading] added verbose_name to app instance and modified admin to use it

  • Participants
  • Parent commits de9f7ab
  • Branches soc2010/app-loading

Comments (0)

Files changed (6)

File django/contrib/admin/__init__.py

 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():
     """
     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)

File django/contrib/admin/options.py

 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
             '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)
             '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)
             '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,
             "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)
             '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)

File django/contrib/admin/sites.py

 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
                         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],
         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:
                             # 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],
         # 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,
         }

File django/core/apps.py

 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
     """
     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
             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)
 

File django/core/management/commands/syncdb.py

 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
 
         # 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:

File django/template/loaders/app_directories.py

 
 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
 # 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))