mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Adds SiteGroup.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] dcim.forms.model_forms.LocationForm, create/edit (e.g. model_forms.py) - [x] dcim.forms.buld_edit.LocationBulkEditForm, bulk edit - [x] dcim.dorms.bulk_import.LocationImportForm, CSV import - [x] 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 - [x] 12. Update the model's documentation
This commit is contained in:
parent
9a9d6cdedb
commit
ed98756f3e
@ -41,7 +41,7 @@ class SiteGroupSerializer(NestedGroupModelSerializer):
|
|||||||
model = SiteGroup
|
model = SiteGroup
|
||||||
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', 'site_count', 'prefix_count', '_depth',
|
'created', 'last_updated', 'site_count', 'prefix_count', 'comments', '_depth',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'site_count', '_depth')
|
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'site_count', '_depth')
|
||||||
|
|
||||||
|
@ -149,6 +149,15 @@ class SiteGroupFilterSet(OrganizationalModelFilterSet, ContactModelFilterSet):
|
|||||||
model = SiteGroup
|
model = SiteGroup
|
||||||
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(description__icontains=value) |
|
||||||
|
Q(comments__icontains=value)
|
||||||
|
).distinct()
|
||||||
|
|
||||||
|
|
||||||
class SiteFilterSet(NetBoxModelFilterSet, TenancyFilterSet, ContactModelFilterSet):
|
class SiteFilterSet(NetBoxModelFilterSet, TenancyFilterSet, ContactModelFilterSet):
|
||||||
status = django_filters.MultipleChoiceFilter(
|
status = django_filters.MultipleChoiceFilter(
|
||||||
|
@ -98,12 +98,13 @@ class SiteGroupBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
max_length=200,
|
max_length=200,
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
comments = CommentField()
|
||||||
|
|
||||||
model = SiteGroup
|
model = SiteGroup
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('parent', 'description'),
|
FieldSet('parent', 'description'),
|
||||||
)
|
)
|
||||||
nullable_fields = ('parent', 'description')
|
nullable_fields = ('parent', 'description', 'comments')
|
||||||
|
|
||||||
|
|
||||||
class SiteBulkEditForm(NetBoxModelBulkEditForm):
|
class SiteBulkEditForm(NetBoxModelBulkEditForm):
|
||||||
|
@ -82,7 +82,7 @@ class SiteGroupImportForm(NetBoxModelImportForm):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = SiteGroup
|
model = SiteGroup
|
||||||
fields = ('name', 'slug', 'parent', 'description')
|
fields = ('name', 'slug', 'parent', 'description', 'comments', 'tags')
|
||||||
|
|
||||||
|
|
||||||
class SiteImportForm(NetBoxModelImportForm):
|
class SiteImportForm(NetBoxModelImportForm):
|
||||||
|
@ -98,6 +98,7 @@ class SiteGroupForm(NetBoxModelForm):
|
|||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
slug = SlugField()
|
slug = SlugField()
|
||||||
|
comments = CommentField()
|
||||||
|
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('parent', 'name', 'slug', 'description', 'tags'),
|
FieldSet('parent', 'name', 'slug', 'description', 'tags'),
|
||||||
@ -106,7 +107,7 @@ class SiteGroupForm(NetBoxModelForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = SiteGroup
|
model = SiteGroup
|
||||||
fields = (
|
fields = (
|
||||||
'parent', 'name', 'slug', 'description', 'tags',
|
'parent', 'name', 'slug', 'description', 'comments', 'tags',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -345,6 +345,7 @@ class SiteGroupIndex(SearchIndex):
|
|||||||
('name', 100),
|
('name', 100),
|
||||||
('slug', 110),
|
('slug', 110),
|
||||||
('description', 500),
|
('description', 500),
|
||||||
|
('comments', 5000),
|
||||||
)
|
)
|
||||||
display_attrs = ('parent', 'description')
|
display_attrs = ('parent', 'description')
|
||||||
|
|
||||||
|
@ -63,8 +63,8 @@ class SiteGroupTable(ContactsColumnMixin, NetBoxTable):
|
|||||||
class Meta(NetBoxTable.Meta):
|
class Meta(NetBoxTable.Meta):
|
||||||
model = SiteGroup
|
model = SiteGroup
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'id', 'name', 'slug', 'site_count', 'description', 'contacts', 'tags', 'created', 'last_updated',
|
'pk', 'id', 'name', 'slug', 'site_count', 'description', 'comments', 'contacts', 'tags',
|
||||||
'actions',
|
'created', 'last_updated', 'actions',
|
||||||
)
|
)
|
||||||
default_columns = ('pk', 'name', 'site_count', 'description')
|
default_columns = ('pk', 'name', 'site_count', 'description')
|
||||||
|
|
||||||
|
@ -105,26 +105,30 @@ class SiteGroupTest(APIViewTestCases.APIViewTestCase):
|
|||||||
{
|
{
|
||||||
'name': 'Site Group 4',
|
'name': 'Site Group 4',
|
||||||
'slug': 'site-group-4',
|
'slug': 'site-group-4',
|
||||||
|
'comments': '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'Site Group 5',
|
'name': 'Site Group 5',
|
||||||
'slug': 'site-group-5',
|
'slug': 'site-group-5',
|
||||||
|
'comments': 'not actually empty',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'Site Group 6',
|
'name': 'Site Group 6',
|
||||||
'slug': 'site-group-6',
|
'slug': 'site-group-6',
|
||||||
|
'comments': 'Do I really exist?',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
bulk_update_data = {
|
bulk_update_data = {
|
||||||
'description': 'New description',
|
'description': 'New description',
|
||||||
|
'comments': 'I do exist!',
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
|
|
||||||
SiteGroup.objects.create(name='Site Group 1', slug='site-group-1')
|
SiteGroup.objects.create(name='Site Group 1', slug='site-group-1')
|
||||||
SiteGroup.objects.create(name='Site Group 2', slug='site-group-2')
|
SiteGroup.objects.create(name='Site Group 2', slug='site-group-2', comments='')
|
||||||
SiteGroup.objects.create(name='Site Group 3', slug='site-group-3')
|
SiteGroup.objects.create(name='Site Group 3', slug='site-group-3', comments='Hi!')
|
||||||
|
|
||||||
|
|
||||||
class SiteTest(APIViewTestCases.APIViewTestCase):
|
class SiteTest(APIViewTestCases.APIViewTestCase):
|
||||||
|
@ -161,13 +161,17 @@ class SiteGroupTestCase(TestCase, ChangeLoggedFilterSetTests):
|
|||||||
SiteGroup(name='Site Group 2A', slug='site-group-2a', parent=parent_groups[1]),
|
SiteGroup(name='Site Group 2A', slug='site-group-2a', parent=parent_groups[1]),
|
||||||
SiteGroup(name='Site Group 2B', slug='site-group-2b', parent=parent_groups[1]),
|
SiteGroup(name='Site Group 2B', slug='site-group-2b', parent=parent_groups[1]),
|
||||||
SiteGroup(name='Site Group 3A', slug='site-group-3a', parent=parent_groups[2]),
|
SiteGroup(name='Site Group 3A', slug='site-group-3a', parent=parent_groups[2]),
|
||||||
SiteGroup(name='Site Group 3B', slug='site-group-3b', parent=parent_groups[2]),
|
SiteGroup(
|
||||||
|
name='Site Group 3B', slug='site-group-3b', parent=parent_groups[2], comments='this is a parent group',
|
||||||
|
),
|
||||||
)
|
)
|
||||||
for site_group in groups:
|
for site_group in groups:
|
||||||
site_group.save()
|
site_group.save()
|
||||||
|
|
||||||
child_groups = (
|
child_groups = (
|
||||||
SiteGroup(name='Site Group 1A1', slug='site-group-1a1', parent=groups[0]),
|
SiteGroup(
|
||||||
|
name='Site Group 1A1', slug='site-group-1a1', parent=groups[0], comments='this is a child group',
|
||||||
|
),
|
||||||
SiteGroup(name='Site Group 1B1', slug='site-group-1b1', parent=groups[1]),
|
SiteGroup(name='Site Group 1B1', slug='site-group-1b1', parent=groups[1]),
|
||||||
SiteGroup(name='Site Group 2A1', slug='site-group-2a1', parent=groups[2]),
|
SiteGroup(name='Site Group 2A1', slug='site-group-2a1', parent=groups[2]),
|
||||||
SiteGroup(name='Site Group 2B1', slug='site-group-2b1', parent=groups[3]),
|
SiteGroup(name='Site Group 2B1', slug='site-group-2b1', parent=groups[3]),
|
||||||
@ -181,6 +185,13 @@ class SiteGroupTestCase(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': 'this'}
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||||
|
|
||||||
|
params = {'q': 'child'}
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||||
|
|
||||||
def test_name(self):
|
def test_name(self):
|
||||||
params = {'name': ['Site Group 1', 'Site Group 2']}
|
params = {'name': ['Site Group 1', 'Site Group 2']}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||||
|
@ -73,7 +73,7 @@ class SiteGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
|
|||||||
|
|
||||||
# Create three SiteGroups
|
# Create three SiteGroups
|
||||||
sitegroups = (
|
sitegroups = (
|
||||||
SiteGroup(name='Site Group 1', slug='site-group-1'),
|
SiteGroup(name='Site Group 1', slug='site-group-1', comments='Still here'),
|
||||||
SiteGroup(name='Site Group 2', slug='site-group-2'),
|
SiteGroup(name='Site Group 2', slug='site-group-2'),
|
||||||
SiteGroup(name='Site Group 3', slug='site-group-3'),
|
SiteGroup(name='Site Group 3', slug='site-group-3'),
|
||||||
)
|
)
|
||||||
@ -88,24 +88,26 @@ class SiteGroupTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
|
|||||||
'parent': sitegroups[2].pk,
|
'parent': sitegroups[2].pk,
|
||||||
'description': 'A new site group',
|
'description': 'A new site group',
|
||||||
'tags': [t.pk for t in tags],
|
'tags': [t.pk for t in tags],
|
||||||
|
'comments': 'still here',
|
||||||
}
|
}
|
||||||
|
|
||||||
cls.csv_data = (
|
cls.csv_data = (
|
||||||
"name,slug,description",
|
"name,slug,description,comments",
|
||||||
"Site Group 4,site-group-4,Fourth site group",
|
"Site Group 4,site-group-4,Fourth site group,",
|
||||||
"Site Group 5,site-group-5,Fifth site group",
|
"Site Group 5,site-group-5,Fifth site group,still hear",
|
||||||
"Site Group 6,site-group-6,Sixth site group",
|
"Site Group 6,site-group-6,Sixth site group,"
|
||||||
)
|
)
|
||||||
|
|
||||||
cls.csv_update_data = (
|
cls.csv_update_data = (
|
||||||
"id,name,description",
|
"id,name,description,comments",
|
||||||
f"{sitegroups[0].pk},Site Group 7,Fourth site group7",
|
f"{sitegroups[0].pk},Site Group 7,Fourth site group7,",
|
||||||
f"{sitegroups[1].pk},Site Group 8,Fifth site group8",
|
f"{sitegroups[1].pk},Site Group 8,Fifth site group8,when will it end",
|
||||||
f"{sitegroups[2].pk},Site Group 0,Sixth site group9",
|
f"{sitegroups[2].pk},Site Group 0,Sixth site group9,",
|
||||||
)
|
)
|
||||||
|
|
||||||
cls.bulk_edit_data = {
|
cls.bulk_edit_data = {
|
||||||
'description': 'New description',
|
'description': 'New description',
|
||||||
|
'comments': 'the end',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% include 'inc/panels/tags.html' %}
|
{% include 'inc/panels/tags.html' %}
|
||||||
{% include 'inc/panels/custom_fields.html' %}
|
{% include 'inc/panels/custom_fields.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">
|
||||||
|
Loading…
Reference in New Issue
Block a user