Commit 77c78201 authored by Brian Rosner's avatar Brian Rosner
Browse files

Fixed #1390 -- Added an app index in the admin interface. Thanks juliae and...

Fixed #1390 -- Added an app index in the admin interface. Thanks juliae and ext for their work on patches.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8474 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent ab26efc9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -207,6 +207,7 @@ answer newbie questions, and generally made Django that much better:
    Nis Jørgensen <nis@superlativ.dk>
    Michael Josephson <http://www.sdjournal.com/>
    jpellerin@gmail.com
    juliae
    junzhang.jn@gmail.com
    Antti Kaihola <http://akaihola.blogspot.com/>
    Bahadır Kandemir <bahadir@pardus.org.tr>
+1 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ body { margin:0; padding:0; font-size:12px; font-family:"Lucida Grande","DejaVu
a:link, a:visited { color: #5b80b2; text-decoration:none; }
a:hover { color: #036; }
a img { border:none; }
a.section:link, a.section:visited { color: white; text-decoration:none; }

/* GLOBAL DEFAULTS */
p, ol, ul, dl { margin:.2em 0 .8em 0; }
+4 −0
Original line number Diff line number Diff line
@@ -522,6 +522,7 @@ class ModelAdmin(BaseModelAdmin):
            'inline_admin_formsets': inline_admin_formsets,
            'errors': helpers.AdminErrorList(form, formsets),
            'root_path': self.admin_site.root_path,
            'app_label': app_label,
        }
        context.update(extra_context or {})
        return self.render_change_form(request, context, add=True)
@@ -600,6 +601,7 @@ class ModelAdmin(BaseModelAdmin):
            'inline_admin_formsets': inline_admin_formsets,
            'errors': helpers.AdminErrorList(form, formsets),
            'root_path': self.admin_site.root_path,
            'app_label': app_label,
        }
        context.update(extra_context or {})
        return self.render_change_form(request, context, change=True, obj=obj)
@@ -631,6 +633,7 @@ class ModelAdmin(BaseModelAdmin):
            'cl': cl,
            'has_add_permission': self.has_add_permission(request),
            'root_path': self.admin_site.root_path,
            'app_label': app_label,
        }
        context.update(extra_context or {})
        return render_to_response(self.change_list_template or [
@@ -685,6 +688,7 @@ class ModelAdmin(BaseModelAdmin):
            "perms_lacking": perms_needed,
            "opts": opts,
            "root_path": self.admin_site.root_path,
            "app_label": app_label,
        }
        context.update(extra_context or {})
        return render_to_response(self.delete_confirmation_template or [
+41 −1
Original line number Diff line number Diff line
@@ -170,6 +170,8 @@ class AdminSite(object):
        else:
            if '/' in url:
                return self.model_page(request, *url.split('/', 2))
            else:
                return self.app_index(request, url)

        raise http.Http404('The requested admin page does not exist.')

@@ -315,6 +317,7 @@ class AdminSite(object):
                    else:
                        app_dict[app_label] = {
                            'name': app_label.title(),
                            'app_url': app_label,
                            'has_module_perms': has_module_perms,
                            'models': [model_dict],
                        }
@@ -361,6 +364,43 @@ class AdminSite(object):
            context_instance=template.RequestContext(request)
        )
        
    def app_index(self, request, app_label):
        user = request.user
        has_module_perms = user.has_module_perms(app_label)
        app_dict = {}
        for model, model_admin in self._registry.items():
            if app_label == model._meta.app_label:
                if has_module_perms:
                    perms = {
                        'add': user.has_perm("%s.%s" % (app_label, model._meta.get_add_permission())),
                        'change': user.has_perm("%s.%s" % (app_label, model._meta.get_change_permission())),
                        'delete': user.has_perm("%s.%s" % (app_label, model._meta.get_delete_permission())),
                    }
                    # Check whether user has any perm for this module.
                    # If so, add the module to the model_list.
                    if True in perms.values():
                        model_dict = {
                            'name': capfirst(model._meta.verbose_name_plural),
                            'admin_url': '%s/' % model.__name__.lower(),
                            'perms': perms,
                        }
                    if app_dict:
                        app_dict['models'].append(model_dict),
                    else:
                        app_dict = {
                            'name': app_label.title(),
                            'app_url': '',
                            'has_module_perms': has_module_perms,
                            'models': [model_dict],
                        }
                    if not app_dict:
                        raise http.Http404('The requested admin page does not exist.')
        # Sort the models alphabetically within each app.
        app_dict['models'].sort(lambda x, y: cmp(x['name'], y['name']))
        return render_to_response('admin/app_index.html', {
            'title': _('%s administration' % capfirst(app_label)),
            'app_list': [app_dict]
        }, context_instance=template.RequestContext(request))

# This global object represents the default admin site, for the common case.
# You can instantiate AdminSite in your own code to create a custom admin site.
+15 −0
Original line number Diff line number Diff line
{% extends "admin/index.html" %} 
{% load i18n %} 

{% if not is_popup %}

{% block breadcrumbs %}
<div class="breadcrumbs"><a href="../">
{% trans "Home" %}</a> &rsaquo; 
{% for app in app_list %}
{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}
{% endfor %}</div>{% endblock %}

{% endif %} 

{% block sidebar %}{% endblock %}
 No newline at end of file
Loading