Code

Ticket #10595: patch_django_10595.20090324.diff

File patch_django_10595.20090324.diff, 3.0 KB (added by david, 5 years ago)

First try

Line 
1Index: django/contrib/admin/options.py
2===================================================================
3--- django/contrib/admin/options.py     (revision 10129)
4+++ django/contrib/admin/options.py     (working copy)
5@@ -207,7 +207,7 @@
6         for inline_class in self.inlines:
7             inline_instance = inline_class(self.model, self.admin_site)
8             self.inline_instances.append(inline_instance)
9-        if 'action_checkbox' not in self.list_display:
10+        if 'action_checkbox' not in self.list_display and self.actions is not None:
11             self.list_display = ['action_checkbox'] +  list(self.list_display)
12         if not self.list_display_links:
13             for name in self.list_display:
14@@ -421,7 +421,10 @@
15         """
16         actions = {}
17         for klass in [self.admin_site] + self.__class__.mro()[::-1]:
18-            for action in getattr(klass, 'actions', []):
19+            class_actions = getattr(klass, 'actions', [])
20+            if not class_actions:
21+                continue # avoid iteration over None value
22+            for action in class_actions:
23                 func, name, description = self.get_action(action)
24                 actions[name] = (func, name, description)
25         return actions
26@@ -948,8 +951,15 @@
27             media = self.media
28             
29         # Build the action form and populate it with available actions.
30-        action_form = self.action_form(auto_id=None)
31-        action_form.fields['action'].choices = self.get_action_choices(request)       
32+        if self.actions is None:
33+            action_form = False
34+            actions_on_top = False
35+            actions_on_bottom = False
36+        else:
37+            action_form = self.action_form(auto_id=None)
38+            action_form.fields['action'].choices = self.get_action_choices(request)
39+            actions_on_top = self.actions_on_top
40+            actions_on_bottom = self.actions_on_bottom
41 
42         context = {
43             'title': cl.title,
44@@ -960,8 +970,8 @@
45             'root_path': self.admin_site.root_path,
46             'app_label': app_label,
47             'action_form': action_form,
48-            'actions_on_top': self.actions_on_top,
49-            'actions_on_bottom': self.actions_on_bottom,
50+            'actions_on_top': actions_on_top,
51+            'actions_on_bottom': actions_on_bottom,
52         }
53         context.update(extra_context or {})
54         return render_to_response(self.change_list_template or [
55Index: django/contrib/admin/templates/admin/change_list.html
56===================================================================
57--- django/contrib/admin/templates/admin/change_list.html       (revision 10129)
58+++ django/contrib/admin/templates/admin/change_list.html       (working copy)
59@@ -9,6 +9,11 @@
60     <script type="text/javascript" src="../../jsi18n/"></script>
61   {% endif %}
62   {{ media }}
63+  {% if not actions_on_top and not actions_on_bottom %}
64+    <style>
65+      #changelist table thead th:first-child {width: inherit}
66+    </style>
67+  {% endif %}
68 {% endblock %}
69 
70 {% block bodyclass %}change-list{% endblock %}