mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 17:08:41 -06:00
Adds TenantGroup.comments to 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.bulk_edit, bulk edit - [x] tenancy.forms.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
b8352260ee
commit
157df20ad4
@ -40,6 +40,7 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
{% include 'inc/panels/tags.html' %}
|
{% include 'inc/panels/tags.html' %}
|
||||||
|
{% include 'inc/panels/comments.html' %}
|
||||||
{% plugin_left_page object %}
|
{% plugin_left_page object %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col col-md-6">
|
<div class="col col-md-6">
|
||||||
|
@ -19,7 +19,7 @@ class TenantGroupSerializer(NestedGroupModelSerializer):
|
|||||||
model = TenantGroup
|
model = TenantGroup
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'name', 'slug', 'parent', 'description', 'tags', 'custom_fields',
|
'id', 'url', 'display_url', 'display', 'name', 'slug', 'parent', 'description', 'tags', 'custom_fields',
|
||||||
'created', 'last_updated', 'tenant_count', '_depth',
|
'created', 'last_updated', 'tenant_count', 'comments', '_depth',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'tenant_count', '_depth')
|
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'tenant_count', '_depth')
|
||||||
|
|
||||||
|
@ -202,6 +202,16 @@ class TenantGroupFilterSet(OrganizationalModelFilterSet):
|
|||||||
model = TenantGroup
|
model = TenantGroup
|
||||||
fields = ('id', 'name', 'slug', 'description')
|
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 TenantFilterSet(NetBoxModelFilterSet, ContactModelFilterSet):
|
class TenantFilterSet(NetBoxModelFilterSet, ContactModelFilterSet):
|
||||||
group_id = TreeNodeMultipleChoiceFilter(
|
group_id = TreeNodeMultipleChoiceFilter(
|
||||||
|
@ -33,9 +33,10 @@ class TenantGroupBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
max_length=200,
|
max_length=200,
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
comments = CommentField()
|
||||||
|
|
||||||
model = TenantGroup
|
model = TenantGroup
|
||||||
nullable_fields = ('parent', 'description')
|
nullable_fields = ('parent', 'description', 'comments')
|
||||||
|
|
||||||
|
|
||||||
class TenantBulkEditForm(NetBoxModelBulkEditForm):
|
class TenantBulkEditForm(NetBoxModelBulkEditForm):
|
||||||
|
@ -31,7 +31,7 @@ class TenantGroupImportForm(NetBoxModelImportForm):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = TenantGroup
|
model = TenantGroup
|
||||||
fields = ('name', 'slug', 'parent', 'description', 'tags')
|
fields = ('name', 'slug', 'parent', 'description', 'tags', 'comments')
|
||||||
|
|
||||||
|
|
||||||
class TenantImportForm(NetBoxModelImportForm):
|
class TenantImportForm(NetBoxModelImportForm):
|
||||||
|
@ -27,6 +27,7 @@ class TenantGroupForm(NetBoxModelForm):
|
|||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
slug = SlugField()
|
slug = SlugField()
|
||||||
|
comments = CommentField()
|
||||||
|
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('parent', 'name', 'slug', 'description', 'tags', name=_('Tenant Group')),
|
FieldSet('parent', 'name', 'slug', 'description', 'tags', name=_('Tenant Group')),
|
||||||
@ -35,7 +36,7 @@ class TenantGroupForm(NetBoxModelForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = TenantGroup
|
model = TenantGroup
|
||||||
fields = [
|
fields = [
|
||||||
'parent', 'name', 'slug', 'description', 'tags',
|
'parent', 'name', 'slug', 'description', 'tags', 'comments'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,5 +60,6 @@ class TenantGroupIndex(SearchIndex):
|
|||||||
('name', 100),
|
('name', 100),
|
||||||
('slug', 110),
|
('slug', 110),
|
||||||
('description', 500),
|
('description', 500),
|
||||||
|
('comments', 5000),
|
||||||
)
|
)
|
||||||
display_attrs = ('description',)
|
display_attrs = ('description',)
|
||||||
|
@ -28,7 +28,8 @@ class TenantGroupTable(NetBoxTable):
|
|||||||
class Meta(NetBoxTable.Meta):
|
class Meta(NetBoxTable.Meta):
|
||||||
model = TenantGroup
|
model = TenantGroup
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'id', 'name', 'tenant_count', 'description', 'slug', 'tags', 'created', 'last_updated', 'actions',
|
'pk', 'id', 'name', 'tenant_count', 'description', 'comments', 'slug', 'tags', 'created',
|
||||||
|
'last_updated', 'actions',
|
||||||
)
|
)
|
||||||
default_columns = ('pk', 'name', 'tenant_count', 'description')
|
default_columns = ('pk', 'name', 'tenant_count', 'description')
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ class TenantGroupTest(APIViewTestCases.APIViewTestCase):
|
|||||||
brief_fields = ['_depth', 'description', 'display', 'id', 'name', 'slug', 'tenant_count', 'url']
|
brief_fields = ['_depth', 'description', 'display', 'id', 'name', 'slug', 'tenant_count', 'url']
|
||||||
bulk_update_data = {
|
bulk_update_data = {
|
||||||
'description': 'New description',
|
'description': 'New description',
|
||||||
|
'comments': 'New Comment',
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -28,12 +29,17 @@ class TenantGroupTest(APIViewTestCases.APIViewTestCase):
|
|||||||
|
|
||||||
parent_tenant_groups = (
|
parent_tenant_groups = (
|
||||||
TenantGroup.objects.create(name='Parent Tenant Group 1', slug='parent-tenant-group-1'),
|
TenantGroup.objects.create(name='Parent Tenant Group 1', slug='parent-tenant-group-1'),
|
||||||
TenantGroup.objects.create(name='Parent Tenant Group 2', slug='parent-tenant-group-2'),
|
TenantGroup.objects.create(
|
||||||
|
name='Parent Tenant Group 2', slug='parent-tenant-group-2', comments='Parent Group 2 comment',
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
TenantGroup.objects.create(name='Tenant Group 1', slug='tenant-group-1', parent=parent_tenant_groups[0])
|
TenantGroup.objects.create(name='Tenant Group 1', slug='tenant-group-1', parent=parent_tenant_groups[0])
|
||||||
TenantGroup.objects.create(name='Tenant Group 2', slug='tenant-group-2', parent=parent_tenant_groups[0])
|
TenantGroup.objects.create(name='Tenant Group 2', slug='tenant-group-2', parent=parent_tenant_groups[0])
|
||||||
TenantGroup.objects.create(name='Tenant Group 3', slug='tenant-group-3', parent=parent_tenant_groups[0])
|
TenantGroup.objects.create(
|
||||||
|
name='Tenant Group 3', slug='tenant-group-3', parent=parent_tenant_groups[0],
|
||||||
|
comments='Tenant Group 3 comment'
|
||||||
|
)
|
||||||
|
|
||||||
cls.create_data = [
|
cls.create_data = [
|
||||||
{
|
{
|
||||||
@ -50,6 +56,7 @@ class TenantGroupTest(APIViewTestCases.APIViewTestCase):
|
|||||||
'name': 'Tenant Group 6',
|
'name': 'Tenant Group 6',
|
||||||
'slug': 'tenant-group-6',
|
'slug': 'tenant-group-6',
|
||||||
'parent': parent_tenant_groups[1].pk,
|
'parent': parent_tenant_groups[1].pk,
|
||||||
|
'comments': 'Tenant Group 6 comment',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ class TenantGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
|||||||
|
|
||||||
parent_tenant_groups = (
|
parent_tenant_groups = (
|
||||||
TenantGroup(name='Tenant Group 1', slug='tenant-group-1'),
|
TenantGroup(name='Tenant Group 1', slug='tenant-group-1'),
|
||||||
TenantGroup(name='Tenant Group 2', slug='tenant-group-2'),
|
TenantGroup(name='Tenant Group 2', slug='tenant-group-2', comments='Parent group 2 comment'),
|
||||||
TenantGroup(name='Tenant Group 3', slug='tenant-group-3'),
|
TenantGroup(name='Tenant Group 3', slug='tenant-group-3'),
|
||||||
)
|
)
|
||||||
for tenant_group in parent_tenant_groups:
|
for tenant_group in parent_tenant_groups:
|
||||||
@ -27,7 +27,8 @@ class TenantGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
|||||||
name='Tenant Group 1A',
|
name='Tenant Group 1A',
|
||||||
slug='tenant-group-1a',
|
slug='tenant-group-1a',
|
||||||
parent=parent_tenant_groups[0],
|
parent=parent_tenant_groups[0],
|
||||||
description='foobar1'
|
description='foobar1',
|
||||||
|
comments='Tenant Group 1A comment',
|
||||||
),
|
),
|
||||||
TenantGroup(
|
TenantGroup(
|
||||||
name='Tenant Group 2A',
|
name='Tenant Group 2A',
|
||||||
@ -48,7 +49,10 @@ class TenantGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
|||||||
child_tenant_groups = (
|
child_tenant_groups = (
|
||||||
TenantGroup(name='Tenant Group 1A1', slug='tenant-group-1a1', parent=tenant_groups[0]),
|
TenantGroup(name='Tenant Group 1A1', slug='tenant-group-1a1', parent=tenant_groups[0]),
|
||||||
TenantGroup(name='Tenant Group 2A1', slug='tenant-group-2a1', parent=tenant_groups[1]),
|
TenantGroup(name='Tenant Group 2A1', slug='tenant-group-2a1', parent=tenant_groups[1]),
|
||||||
TenantGroup(name='Tenant Group 3A1', slug='tenant-group-3a1', parent=tenant_groups[2]),
|
TenantGroup(
|
||||||
|
name='Tenant Group 3A1', slug='tenant-group-3a1', parent=tenant_groups[2],
|
||||||
|
comments='Tenant Group 3A1 comment',
|
||||||
|
),
|
||||||
)
|
)
|
||||||
for tenant_group in child_tenant_groups:
|
for tenant_group in child_tenant_groups:
|
||||||
tenant_group.save()
|
tenant_group.save()
|
||||||
@ -57,6 +61,13 @@ class TenantGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
|||||||
params = {'q': 'foobar1'}
|
params = {'q': 'foobar1'}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
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(), 1)
|
||||||
|
|
||||||
|
params = {'q': 'comment'}
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
|
||||||
|
|
||||||
def test_name(self):
|
def test_name(self):
|
||||||
params = {'name': ['Tenant Group 1', 'Tenant Group 2']}
|
params = {'name': ['Tenant Group 1', 'Tenant Group 2']}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||||
|
@ -15,7 +15,7 @@ class TenantGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
|
|||||||
|
|
||||||
tenant_groups = (
|
tenant_groups = (
|
||||||
TenantGroup(name='Tenant Group 1', slug='tenant-group-1'),
|
TenantGroup(name='Tenant Group 1', slug='tenant-group-1'),
|
||||||
TenantGroup(name='Tenant Group 2', slug='tenant-group-2'),
|
TenantGroup(name='Tenant Group 2', slug='tenant-group-2', comments='Tenant Group 2 comment'),
|
||||||
TenantGroup(name='Tenant Group 3', slug='tenant-group-3'),
|
TenantGroup(name='Tenant Group 3', slug='tenant-group-3'),
|
||||||
)
|
)
|
||||||
for tenanantgroup in tenant_groups:
|
for tenanantgroup in tenant_groups:
|
||||||
@ -28,24 +28,26 @@ class TenantGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
|
|||||||
'slug': 'tenant-group-x',
|
'slug': 'tenant-group-x',
|
||||||
'description': 'A new tenant group',
|
'description': 'A new tenant group',
|
||||||
'tags': [t.pk for t in tags],
|
'tags': [t.pk for t in tags],
|
||||||
|
'comments': 'Tenant Group X comment',
|
||||||
}
|
}
|
||||||
|
|
||||||
cls.csv_data = (
|
cls.csv_data = (
|
||||||
"name,slug,description",
|
"name,slug,description,comments",
|
||||||
"Tenant Group 4,tenant-group-4,Fourth tenant group",
|
"Tenant Group 4,tenant-group-4,Fourth tenant group,",
|
||||||
"Tenant Group 5,tenant-group-5,Fifth tenant group",
|
"Tenant Group 5,tenant-group-5,Fifth tenant group,",
|
||||||
"Tenant Group 6,tenant-group-6,Sixth tenant group",
|
"Tenant Group 6,tenant-group-6,Sixth tenant group,Sixth tenant group comment",
|
||||||
)
|
)
|
||||||
|
|
||||||
cls.csv_update_data = (
|
cls.csv_update_data = (
|
||||||
"id,name,description",
|
"id,name,description,comments",
|
||||||
f"{tenant_groups[0].pk},Tenant Group 7,Fourth tenant group7",
|
f"{tenant_groups[0].pk},Tenant Group 7,Fourth tenant group7,Group 7 comment",
|
||||||
f"{tenant_groups[1].pk},Tenant Group 8,Fifth tenant group8",
|
f"{tenant_groups[1].pk},Tenant Group 8,Fifth tenant group8,",
|
||||||
f"{tenant_groups[2].pk},Tenant Group 0,Sixth tenant group9",
|
f"{tenant_groups[2].pk},Tenant Group 0,Sixth tenant group9,",
|
||||||
)
|
)
|
||||||
|
|
||||||
cls.bulk_edit_data = {
|
cls.bulk_edit_data = {
|
||||||
'description': 'New description',
|
'description': 'New description',
|
||||||
|
'comments': 'New comment',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user