Closes #5972: Bulk edit support for organizational models (#5974)

* Enable bulk editing of organizational models

* Enable bulk editing of nested group models

* Changelog for #5972
This commit is contained in:
Jeremy Stretch
2021-03-12 16:14:42 -05:00
committed by GitHub
parent fca5accba8
commit 61d23df83a
26 changed files with 526 additions and 1 deletions

View File

@@ -44,6 +44,24 @@ class TenantGroupCSVForm(CustomFieldModelCSVForm):
fields = TenantGroup.csv_headers
class TenantGroupBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
pk = forms.ModelMultipleChoiceField(
queryset=TenantGroup.objects.all(),
widget=forms.MultipleHiddenInput
)
parent = DynamicModelChoiceField(
queryset=TenantGroup.objects.all(),
required=False
)
description = forms.CharField(
max_length=200,
required=False
)
class Meta:
nullable_fields = ['parent', 'description']
#
# Tenants
#

View File

@@ -29,6 +29,10 @@ class TenantGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
"Tenant Group 6,tenant-group-6,Sixth tenant group",
)
cls.bulk_edit_data = {
'description': 'New description',
}
class TenantTestCase(ViewTestCases.PrimaryObjectViewTestCase):
model = Tenant

View File

@@ -11,6 +11,7 @@ urlpatterns = [
path('tenant-groups/', views.TenantGroupListView.as_view(), name='tenantgroup_list'),
path('tenant-groups/add/', views.TenantGroupEditView.as_view(), name='tenantgroup_add'),
path('tenant-groups/import/', views.TenantGroupBulkImportView.as_view(), name='tenantgroup_import'),
path('tenant-groups/edit/', views.TenantGroupBulkEditView.as_view(), name='tenantgroup_bulk_edit'),
path('tenant-groups/delete/', views.TenantGroupBulkDeleteView.as_view(), name='tenantgroup_bulk_delete'),
path('tenant-groups/<int:pk>/edit/', views.TenantGroupEditView.as_view(), name='tenantgroup_edit'),
path('tenant-groups/<int:pk>/delete/', views.TenantGroupDeleteView.as_view(), name='tenantgroup_delete'),

View File

@@ -39,6 +39,19 @@ class TenantGroupBulkImportView(generic.BulkImportView):
table = tables.TenantGroupTable
class TenantGroupBulkEditView(generic.BulkEditView):
queryset = TenantGroup.objects.add_related_count(
TenantGroup.objects.all(),
Tenant,
'group',
'tenant_count',
cumulative=True
)
filterset = filters.TenantGroupFilterSet
table = tables.TenantGroupTable
form = forms.TenantGroupBulkEditForm
class TenantGroupBulkDeleteView(generic.BulkDeleteView):
queryset = TenantGroup.objects.add_related_count(
TenantGroup.objects.all(),