Code

Ticket #1390: app-name-in-admin-breadcrumbs2.diff

File app-name-in-admin-breadcrumbs2.diff, 10.5 KB (added by eXt, 7 years ago)

Updated patch against 6930

Line 
1Index: django/contrib/admin/media/css/global.css
2===================================================================
3--- django/contrib/admin/media/css/global.css   (revision 6903)
4+++ django/contrib/admin/media/css/global.css   (working copy)
5@@ -5,6 +5,8 @@
6 a:hover { color: #036; }
7 a img { border:none; }
8 
9+a.section:link, a.section:visited { color: white; text-decoration:none; }
10+
11 /* GLOBAL DEFAULTS */
12 p, ol, ul, dl { margin:.2em 0 .8em 0; }
13 p { padding:0; line-height:140%; }
14Index: django/contrib/admin/options.py
15===================================================================
16--- django/contrib/admin/options.py     (revision 6903)
17+++ django/contrib/admin/options.py     (working copy)
18@@ -526,6 +526,7 @@
19             'show_delete': False,
20             'media': mark_safe(media),
21             'inline_admin_formsets': inline_admin_formsets,
22+            'app_label': app_label,
23         })
24         return self.render_change_form(request, model, c, add=True)
25 
26@@ -601,6 +602,7 @@
27             'is_popup': request.REQUEST.has_key('_popup'),
28             'media': mark_safe(media),
29             'inline_admin_formsets': inline_admin_formsets,
30+            'app_label': app_label,
31         })
32         return self.render_change_form(request, model, c, change=True, obj=obj)
33 
34@@ -627,6 +629,7 @@
35             'title': cl.title,
36             'is_popup': cl.is_popup,
37             'cl': cl,
38+            'app_label': app_label,
39         })
40         c.update({'has_add_permission': self.has_add_permission(request)}),
41         return render_to_response(['admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
42@@ -669,16 +672,17 @@
43             request.user.message_set.create(message=_('The %(name)s "%(obj)s" was deleted successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj_display)})
44             return HttpResponseRedirect("../../")
45         extra_context = {
46-            "title": _("Are you sure?"),
47-            "object_name": opts.verbose_name,
48-            "object": obj,
49-            "deleted_objects": deleted_objects,
50-            "perms_lacking": perms_needed,
51-            "opts": opts,
52+            'title': _('Are you sure?'),
53+            'object_name': opts.verbose_name,
54+            'object': obj,
55+            'deleted_objects': deleted_objects,
56+            'perms_lacking': perms_needed,
57+            'opts': opts,
58+            'app_label': app_label,
59         }
60-        return render_to_response(["admin/%s/%s/delete_confirmation.html" % (app_label, opts.object_name.lower() ),
61-                                "admin/%s/delete_confirmation.html" % app_label ,
62-                                "admin/delete_confirmation.html"], extra_context, context_instance=template.RequestContext(request))
63+        return render_to_response(['admin/%s/%s/delete_confirmation.html' % (app_label, opts.object_name.lower() ),
64+                                'admin/%s/delete_confirmation.html' % app_label ,
65+                                'admin/delete_confirmation.html'], extra_context, context_instance=template.RequestContext(request))
66 
67     def history_view(self, request, object_id):
68         "The 'history' admin view for this model."
69Index: django/contrib/admin/templates/admin/change_list.html
70===================================================================
71--- django/contrib/admin/templates/admin/change_list.html       (revision 6903)
72+++ django/contrib/admin/templates/admin/change_list.html       (working copy)
73@@ -7,7 +7,7 @@
74 
75 {% block userlinks %}<a href="../../doc/">{% trans 'Documentation' %}</a> / <a href="../../password_change/">{% trans 'Change password' %}</a> / <a href="../../logout/">{% trans 'Log out' %}</a>{% endblock %}
76 
77-{% 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 %}
78+{% 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 %}
79 
80 {% block coltype %}flex{% endblock %}
81 
82Index: django/contrib/admin/templates/admin/index.html
83===================================================================
84--- django/contrib/admin/templates/admin/index.html     (revision 6903)
85+++ django/contrib/admin/templates/admin/index.html     (working copy)
86@@ -16,7 +16,7 @@
87     {% for app in app_list %}
88         <div class="module">
89         <table summary="{% blocktrans with app.name as name %}Models available in the {{ name }} application.{% endblocktrans %}">
90-        <caption>{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</caption>
91+        <caption><a href="{{ app.app_url }}" class="section">{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</a></caption>
92         {% for model in app.models %}
93             <tr>
94             {% if model.perms.change %}
95Index: django/contrib/admin/templates/admin/app_index.html
96===================================================================
97--- django/contrib/admin/templates/admin/app_index.html (revision 0)
98+++ django/contrib/admin/templates/admin/app_index.html (revision 0)
99@@ -0,0 +1,5 @@
100+{% extends "admin/index.html" %}
101+{% load i18n %}
102+
103+{% 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 %}
104+{% block sidebar %}{% endblock %}
105\ No newline at end of file
106Index: django/contrib/admin/templates/admin/change_form.html
107===================================================================
108--- django/contrib/admin/templates/admin/change_form.html       (revision 6903)
109+++ django/contrib/admin/templates/admin/change_form.html       (working copy)
110@@ -17,6 +17,7 @@
111 {% block breadcrumbs %}{% if not is_popup %}
112 <div class="breadcrumbs">
113      <a href="../../../">{% trans "Home" %}</a> &rsaquo;
114+     <a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
115      <a href="../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
116      {% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
117 </div>
118Index: django/contrib/admin/templates/admin/delete_confirmation.html
119===================================================================
120--- django/contrib/admin/templates/admin/delete_confirmation.html       (revision 6903)
121+++ django/contrib/admin/templates/admin/delete_confirmation.html       (working copy)
122@@ -6,6 +6,7 @@
123 {% block breadcrumbs %}
124 <div class="breadcrumbs">
125      <a href="../../../../">{% trans "Home" %}</a> &rsaquo;
126+     <a href="../../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
127      <a href="../../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
128      <a href="../">{{ object|escape|truncatewords:"18" }}</a> &rsaquo;
129      {% trans 'Delete' %}
130Index: django/contrib/admin/sites.py
131===================================================================
132--- django/contrib/admin/sites.py       (revision 6903)
133+++ django/contrib/admin/sites.py       (working copy)
134@@ -115,7 +115,6 @@
135         if not self.has_permission(request):
136             return self.login(request)
137 
138-
139         if url == '':
140             return self.index(request)
141         elif url == 'password_change':
142@@ -132,9 +131,11 @@
143             match = USER_CHANGE_PASSWORD_URL_RE.match(url)
144             if match:
145                 return self.user_change_password(request, match.group(1))
146-               
147+
148             if '/' in url:
149                 return self.model_page(request, *url.split('/', 2))
150+            else:
151+                return self.app_index(request, url)
152 
153         raise http.Http404('The requested admin page does not exist.')
154 
155@@ -281,6 +282,7 @@
156                     else:
157                         app_dict[app_label] = {
158                             'name': app_label.title(),
159+                            'app_url': app_label,
160                             'has_module_perms': has_module_perms,
161                             'models': [model_dict],
162                         }
163@@ -298,6 +300,51 @@
164             'app_list': app_list,
165         }, context_instance=template.RequestContext(request))
166 
167+    def app_index(self, request, app_label):
168+        """
169+        Displays the application's index page, which lists all of
170+        the application's models
171+        """
172+       
173+        user = request.user
174+        has_module_perms = user.has_module_perms(app_label)
175+        app_dict = {}
176+        for model, model_admin in self._registry.items():
177+            if app_label == model._meta.app_label:
178+                if has_module_perms:
179+                    perms = {
180+                        'add': user.has_perm("%s.%s" % (app_label, model._meta.get_add_permission())),
181+                        'change': user.has_perm("%s.%s" % (app_label, model._meta.get_change_permission())),
182+                        'delete': user.has_perm("%s.%s" % (app_label, model._meta.get_delete_permission())),
183+                    }
184+       
185+                    # Check whether user has any perm for this module.
186+                    # If so, add the module to the model_list.
187+                    if True in perms.values():
188+                        model_dict = {
189+                            'name': capfirst(model._meta.verbose_name_plural),
190+                            'admin_url': '%s/' % model.__name__.lower(),
191+                            'perms': perms,
192+                        }
193+                        if app_dict:
194+                            app_dict['models'].append(model_dict)
195+                        else:
196+                            app_dict = {
197+                                'name': app_label.title(),
198+                                'app_url':'',
199+                                'has_module_perms': has_module_perms,
200+                                'models': [model_dict],
201+                            }
202+        if not app_dict:
203+            raise http.Http404('The requested admin page does not exist.')
204+        # Sort the models alphabetically within each app.
205+        app_dict['models'].sort(lambda x, y: cmp(x['name'], y['name']))
206+
207+        return render_to_response('admin/app_index.html', {
208+            'title': _('%s administration' % capfirst(app_label)),
209+            'app_list': [app_dict,],
210+        }, context_instance=template.RequestContext(request))
211+
212 # This global object represents the default admin site, for the common case.
213 # You can instantiate AdminSite in your own code to create a custom admin site.
214 site = AdminSite()