mirror of
https://github.com/django/django.git
synced 2025-11-19 03:08:59 +00:00
Fixed #10505: added support for bulk admin actions, including a globally-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
This commit is contained in:
parent
4e2533436e
commit
44f3080226
26 changed files with 881 additions and 108 deletions
|
|
@ -6,6 +6,14 @@ from django.utils.safestring import mark_safe
|
|||
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 @@ class InlineAdminForm(AdminForm):
|
|||
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 @@ class InlineAdminForm(AdminForm):
|
|||
|
||||
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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue