Ticket #4326: django_new_admin_bug_fixed.patch
File django_new_admin_bug_fixed.patch, 3.2 KB (added by , 18 years ago) |
---|
-
django/contrib/admin/sites.py
2 2 from django.contrib.admin import ModelAdmin 3 3 from django.contrib.auth import authenticate, login 4 4 from django.db.models import Model 5 from django.db.models.base import ModelBase 5 6 from django.shortcuts import render_to_response 6 7 from django.utils.text import capfirst 7 8 from django.utils.translation import gettext_lazy 9 from django.utils.datastructures import SortedDict 8 10 import base64 9 11 import cPickle as pickle 10 12 import datetime … … 53 55 54 56 class AdminSite(object): 55 57 def __init__(self): 56 self._registry = {}# model_class class -> admin_class instance58 self._registry = SortedDict() # model_class class -> admin_class instance 57 59 58 60 def register(self, model_or_iterable, admin_class=None, **options): 59 61 """ … … 69 71 """ 70 72 admin_class = admin_class or ModelAdmin 71 73 # TODO: Handle options 72 if is subclass(model_or_iterable, Model):74 if isinstance(model_or_iterable, ModelBase) and issubclass(model_or_iterable, Model): 73 75 model_or_iterable = [model_or_iterable] 74 76 for model in model_or_iterable: 75 77 if model in self._registry: 76 raise AlreadyRegistered('The model %s is already registered' % model.__class__.__name__) 78 raise AlreadyRegistered('The model %s is already registered' % model.__name__) 79 model._meta.admin = admin_class 77 80 self._registry[model] = admin_class(model) 78 81 79 82 def unregister(self, model_or_iterable): … … 234 237 Displays the main admin index page, which lists all of the installed 235 238 apps that have been registered in this site. 236 239 """ 237 app _list = []240 apps = SortedDict() 238 241 user = request.user 239 242 for model, model_admin in self._registry.items(): 240 243 app_label = model._meta.app_label … … 254 257 'admin_url': '%s/%s/' % (app_label, model.__name__.lower()), 255 258 'perms': perms, 256 259 } 257 app_list.append({ 258 'name': app_label.title(), 259 'has_module_perms': has_module_perms, 260 'models': [model_dict], 261 }) 260 if app_label in apps: 261 apps[app_label]['models'].append(model_dict) 262 else: 263 apps[app_label] = { 264 'name': app_label.title(), 265 # I found that this isn't used in template. 266 #'has_module_perms': has_module_perms, 267 'models': [model_dict], 268 } 262 269 return render_to_response('admin/index.html', { 263 270 'title': _('Site administration'), 264 'app_list': app _list,271 'app_list': apps.values(), 265 272 }, context_instance=template.RequestContext(request)) 266 273 267 274 # This global object represents the default admin site, for the common case.