Permalink
Browse files

Fixed #10505: added support for bulk admin actions, including a globa…

…lly-available "delete selected" action. See the documentation for details.

This work started life as Brian Beck's "django-batchadmin." It was rewritten for inclusion in Django by Alex Gaynor, Jannis Leidel (jezdez), and Martin Mahner (bartTC). Thanks, guys!

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10121 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 4e25334 commit 44f3080226888eb709cc6e027321647964ebe64e @jacobian jacobian committed Mar 23, 2009
View
@@ -56,6 +56,7 @@ answer newbie questions, and generally made Django that much better:
Ned Batchelder <http://www.nedbatchelder.com/>
batiste@dosimple.ch
Batman
+ Brian Beck <http://blog.brianbeck.com/>
Shannon -jj Behrens <http://jjinux.blogspot.com/>
Esdras Beleza <linux@esdrasbeleza.com>
Chris Bennett <chrisrbennett@yahoo.com>
@@ -268,6 +269,7 @@ answer newbie questions, and generally made Django that much better:
Daniel Lindsley <polarcowz@gmail.com>
Trey Long <trey@ktrl.com>
msaelices <msaelices@gmail.com>
+ Martin Mahner <http://www.mahner.org/>
Matt McClanahan <http://mmcc.cx/>
Frantisek Malina <vizualbod@vizualbod.com>
Martin Maney <http://www.chipy.org/Martin_Maney>
@@ -1,3 +1,4 @@
+from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL
from django.contrib.admin.options import StackedInline, TabularInline
from django.contrib.admin.sites import AdminSite, site
@@ -6,6 +6,14 @@
from django.utils.encoding import force_unicode
from django.contrib.admin.util import flatten_fieldsets
from django.contrib.contenttypes.models import ContentType
+from django.utils.translation import ugettext_lazy as _
+
+ACTION_CHECKBOX_NAME = '_selected_action'
+
+class ActionForm(forms.Form):
+ action = forms.ChoiceField(label=_('Action:'))
+
+checkbox = forms.CheckboxInput({'class': 'action-select'}, lambda value: False)
class AdminForm(object):
def __init__(self, form, fieldsets, prepopulated_fields):
@@ -132,11 +140,11 @@ def __init__(self, formset, form, fieldsets, prepopulated_fields, original):
self.original.content_type_id = ContentType.objects.get_for_model(original).pk
self.show_url = original and hasattr(original, 'get_absolute_url')
super(InlineAdminForm, self).__init__(form, fieldsets, prepopulated_fields)
-
+
def __iter__(self):
for name, options in self.fieldsets:
yield InlineFieldset(self.formset, self.form, name, **options)
-
+
def field_count(self):
# tabular.html uses this function for colspan value.
num_of_fields = 1 # always has at least one field
@@ -149,7 +157,7 @@ def field_count(self):
def pk_field(self):
return AdminField(self.form, self.formset._pk_field.name, False)
-
+
def fk_field(self):
fk = getattr(self.formset, "fk", None)
if fk:
@@ -169,14 +177,14 @@ class InlineFieldset(Fieldset):
def __init__(self, formset, *args, **kwargs):
self.formset = formset
super(InlineFieldset, self).__init__(*args, **kwargs)
-
+
def __iter__(self):
fk = getattr(self.formset, "fk", None)
for field in self.fields:
if fk and fk.name == field:
continue
yield Fieldline(self.form, field)
-
+
class AdminErrorList(forms.util.ErrorList):
"""
Stores all errors for the form/formsets in an add/change stage view.
@@ -50,12 +50,24 @@
#changelist table thead th {
white-space: nowrap;
+ vertical-align: middle;
+}
+
+#changelist table thead th:first-child {
+ width: 1.5em;
+ text-align: center;
}
#changelist table tbody td {
border-left: 1px solid #ddd;
}
+#changelist table tbody td:first-child {
+ border-left: 0;
+ border-right: 1px solid #ddd;
+ text-align: center;
+}
+
#changelist table tfoot {
color: #666;
}
@@ -209,3 +221,35 @@
border-color: #036;
}
+/* ACTIONS */
+
+.filtered .actions {
+ margin-right: 160px !important;
+ border-right: 1px solid #ddd;
+}
+
+#changelist .actions {
+ color: #666;
+ padding: 3px;
+ border-bottom: 1px solid #ddd;
+ background: #e1e1e1 url(../img/admin/nav-bg.gif) top left repeat-x;
+}
+
+#changelist .actions:last-child {
+ border-bottom: none;
+}
+
+#changelist .actions select {
+ border: 1px solid #aaa;
+ margin: 0 0.5em;
+ padding: 1px 2px;
+}
+
+#changelist .actions label {
+ font-size: 11px;
+ margin: 0 0.5em;
+}
+
+#changelist #action-toggle {
+ display: none;
+}
@@ -0,0 +1,19 @@
+var Actions = {
+ init: function() {
+ selectAll = document.getElementById('action-toggle');
+ if (selectAll) {
+ selectAll.style.display = 'inline';
+ addEvent(selectAll, 'change', function() {
+ Actions.checker(this.checked);
+ });
+ }
+ },
+ checker: function(checked) {
+ actionCheckboxes = document.getElementsBySelector('tr input.action-select');
+ for(var i = 0; i < actionCheckboxes.length; i++) {
+ actionCheckboxes[i].checked = checked;
+ }
+ }
+}
+
+addEvent(window, 'load', Actions.init);
Oops, something went wrong.

0 comments on commit 44f3080

Please sign in to comment.