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
This commit is contained in:
Brian Rosner 2008-08-23 04:00:15 +00:00
parent ab26efc952
commit 77c78201b8
9 changed files with 66 additions and 3 deletions

View File

@ -207,6 +207,7 @@ answer newbie questions, and generally made Django that much better:
Nis Jørgensen <nis@superlativ.dk> Nis Jørgensen <nis@superlativ.dk>
Michael Josephson <http://www.sdjournal.com/> Michael Josephson <http://www.sdjournal.com/>
jpellerin@gmail.com jpellerin@gmail.com
juliae
junzhang.jn@gmail.com junzhang.jn@gmail.com
Antti Kaihola <http://akaihola.blogspot.com/> Antti Kaihola <http://akaihola.blogspot.com/>
Bahadır Kandemir <bahadir@pardus.org.tr> Bahadır Kandemir <bahadir@pardus.org.tr>

View File

@ -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:link, a:visited { color: #5b80b2; text-decoration:none; }
a:hover { color: #036; } a:hover { color: #036; }
a img { border:none; } a img { border:none; }
a.section:link, a.section:visited { color: white; text-decoration:none; }
/* GLOBAL DEFAULTS */ /* GLOBAL DEFAULTS */
p, ol, ul, dl { margin:.2em 0 .8em 0; } p, ol, ul, dl { margin:.2em 0 .8em 0; }

View File

@ -522,6 +522,7 @@ class ModelAdmin(BaseModelAdmin):
'inline_admin_formsets': inline_admin_formsets, 'inline_admin_formsets': inline_admin_formsets,
'errors': helpers.AdminErrorList(form, formsets), 'errors': helpers.AdminErrorList(form, formsets),
'root_path': self.admin_site.root_path, 'root_path': self.admin_site.root_path,
'app_label': app_label,
} }
context.update(extra_context or {}) context.update(extra_context or {})
return self.render_change_form(request, context, add=True) return self.render_change_form(request, context, add=True)
@ -600,6 +601,7 @@ class ModelAdmin(BaseModelAdmin):
'inline_admin_formsets': inline_admin_formsets, 'inline_admin_formsets': inline_admin_formsets,
'errors': helpers.AdminErrorList(form, formsets), 'errors': helpers.AdminErrorList(form, formsets),
'root_path': self.admin_site.root_path, 'root_path': self.admin_site.root_path,
'app_label': app_label,
} }
context.update(extra_context or {}) context.update(extra_context or {})
return self.render_change_form(request, context, change=True, obj=obj) return self.render_change_form(request, context, change=True, obj=obj)
@ -631,6 +633,7 @@ class ModelAdmin(BaseModelAdmin):
'cl': cl, 'cl': cl,
'has_add_permission': self.has_add_permission(request), 'has_add_permission': self.has_add_permission(request),
'root_path': self.admin_site.root_path, 'root_path': self.admin_site.root_path,
'app_label': app_label,
} }
context.update(extra_context or {}) context.update(extra_context or {})
return render_to_response(self.change_list_template or [ return render_to_response(self.change_list_template or [
@ -685,6 +688,7 @@ class ModelAdmin(BaseModelAdmin):
"perms_lacking": perms_needed, "perms_lacking": perms_needed,
"opts": opts, "opts": opts,
"root_path": self.admin_site.root_path, "root_path": self.admin_site.root_path,
"app_label": app_label,
} }
context.update(extra_context or {}) context.update(extra_context or {})
return render_to_response(self.delete_confirmation_template or [ return render_to_response(self.delete_confirmation_template or [

View File

@ -170,6 +170,8 @@ class AdminSite(object):
else: else:
if '/' in url: if '/' in url:
return self.model_page(request, *url.split('/', 2)) 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.') raise http.Http404('The requested admin page does not exist.')
@ -315,6 +317,7 @@ class AdminSite(object):
else: else:
app_dict[app_label] = { app_dict[app_label] = {
'name': app_label.title(), 'name': app_label.title(),
'app_url': app_label,
'has_module_perms': has_module_perms, 'has_module_perms': has_module_perms,
'models': [model_dict], 'models': [model_dict],
} }
@ -361,6 +364,43 @@ class AdminSite(object):
context_instance=template.RequestContext(request) 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. # 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. # You can instantiate AdminSite in your own code to create a custom admin site.

View File

@ -0,0 +1,15 @@
{% 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 %}

View File

@ -15,6 +15,7 @@
{% block breadcrumbs %}{% if not is_popup %} {% block breadcrumbs %}{% if not is_popup %}
<div class="breadcrumbs"> <div class="breadcrumbs">
<a href="../../../">{% trans "Home" %}</a> &rsaquo; <a href="../../../">{% trans "Home" %}</a> &rsaquo;
<a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
<a href="../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo; <a href="../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
{% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %} {% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
</div> </div>

View File

@ -5,7 +5,7 @@
{% block bodyclass %}change-list{% endblock %} {% block bodyclass %}change-list{% endblock %}
{% 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 %} {% 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 %}
{% block coltype %}flex{% endblock %} {% block coltype %}flex{% endblock %}

View File

@ -4,6 +4,7 @@
{% block breadcrumbs %} {% block breadcrumbs %}
<div class="breadcrumbs"> <div class="breadcrumbs">
<a href="../../../../">{% trans "Home" %}</a> &rsaquo; <a href="../../../../">{% trans "Home" %}</a> &rsaquo;
<a href="../../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
<a href="../../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo; <a href="../../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
<a href="../">{{ object|escape|truncatewords:"18" }}</a> &rsaquo; <a href="../">{{ object|escape|truncatewords:"18" }}</a> &rsaquo;
{% trans 'Delete' %} {% trans 'Delete' %}

View File

@ -16,7 +16,7 @@
{% for app in app_list %} {% for app in app_list %}
<div class="module"> <div class="module">
<table summary="{% blocktrans with app.name as name %}Models available in the {{ name }} application.{% endblocktrans %}"> <table summary="{% blocktrans with app.name as name %}Models available in the {{ name }} application.{% endblocktrans %}">
<caption>{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</caption> <caption><a href="{{ app.app_url }}" class="section">{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</a></caption>
{% for model in app.models %} {% for model in app.models %}
<tr> <tr>
{% if model.perms.change %} {% if model.perms.change %}