Code

Ticket #15810: dj_adm_add_applabel_class.diff

File dj_adm_add_applabel_class.diff, 5.7 KB (added by aatanasov+django@…, 3 years ago)

patch which adds AppLabel to admin used to display app_label in a friendly way

Line 
1Index: django/contrib/admin/templates/admin/change_list.html
2===================================================================
3--- django/contrib/admin/templates/admin/change_list.html       (revision 16025)
4+++ django/contrib/admin/templates/admin/change_list.html       (working copy)
5@@ -43,7 +43,7 @@
6       </a>
7        &rsaquo;
8        <a href="../">
9-         {{ app_label|capfirst }}
10+         {{ app_label.title|capfirst }}
11       </a>
12       &rsaquo;
13       {{ cl.opts.verbose_name_plural|capfirst }}
14Index: django/contrib/admin/templates/admin/delete_selected_confirmation.html
15===================================================================
16--- django/contrib/admin/templates/admin/delete_selected_confirmation.html      (revision 16025)
17+++ django/contrib/admin/templates/admin/delete_selected_confirmation.html      (working copy)
18@@ -4,7 +4,7 @@
19 {% block breadcrumbs %}
20 <div class="breadcrumbs">
21      <a href="../../">{% trans "Home" %}</a> &rsaquo;
22-     <a href="../">{{ app_label|capfirst }}</a> &rsaquo;
23+     <a href="../">{{ app_label.title|capfirst }}</a> &rsaquo;
24      <a href="./">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
25      {% trans 'Delete multiple objects' %}
26 </div>
27Index: django/contrib/admin/templates/admin/object_history.html
28===================================================================
29--- django/contrib/admin/templates/admin/object_history.html    (revision 16025)
30+++ django/contrib/admin/templates/admin/object_history.html    (working copy)
31@@ -4,7 +4,7 @@
32 {% block breadcrumbs %}
33 <div class="breadcrumbs">
34     <a href="../../../../">{% trans 'Home' %}</a> &rsaquo;
35-    <a href="../../../">{{ app_label|capfirst }}</a> &rsaquo;
36+    <a href="../../../">{{ app_label.title|capfirst }}</a> &rsaquo;
37     <a href="../../">{{ module_name }}</a> &rsaquo;
38     <a href="../">{{ object|truncatewords:"18" }}</a> &rsaquo;
39     {% trans 'History' %}
40Index: django/contrib/admin/templates/admin/auth/user/change_password.html
41===================================================================
42--- django/contrib/admin/templates/admin/auth/user/change_password.html (revision 16025)
43+++ django/contrib/admin/templates/admin/auth/user/change_password.html (working copy)
44@@ -10,7 +10,7 @@
45 {% block breadcrumbs %}{% if not is_popup %}
46 <div class="breadcrumbs">
47      <a href="../../../../">{% trans "Home" %}</a> &rsaquo;
48-     <a href="../../../">{{ opts.app_label|capfirst|escape }}</a> &rsaquo;
49+     <a href="../../../">{{ opts.app_label.title|capfirst|escape }}</a> &rsaquo;
50      <a href="../../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
51      <a href="../">{{ original|truncatewords:"18" }}</a> &rsaquo;
52      {% trans 'Change password' %}
53Index: django/contrib/admin/templates/admin/change_form.html
54===================================================================
55--- django/contrib/admin/templates/admin/change_form.html       (revision 16025)
56+++ django/contrib/admin/templates/admin/change_form.html       (working copy)
57@@ -17,7 +17,7 @@
58 {% block breadcrumbs %}{% if not is_popup %}
59 <div class="breadcrumbs">
60      <a href="../../../">{% trans "Home" %}</a> &rsaquo;
61-     <a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
62+     <a href="../../">{{ app_label.title|capfirst|escape }}</a> &rsaquo;
63      {% if has_change_permission %}<a href="../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} &rsaquo;
64      {% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
65 </div>
66Index: django/contrib/admin/templates/admin/delete_confirmation.html
67===================================================================
68--- django/contrib/admin/templates/admin/delete_confirmation.html       (revision 16025)
69+++ django/contrib/admin/templates/admin/delete_confirmation.html       (working copy)
70@@ -4,7 +4,7 @@
71 {% block breadcrumbs %}
72 <div class="breadcrumbs">
73      <a href="../../../../">{% trans "Home" %}</a> &rsaquo;
74-     <a href="../../../">{{ app_label|capfirst }}</a> &rsaquo;
75+     <a href="../../../">{{ app_label.title|capfirst }}</a> &rsaquo;
76      <a href="../../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
77      <a href="../">{{ object|truncatewords:"18" }}</a> &rsaquo;
78      {% trans 'Delete' %}
79Index: django/contrib/admin/util.py
80===================================================================
81--- django/contrib/admin/util.py        (revision 16025)
82+++ django/contrib/admin/util.py        (working copy)
83@@ -385,3 +385,15 @@
84         return limit_choices_to # already a Q
85     else:
86         return models.Q(**limit_choices_to) # convert dict to Q
87+
88+
89+class AppLabel(str):
90+    def __new__(cls,value,title=None):
91+        obj = str.__new__(cls, value)
92+        obj._my_title = title
93+        return obj
94+
95+    def title(self):
96+        if self._my_title is not None:
97+            return self._my_title
98+        return super(AppLabel,self).title()
99Index: django/contrib/admin/sites.py
100===================================================================
101--- django/contrib/admin/sites.py       (revision 16025)
102+++ django/contrib/admin/sites.py       (working copy)
103@@ -388,6 +388,7 @@
104         app_dict = {}
105         for model, model_admin in self._registry.items():
106             if app_label == model._meta.app_label:
107+                app_label = model._meta.app_label
108                 if has_module_perms:
109                     perms = model_admin.get_model_perms(request)
110 
111@@ -416,7 +417,7 @@
112         # Sort the models alphabetically within each app.
113         app_dict['models'].sort(key=lambda x: x['name'])
114         context = {
115-            'title': _('%s administration') % capfirst(app_label),
116+            'title': _('%s administration') % (app_label.title()),
117             'app_list': [app_dict],
118             'root_path': self.root_path,
119         }