mirror of
				https://github.com/django/django.git
				synced 2025-10-30 17:16:10 +00:00 
			
		
		
		
	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:
		
							
								
								
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							
							
						
						
									
										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> | ||||
|   | ||||
| @@ -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; } | ||||
|   | ||||
| @@ -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 [ | ||||
|   | ||||
| @@ -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
									
								
								django/contrib/admin/templates/admin/app_index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								django/contrib/admin/templates/admin/app_index.html
									
									
									
									
									
										Normal 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> ›  | ||||
| {% for app in app_list %} | ||||
| {% blocktrans with app.name as name %}{{ name }}{% endblocktrans %} | ||||
| {% endfor %}</div>{% endblock %} | ||||
|  | ||||
| {% endif %}  | ||||
|  | ||||
| {% block sidebar %}{% endblock %} | ||||
| @@ -15,6 +15,7 @@ | ||||
| {% block breadcrumbs %}{% if not is_popup %} | ||||
| <div class="breadcrumbs"> | ||||
|      <a href="../../../">{% trans "Home" %}</a> › | ||||
|      <a href="../../">{{ app_label|capfirst|escape }}</a> ›  | ||||
|      <a href="../">{{ opts.verbose_name_plural|capfirst }}</a> › | ||||
|      {% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %} | ||||
| </div> | ||||
|   | ||||
| @@ -5,7 +5,7 @@ | ||||
|  | ||||
| {% block bodyclass %}change-list{% endblock %} | ||||
|  | ||||
| {% if not is_popup %}{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../">{% trans "Home" %}</a> › {{ cl.opts.verbose_name_plural|capfirst|escape }}</div>{% endblock %}{% endif %} | ||||
| {% if not is_popup %}{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../">{% trans "Home" %}</a> › <a href="../">{{ app_label|capfirst|escape }}</a> › {{ cl.opts.verbose_name_plural|capfirst|escape }}</div>{% endblock %}{% endif %} | ||||
|  | ||||
| {% block coltype %}flex{% endblock %} | ||||
|  | ||||
|   | ||||
| @@ -4,6 +4,7 @@ | ||||
| {% block breadcrumbs %} | ||||
| <div class="breadcrumbs"> | ||||
|      <a href="../../../../">{% trans "Home" %}</a> › | ||||
|      <a href="../../../">{{ app_label|capfirst|escape }}</a> ›  | ||||
|      <a href="../../">{{ opts.verbose_name_plural|capfirst }}</a> › | ||||
|      <a href="../">{{ object|escape|truncatewords:"18" }}</a> › | ||||
|      {% trans 'Delete' %} | ||||
|   | ||||
| @@ -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 %} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user