Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1390 -- Added an app index in the admin interface. Thanks juli…

…ae and ext for their work on patches.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8474 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 77c78201b802c407361641a76208fc11af16b68d 1 parent ab26efc
Brian Rosner authored August 23, 2008
1  AUTHORS
@@ -207,6 +207,7 @@ answer newbie questions, and generally made Django that much better:
207 207
     Nis Jørgensen <nis@superlativ.dk>
208 208
     Michael Josephson <http://www.sdjournal.com/>
209 209
     jpellerin@gmail.com
  210
+    juliae
210 211
     junzhang.jn@gmail.com
211 212
     Antti Kaihola <http://akaihola.blogspot.com/>
212 213
     Bahadır Kandemir <bahadir@pardus.org.tr>
1  django/contrib/admin/media/css/global.css
@@ -4,6 +4,7 @@ body { margin:0; padding:0; font-size:12px; font-family:"Lucida Grande","DejaVu
4 4
 a:link, a:visited { color: #5b80b2; text-decoration:none; }
5 5
 a:hover { color: #036; }
6 6
 a img { border:none; }
  7
+a.section:link, a.section:visited { color: white; text-decoration:none; }
7 8
 
8 9
 /* GLOBAL DEFAULTS */
9 10
 p, ol, ul, dl { margin:.2em 0 .8em 0; }
4  django/contrib/admin/options.py
@@ -522,6 +522,7 @@ def add_view(self, request, form_url='', extra_context=None):
522 522
             'inline_admin_formsets': inline_admin_formsets,
523 523
             'errors': helpers.AdminErrorList(form, formsets),
524 524
             'root_path': self.admin_site.root_path,
  525
+            'app_label': app_label,
525 526
         }
526 527
         context.update(extra_context or {})
527 528
         return self.render_change_form(request, context, add=True)
@@ -600,6 +601,7 @@ def change_view(self, request, object_id, extra_context=None):
600 601
             'inline_admin_formsets': inline_admin_formsets,
601 602
             'errors': helpers.AdminErrorList(form, formsets),
602 603
             'root_path': self.admin_site.root_path,
  604
+            'app_label': app_label,
603 605
         }
604 606
         context.update(extra_context or {})
605 607
         return self.render_change_form(request, context, change=True, obj=obj)
@@ -631,6 +633,7 @@ def changelist_view(self, request, extra_context=None):
631 633
             'cl': cl,
632 634
             'has_add_permission': self.has_add_permission(request),
633 635
             'root_path': self.admin_site.root_path,
  636
+            'app_label': app_label,
634 637
         }
635 638
         context.update(extra_context or {})
