mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 02:48:38 -06:00
17178 review changes
This commit is contained in:
parent
a4eb86f8b6
commit
83793de408
@ -65,13 +65,13 @@ class ContactRoleFilterSet(OrganizationalModelFilterSet):
|
||||
|
||||
|
||||
class ContactFilterSet(NetBoxModelFilterSet):
|
||||
contact_group_id = TreeNodeMultipleChoiceFilter(
|
||||
group_id = TreeNodeMultipleChoiceFilter(
|
||||
queryset=ContactGroup.objects.all(),
|
||||
field_name='groups',
|
||||
lookup_expr='in',
|
||||
label=_('Contact group (ID)'),
|
||||
)
|
||||
contact_group = TreeNodeMultipleChoiceFilter(
|
||||
group = TreeNodeMultipleChoiceFilter(
|
||||
queryset=ContactGroup.objects.all(),
|
||||
field_name='groups',
|
||||
to_field_name='slug',
|
||||
|
@ -90,8 +90,13 @@ class ContactRoleBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
|
||||
class ContactBulkEditForm(NetBoxModelBulkEditForm):
|
||||
groups = DynamicModelMultipleChoiceField(
|
||||
label=_('Groups'),
|
||||
add_groups = DynamicModelMultipleChoiceField(
|
||||
label=_('Add groups'),
|
||||
queryset=ContactGroup.objects.all(),
|
||||
required=False
|
||||
)
|
||||
remove_groups = DynamicModelMultipleChoiceField(
|
||||
label=_('Remove groups'),
|
||||
queryset=ContactGroup.objects.all(),
|
||||
required=False
|
||||
)
|
||||
@ -127,9 +132,11 @@ class ContactBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
model = Contact
|
||||
fieldsets = (
|
||||
FieldSet('groups', 'title', 'phone', 'email', 'address', 'link', 'description'),
|
||||
FieldSet('add_groups', 'remove_groups', 'title', 'phone', 'email', 'address', 'link', 'description'),
|
||||
)
|
||||
nullable_fields = (
|
||||
'add_groups', 'remove_groups', 'title', 'phone', 'email', 'address', 'link', 'description', 'comments'
|
||||
)
|
||||
nullable_fields = ('groups', 'title', 'phone', 'email', 'address', 'link', 'description', 'comments')
|
||||
|
||||
|
||||
class ContactAssignmentBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
@ -71,11 +71,11 @@ class ContactRoleFilterForm(NetBoxModelFilterSetForm):
|
||||
|
||||
class ContactFilterForm(NetBoxModelFilterSetForm):
|
||||
model = Contact
|
||||
contact_group_id = DynamicModelMultipleChoiceField(
|
||||
group_id = DynamicModelMultipleChoiceField(
|
||||
queryset=ContactGroup.objects.all(),
|
||||
required=False,
|
||||
null_option='None',
|
||||
label=_('Group')
|
||||
label=_('Groups')
|
||||
)
|
||||
tag = TagFilterField(model)
|
||||
|
||||
|
@ -241,6 +241,7 @@ class ContactRoleTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
class ContactTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
queryset = Contact.objects.all()
|
||||
filterset = ContactFilterSet
|
||||
ignore_fields = ('groups',)
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
@ -277,9 +278,9 @@ class ContactTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
|
||||
def test_group(self):
|
||||
group = ContactGroup.objects.all()[:2]
|
||||
params = {'contact_group_id': [group[0].pk, group[1].pk]}
|
||||
params = {'group_id': [group[0].pk, group[1].pk]}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
params = {'contact_group': [group[0].slug, group[1].slug]}
|
||||
params = {'group': [group[0].slug, group[1].slug]}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
|
||||
|
@ -400,6 +400,15 @@ class ContactAssignmentBulkEditView(generic.BulkEditView):
|
||||
table = tables.ContactAssignmentTable
|
||||
form = forms.ContactAssignmentBulkEditForm
|
||||
|
||||
def post_save_operations(self, form, obj):
|
||||
super().post_save_operations(form, obj)
|
||||
|
||||
# Add/remove groups
|
||||
if form.cleaned_data.get('add_groups', None):
|
||||
obj.groups.add(*form.cleaned_data['add_groups'])
|
||||
if form.cleaned_data.get('remove_groups', None):
|
||||
obj.groups.remove(*form.cleaned_data['remove_groups'])
|
||||
|
||||
|
||||
@register_model_view(ContactAssignment, 'bulk_delete', path='delete', detail=False)
|
||||
class ContactAssignmentBulkDeleteView(generic.BulkDeleteView):
|
||||
|
Loading…
Reference in New Issue
Block a user