Ticket #4477: newforms-admin-5427-app_grouping.diff

File newforms-admin-5427-app_grouping.diff, 2.1 KB (added by Honza Král <Honza.Kral@…>, 19 years ago)

Patch correcting the bug

  • django/contrib/admin/sites.py

     
    55from django.shortcuts import render_to_response
    66from django.utils.text import capfirst
    77from django.utils.translation import gettext_lazy
     8from django.utils.datastructures import SortedDict
    89import base64
    910import cPickle as pickle
    1011import datetime
    … …  
    234235        Displays the main admin index page, which lists all of the installed
    235236        apps that have been registered in this site.
    236237        """
    237         app_list = []
     238        app_dict = SortedDict()
    238239        user = request.user
    239240        for model, model_admin in self._registry.items():
    240241            app_label = model._meta.app_label
    241242            has_module_perms = user.has_module_perms(app_label)
     243
    242244            if has_module_perms:
    243245                perms = {
    244246                    'add': user.has_perm("%s.%s" % (app_label, model._meta.get_add_permission())),
    … …  
    254256                        'admin_url': '%s/%s/' % (app_label, model.__name__.lower()),
    255257                        'perms': perms,
    256258                    }
    257                     app_list.append({
    258                         'name': app_label.title(),
    259                         'has_module_perms': has_module_perms,
    260                         'models': [model_dict],
    261                     })
     259                    if app_dict.has_key( app_label ):
     260                        app_dict[app_label]['models'].append( model_dict )
     261                    else:
     262                        app_dict[app_label] = {
     263                            'name': app_label.title(),
     264                            'has_module_perms': has_module_perms,
     265                            'models': [model_dict],
     266                        }
    262267        return render_to_response('admin/index.html', {
    263268            'title': _('Site administration'),
    264             'app_list': app_list,
     269            'app_list': app_dict.values(),
    265270        }, context_instance=template.RequestContext(request))
    266271
    267272# This global object represents the default admin site, for the common case.
Back to Top