mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Adds ContactGroup.comments in the required locations
- [x] 1. Add the field to the model class - [x] 2. Generate and run database migrations - [NA] 3. Add validation logic to clean() - [NA] 4. Update relevant querysets - [x] 5. Update API serializer - [x] 6. Add fields to forms - [x] tenancy.forms.model_forms, create/edit (e.g. model_forms.py) - [x] tenancy.forms.buld_edit, bulk edit - [x] tenancy.dorms.bulk_import, CSV import - [NA] filter (UI and API) - [x] 7. Extend object filter set - [x] 8. Add column to object table - [x] 9. Update the SearchIndex - [x] 10. Update the UI templates - [x] 11. Create/extend test cases - [NA] models - [x] views - [NA] forms - [x] filtersets - [x] api - [NA] 12. Update the model's documentation
This commit is contained in:
parent
ed98756f3e
commit
b8352260ee
@ -32,6 +32,7 @@
|
||||
</table>
|
||||
</div>
|
||||
{% include 'inc/panels/tags.html' %}
|
||||
{% include 'inc/panels/comments.html' %}
|
||||
{% plugin_left_page object %}
|
||||
</div>
|
||||
<div class="col col-md-6">
|
||||
|
@ -26,7 +26,7 @@ class ContactGroupSerializer(NestedGroupModelSerializer):
|
||||
model = ContactGroup
|
||||
fields = [
|
||||
'id', 'url', 'display_url', 'display', 'name', 'slug', 'parent', 'description', 'tags', 'custom_fields',
|
||||
'created', 'last_updated', 'contact_count', '_depth',
|
||||
'created', 'last_updated', 'contact_count', 'comments', '_depth',
|
||||
]
|
||||
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'contact_count', '_depth')
|
||||
|
||||
|
@ -51,6 +51,16 @@ class ContactGroupFilterSet(OrganizationalModelFilterSet):
|
||||
model = ContactGroup
|
||||
fields = ('id', 'name', 'slug', 'description')
|
||||
|
||||
def search(self, queryset, name, value):
|
||||
if not value.strip():
|
||||
return queryset
|
||||
return queryset.filter(
|
||||
Q(name__icontains=value) |
|
||||
Q(slug__icontains=value) |
|
||||
Q(description__icontains=value) |
|
||||
Q(comments__icontains=value)
|
||||
)
|
||||
|
||||
|
||||
class ContactRoleFilterSet(OrganizationalModelFilterSet):
|
||||
|
||||
|
@ -67,12 +67,13 @@ class ContactGroupBulkEditForm(NetBoxModelBulkEditForm):
|
||||
max_length=200,
|
||||
required=False
|
||||
)
|
||||
comments = CommentField()
|
||||
|
||||
model = ContactGroup
|
||||
fieldsets = (
|
||||
FieldSet('parent', 'description'),
|
||||
)
|
||||
nullable_fields = ('parent', 'description')
|
||||
nullable_fields = ('parent', 'description', 'comments')
|
||||
|
||||
|
||||
class ContactRoleBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
@ -65,7 +65,7 @@ class ContactGroupImportForm(NetBoxModelImportForm):
|
||||
|
||||
class Meta:
|
||||
model = ContactGroup
|
||||
fields = ('name', 'slug', 'parent', 'description', 'tags')
|
||||
fields = ('name', 'slug', 'parent', 'description', 'tags', 'comments')
|
||||
|
||||
|
||||
class ContactRoleImportForm(NetBoxModelImportForm):
|
||||
|
@ -70,6 +70,7 @@ class ContactGroupForm(NetBoxModelForm):
|
||||
required=False
|
||||
)
|
||||
slug = SlugField()
|
||||
comments = CommentField()
|
||||
|
||||
fieldsets = (
|
||||
FieldSet('parent', 'name', 'slug', 'description', 'tags', name=_('Contact Group')),
|
||||
@ -77,7 +78,7 @@ class ContactGroupForm(NetBoxModelForm):
|
||||
|
||||
class Meta:
|
||||
model = ContactGroup
|
||||
fields = ('parent', 'name', 'slug', 'description', 'tags')
|
||||
fields = ('parent', 'name', 'slug', 'description', 'tags', 'comments')
|
||||
|
||||
|
||||
class ContactRoleForm(NetBoxModelForm):
|
||||
|
@ -25,6 +25,7 @@ class ContactGroupIndex(SearchIndex):
|
||||
('name', 100),
|
||||
('slug', 110),
|
||||
('description', 500),
|
||||
('comments', 5000),
|
||||
)
|
||||
display_attrs = ('description',)
|
||||
|
||||
|
@ -31,7 +31,8 @@ class ContactGroupTable(NetBoxTable):
|
||||
class Meta(NetBoxTable.Meta):
|
||||
model = ContactGroup
|
||||
fields = (
|
||||
'pk', 'name', 'contact_count', 'description', 'slug', 'tags', 'created', 'last_updated', 'actions',
|
||||
'pk', 'name', 'contact_count', 'description', 'comments', 'slug', 'tags', 'created',
|
||||
'last_updated', 'actions',
|
||||
)
|
||||
default_columns = ('pk', 'name', 'contact_count', 'description')
|
||||
|
||||
|
@ -107,13 +107,18 @@ class ContactGroupTest(APIViewTestCases.APIViewTestCase):
|
||||
def setUpTestData(cls):
|
||||
|
||||
parent_contact_groups = (
|
||||
ContactGroup.objects.create(name='Parent Contact Group 1', slug='parent-contact-group-1'),
|
||||
ContactGroup.objects.create(
|
||||
name='Parent Contact Group 1', slug='parent-contact-group-1', comments='Parent 1 comment'
|
||||
),
|
||||
ContactGroup.objects.create(name='Parent Contact Group 2', slug='parent-contact-group-2'),
|
||||
)
|
||||
|
||||
ContactGroup.objects.create(name='Contact Group 1', slug='contact-group-1', parent=parent_contact_groups[0])
|
||||
ContactGroup.objects.create(name='Contact Group 2', slug='contact-group-2', parent=parent_contact_groups[0])
|
||||
ContactGroup.objects.create(name='Contact Group 3', slug='contact-group-3', parent=parent_contact_groups[0])
|
||||
ContactGroup.objects.create(
|
||||
name='Contact Group 3', slug='contact-group-3', parent=parent_contact_groups[0],
|
||||
comments='Child Group 3 comment',
|
||||
)
|
||||
|
||||
cls.create_data = [
|
||||
{
|
||||
@ -125,11 +130,13 @@ class ContactGroupTest(APIViewTestCases.APIViewTestCase):
|
||||
'name': 'Contact Group 5',
|
||||
'slug': 'contact-group-5',
|
||||
'parent': parent_contact_groups[1].pk,
|
||||
'comments': '',
|
||||
},
|
||||
{
|
||||
'name': 'Contact Group 6',
|
||||
'slug': 'contact-group-6',
|
||||
'parent': parent_contact_groups[1].pk,
|
||||
'comments': 'Child Group 6 comment',
|
||||
},
|
||||
]
|
||||
|
||||
|
@ -139,7 +139,7 @@ class ContactGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
|
||||
parent_contact_groups = (
|
||||
ContactGroup(name='Contact Group 1', slug='contact-group-1'),
|
||||
ContactGroup(name='Contact Group 2', slug='contact-group-2'),
|
||||
ContactGroup(name='Contact Group 2', slug='contact-group-2', comments='Parent group 2'),
|
||||
ContactGroup(name='Contact Group 3', slug='contact-group-3'),
|
||||
)
|
||||
for contact_group in parent_contact_groups:
|
||||
@ -162,14 +162,18 @@ class ContactGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
name='Contact Group 3A',
|
||||
slug='contact-group-3a',
|
||||
parent=parent_contact_groups[2],
|
||||
description='foobar3'
|
||||
description='foobar3',
|
||||
comments='Contact Group 3A comment, not a parent',
|
||||
),
|
||||
)
|
||||
for contact_group in contact_groups:
|
||||
contact_group.save()
|
||||
|
||||
child_contact_groups = (
|
||||
ContactGroup(name='Contact Group 1A1', slug='contact-group-1a1', parent=contact_groups[0]),
|
||||
ContactGroup(
|
||||
name='Contact Group 1A1', slug='contact-group-1a1', parent=contact_groups[0],
|
||||
comments='Contact Group 1A1 comment',
|
||||
),
|
||||
ContactGroup(name='Contact Group 2A1', slug='contact-group-2a1', parent=contact_groups[1]),
|
||||
ContactGroup(name='Contact Group 3A1', slug='contact-group-3a1', parent=contact_groups[2]),
|
||||
)
|
||||
@ -180,6 +184,13 @@ class ContactGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
params = {'q': 'foobar1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_q_comments(self):
|
||||
params = {'q': 'parent'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
params = {'q': '1A1'}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||
|
||||
def test_name(self):
|
||||
params = {'name': ['Contact Group 1', 'Contact Group 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
@ -106,7 +106,7 @@ class ContactGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
|
||||
def setUpTestData(cls):
|
||||
|
||||
contact_groups = (
|
||||
ContactGroup(name='Contact Group 1', slug='contact-group-1'),
|
||||
ContactGroup(name='Contact Group 1', slug='contact-group-1', comments='Comment 1'),
|
||||
ContactGroup(name='Contact Group 2', slug='contact-group-2'),
|
||||
ContactGroup(name='Contact Group 3', slug='contact-group-3'),
|
||||
)
|
||||
@ -120,24 +120,26 @@ class ContactGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
|
||||
'slug': 'contact-group-x',
|
||||
'description': 'A new contact group',
|
||||
'tags': [t.pk for t in tags],
|
||||
'comments': 'Form data comment',
|
||||
}
|
||||
|
||||
cls.csv_data = (
|
||||
"name,slug,description",
|
||||
"Contact Group 4,contact-group-4,Fourth contact group",
|
||||
"Contact Group 5,contact-group-5,Fifth contact group",
|
||||
"Contact Group 6,contact-group-6,Sixth contact group",
|
||||
"name,slug,description,comments",
|
||||
"Contact Group 4,contact-group-4,Fourth contact group,",
|
||||
"Contact Group 5,contact-group-5,Fifth contact group,Fifth comment",
|
||||
"Contact Group 6,contact-group-6,Sixth contact group,",
|
||||
)
|
||||
|
||||
cls.csv_update_data = (
|
||||
"id,name,description",
|
||||
f"{contact_groups[0].pk},Contact Group 7,Fourth contact group7",
|
||||
f"{contact_groups[1].pk},Contact Group 8,Fifth contact group8",
|
||||
f"{contact_groups[2].pk},Contact Group 0,Sixth contact group9",
|
||||
"id,name,description,comments",
|
||||
f"{contact_groups[0].pk},Contact Group 7,Fourth contact group7,",
|
||||
f"{contact_groups[1].pk},Contact Group 8,Fifth contact group8,Group 8 comment",
|
||||
f"{contact_groups[2].pk},Contact Group 0,Sixth contact group9,",
|
||||
)
|
||||
|
||||
cls.bulk_edit_data = {
|
||||
'description': 'New description',
|
||||
'comments': 'Bulk update comment',
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user