Django

Code

Changeset 5441

Show
Ignore:
Timestamp:
06/07/07 17:12:58 (2 years ago)
Author:
adrian
Message:

newforms-admin: Fixed #4258 and #4477 -- Changed admin index page to group by applications, and alphabetized things. Thanks to Matthias Pronk and Honza Kral for the patches; I ended up using a hybrid of both

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/newforms-admin/django/contrib/admin/sites.py

    r4942 r5441  
    235235        apps that have been registered in this site. 
    236236        """ 
    237         app_list = [] 
     237        app_dict = {} 
    238238        user = request.user 
    239239        for model, model_admin in self._registry.items(): 
    240240            app_label = model._meta.app_label 
    241241            has_module_perms = user.has_module_perms(app_label) 
     242 
    242243            if has_module_perms: 
    243244                perms = { 
     
    255256                        'perms': perms, 
    256257                    } 
    257                     app_list.append({ 
    258                         'name': app_label.title(), 
    259                         'has_module_perms': has_module_perms, 
    260                         'models': [model_dict], 
    261                     }) 
     258                    if app_label in app_dict: 
     259                        app_dict[app_label]['models'].append(model_dict) 
     260                    else: 
     261                        app_dict[app_label] = { 
     262                            'name': app_label.title(), 
     263                            'has_module_perms': has_module_perms, 
     264                            'models': [model_dict], 
     265                        } 
     266 
     267        # Sort the apps alphabetically. 
     268        app_list = app_dict.values() 
     269        app_list.sort(lambda x, y: cmp(x['name'], y['name'])) 
     270 
     271        # Sort the models alphabetically within each app. 
     272        for app in app_list: 
     273            app['models'].sort(lambda x, y: cmp(x['name'], y['name'])) 
     274 
    262275        return render_to_response('admin/index.html', { 
    263276            'title': _('Site administration'),