636 639
         return render_to_response(self.change_list_template or [
@@ -685,6 +688,7 @@ def delete_view(self, request, object_id, extra_context=None):
685 688
             "perms_lacking": perms_needed,
686 689
             "opts": opts,
687 690
             "root_path": self.admin_site.root_path,
  691
+            "app_label": app_label,
688 692
         }
689 693
         context.update(extra_context or {})
690 694
         return render_to_response(self.delete_confirmation_template or [
42  django/contrib/admin/sites.py
@@ -170,6 +170,8 @@ def root(self, request, url):
170 170
         else:
171 171
             if '/' in url:
172 172
                 return self.model_page(request, *url.split('/', 2))
  173
+            else:
  174
+                return self.app_index(request, url)
173 175
 
174 176
         raise http.Http404('The requested admin page does not exist.')
175 177
 
@@ -315,6 +317,7 @@ def index(self, request, extra_context=None):
315 317
                     else:
316 318
                         app_dict[app_label] = {
317 319
                             'name': app_label.title(),
  320
+                            'app_url': app_label,
318 321
                             'has_module_perms': has_module_perms,
319 322
                             'models': [model_dict],
320 323
                         }
@@ -360,7 +363,44 @@ def display_login_form(self, request, error_message='', extra_context=None):
360 363
         return render_to_response(self.login_template or 'admin/login.html', context,
361 364
             context_instance=template.RequestContext(request)
362 365
         )
363  
-
  366
+        
  367
+    def app_index(self, request, app_label):
  368
+        user = request.user
  369
+        has_module_perms = user.has_module_perms(app_label)
  370
+        app_dict = {}
  371
+        for model, model_admin in self._registry.items():
  372
+            if app_label == model._meta.app_label:
  373
+                if has_module_perms:
  374
+                    perms = {
  375
+                        'add': user.has_perm("%s.%s" % (app_label, model._meta.get_add_permission())),
  376
+                        'change': user.has_perm("%s.%s" % (app_label, model._meta.get_change_permission())),
  377
+                        'delete': user.has_perm("%s.%s" % (app_label, model._meta.get_delete_permission())),
  378
+                    }
  379
+                    # Check whether user has any perm for this module.
  380
+                    # If so, add the module to the model_list.
  381
+                    if True in perms.values():
  382
+                        model_dict = {
  383
+                            'name': capfirst(model._meta.verbose_name_plural),
  384
+                            'admin_url': '%s/' % model.__name__.lower(),
  385
+                            'perms': perms,
  386
+                        }
  387
+                    if app_dict:
  388
+                        app_dict['models'].append(model_dict),
  389
+                    else:
  390
+                        app_dict = {
  391
+                            'name': app_label.title(),
  392
+                            'app_url': '',
  393
+                            'has_module_perms': has_module_perms,
  394
+                            'models': [model_dict],
  395
+                        }
  396
+                    if not app_dict:
  397
+                        raise http.Http404('The requested admin page does not exist.')
  398
+        # Sort the models alphabetically within each app.
  399
+        app_dict['models'].sort(lambda x, y: cmp(x['name'], y['name']))
  400
+        return render_to_response('admin/app_index.html', {
  401
+            'title': _('%s administration' % capfirst(app_label)),
  402
+            'app_list': [app_dict]
  403
+        }, context_instance=template.RequestContext(request))
364 404
 
365 405
 # This global object represents the default admin site, for the common case.
366 406
 # You can instantiate AdminSite in your own code to create a custom admin site.
15  django/contrib/admin/templates/admin/app_index.html
... ...
@@ -0,0 +1,15 @@
  1
+{% extends "admin/index.html" %} 
  2
+{% load i18n %} 
  3
+
  4
+{% if not is_popup %}
  5
+
  6
+{% block breadcrumbs %}
  7
+<div class="breadcrumbs"><a href="../">
  8
+{% trans "Home" %}</a> &rsaquo; 
  9
+{% for app in app_list %}
  10
+{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}
  11
+{% endfor %}</div>{% endblock %}
  12
+
  13
+{% endif %} 
  14
+
  15
+{% block sidebar %}{% endblock %}
1  django/contrib/admin/templates/admin/change_form.html
@@ -15,6 +15,7 @@
15 15
 {% block breadcrumbs %}{% if not is_popup %}
16 16
 <div class="breadcrumbs">
17 17
      <a href="../../../">{% trans "Home" %}</a> &rsaquo;
  18
+     <a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo; 
18 19
      <a href="../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
19 20
      {% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
20 21
 </div>
2  django/contrib/admin/templates/admin/change_list.html
@@ -5,7 +5,7 @@
5 5
 
6 6
 {% block bodyclass %}change-list{% endblock %}
7 7
 
8  
-{% if not is_popup %}{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../">{% trans "Home" %}</a> &rsaquo; {{ cl.opts.verbose_name_plural|capfirst|escape }}</div>{% endblock %}{% endif %}
  8
+{% if not is_popup %}{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../">{% trans "Home" %}</a> &rsaquo; <a href="../">{{ app_label|capfirst|escape }}</a> &rsaquo; {{ cl.opts.verbose_name_plural|capfirst|escape }}</div>{% endblock %}{% endif %}
9 9
 
10 10
 {% block coltype %}flex{% endblock %}
11 11
 
1  django/contrib/admin/templates/admin/delete_confirmation.html
@@ -4,6 +4,7 @@
4 4
 {% block breadcrumbs %}
5 5
 <div class="breadcrumbs">
6 6
      <a href="../../../../">{% trans "Home" %}</a> &rsaquo;
  7
+     <a href="../../../">{{ app_label|capfirst|escape }}</a> &rsaquo; 
7 8
      <a href="../../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
8 9
      <a href="../">{{ object|escape|truncatewords:"18" }}</a> &rsaquo;
9 10
      {% trans 'Delete' %}
2  django/contrib/admin/templates/admin/index.html
@@ -16,7 +16,7 @@
16 16
     {% for app in app_list %}
17 17
         <div class="module">
18 18
         <table summary="{% blocktrans with app.name as name %}Models available in the {{ name }} application.{% endblocktrans %}">
19  
-        <caption>{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</caption>
  19
+        <caption><a href="{{ app.app_url }}" class="section">{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</a></caption>
20 20
         {% for model in app.models %}
21 21
             <tr>
22 22
             {% if model.perms.change %}

0 notes on commit 77c7820

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