Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@5441 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fe5194ecfd8ad5ad27c6bddc10fa8c6837d290f6 1 parent d34639b
Adrian Holovaty authored June 07, 2007

Showing 1 changed file with 19 additions and 6 deletions. Show diff stats Hide diff stats

  1. 25  django/contrib/admin/sites.py
25  django/contrib/admin/sites.py
@@ -234,11 +234,12 @@ def index(self, request):
234 234
         Displays the main admin index page, which lists all of the installed
235 235
         apps that have been registered in this site.
236 236
         """
237  
-        app_list = []
  237
+        app_dict = {}
238 238
         user = request.user
239 239
         for model, model_admin in self._registry.items():
240 240
             app_label = model._meta.app_label
241 241
             has_module_perms = user.has_module_perms(app_label)
  242
+
242 243
             if has_module_perms:
243 244
                 perms = {
244 245
                     'add': user.has_perm("%s.%s" % (app_label, model._meta.get_add_permission())),
@@ -254,11 +255,23 @@ def index(self, request):
254 255
                         'admin_url': '%s/%s/' % (app_label, model.__name__.lower()),
255 256
                         'perms': perms,
256 257
                     }
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
+
262 275
         return render_to_response('admin/index.html', {
263 276
             'title': _('Site administration'),
264 277
             'app_list': app_list,

0 notes on commit fe5194e

Please sign in to comment.
Something went wrong with that request. Please try again.