Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@brosner brosner authored
View
1  AUTHORS
@@ -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>
View
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
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; }
View
4 django/contrib/admin/options.py
@@ -522,6 +522,7 @@ def add_view(self, request, form_url='', extra_context=None):
'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 @@ def change_view(self, request, object_id, extra_context=None):
'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 @@ def changelist_view(self, request, extra_context=None):
'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 @@ def delete_view(self, request, object_id, extra_context=None):
"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 [
View
42 django/contrib/admin/sites.py
@@ -170,6 +170,8 @@ def root(self, request, url):
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 @@ def index(self, request, extra_context=None):
else:
app_dict[app_label] = {
'name': app_label.title(),
+ 'app_url': app_label,
'has_module_perms': has_module_perms,
'models': [model_dict],
}
@@ -360,7 +363,44 @@ def display_login_form(self, request, error_message='', extra_context=None):
return render_to_response(self.login_template or 'admin/login.html', context,
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.
View
15 django/contrib/admin/templates/admin/app_index.html
@@ -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
1  django/contrib/admin/templates/admin/change_form.html
@@ -15,6 +15,7 @@
{% block breadcrumbs %}{% if not is_popup %}
<div class="breadcrumbs">
<a href="../../../">{% trans "Home" %}</a> &rsaquo;
+ <a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
<a href="../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
{% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
</div>
View
2  django/contrib/admin/templates/admin/change_list.html
@@ -5,7 +5,7 @@
{% 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 %}
View
1  django/contrib/admin/templates/admin/delete_confirmation.html
@@ -4,6 +4,7 @@
{% block breadcrumbs %}
<div class="breadcrumbs">
<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="../">{{ object|escape|truncatewords:"18" }}</a> &rsaquo;
{% trans 'Delete' %}
View
2  django/contrib/admin/templates/admin/index.html
@@ -16,7 +16,7 @@
{% for app in app_list %}
<div class="module">
<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 %}
<tr>
{% if model.perms.change %}
Please sign in to comment.
Something went wrong with that request. Please try again.