mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-17 04:32:51 -06:00
Add JournalEntry filter for kind
This commit is contained in:
parent
82fbd975f1
commit
7e65a3d3b4
@ -135,10 +135,13 @@ class JournalEntryFilterSet(BaseFilterSet):
|
|||||||
to_field_name='username',
|
to_field_name='username',
|
||||||
label='User (name)',
|
label='User (name)',
|
||||||
)
|
)
|
||||||
|
kind = django_filters.MultipleChoiceFilter(
|
||||||
|
choices=JournalEntryKindChoices
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = JournalEntry
|
model = JournalEntry
|
||||||
fields = ['id', 'assigned_object_type_id', 'assigned_object_id', 'created']
|
fields = ['id', 'assigned_object_type_id', 'assigned_object_id', 'created', 'kind']
|
||||||
|
|
||||||
def search(self, queryset, name, value):
|
def search(self, queryset, name, value):
|
||||||
if not value.strip():
|
if not value.strip():
|
||||||
|
@ -5,7 +5,7 @@ from django.contrib.contenttypes.models import ContentType
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from dcim.models import DeviceRole, Platform, Rack, Region, Site, SiteGroup
|
from dcim.models import DeviceRole, Platform, Rack, Region, Site, SiteGroup
|
||||||
from extras.choices import ObjectChangeActionChoices
|
from extras.choices import JournalEntryKindChoices, ObjectChangeActionChoices
|
||||||
from extras.filters import *
|
from extras.filters import *
|
||||||
from extras.models import *
|
from extras.models import *
|
||||||
from ipam.models import IPAddress
|
from ipam.models import IPAddress
|
||||||
@ -284,31 +284,37 @@ class JournalEntryTestCase(TestCase):
|
|||||||
JournalEntry(
|
JournalEntry(
|
||||||
assigned_object=sites[0],
|
assigned_object=sites[0],
|
||||||
created_by=users[0],
|
created_by=users[0],
|
||||||
|
kind=JournalEntryKindChoices.KIND_INFO,
|
||||||
comments='New journal entry'
|
comments='New journal entry'
|
||||||
),
|
),
|
||||||
JournalEntry(
|
JournalEntry(
|
||||||
assigned_object=sites[0],
|
assigned_object=sites[0],
|
||||||
created_by=users[1],
|
created_by=users[1],
|
||||||
|
kind=JournalEntryKindChoices.KIND_SUCCESS,
|
||||||
comments='New journal entry'
|
comments='New journal entry'
|
||||||
),
|
),
|
||||||
JournalEntry(
|
JournalEntry(
|
||||||
assigned_object=sites[1],
|
assigned_object=sites[1],
|
||||||
created_by=users[2],
|
created_by=users[2],
|
||||||
|
kind=JournalEntryKindChoices.KIND_WARNING,
|
||||||
comments='New journal entry'
|
comments='New journal entry'
|
||||||
),
|
),
|
||||||
JournalEntry(
|
JournalEntry(
|
||||||
assigned_object=racks[0],
|
assigned_object=racks[0],
|
||||||
created_by=users[0],
|
created_by=users[0],
|
||||||
|
kind=JournalEntryKindChoices.KIND_INFO,
|
||||||
comments='New journal entry'
|
comments='New journal entry'
|
||||||
),
|
),
|
||||||
JournalEntry(
|
JournalEntry(
|
||||||
assigned_object=racks[0],
|
assigned_object=racks[0],
|
||||||
created_by=users[1],
|
created_by=users[1],
|
||||||
|
kind=JournalEntryKindChoices.KIND_SUCCESS,
|
||||||
comments='New journal entry'
|
comments='New journal entry'
|
||||||
),
|
),
|
||||||
JournalEntry(
|
JournalEntry(
|
||||||
assigned_object=racks[1],
|
assigned_object=racks[1],
|
||||||
created_by=users[2],
|
created_by=users[2],
|
||||||
|
kind=JournalEntryKindChoices.KIND_WARNING,
|
||||||
comments='New journal entry'
|
comments='New journal entry'
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -338,6 +344,10 @@ class JournalEntryTestCase(TestCase):
|
|||||||
}
|
}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||||
|
|
||||||
|
def test_kind(self):
|
||||||
|
params = {'kind': [JournalEntryKindChoices.KIND_INFO, JournalEntryKindChoices.KIND_SUCCESS]}
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
|
||||||
|
|
||||||
|
|
||||||
class ConfigContextTestCase(TestCase):
|
class ConfigContextTestCase(TestCase):
|
||||||
queryset = ConfigContext.objects.all()
|
queryset = ConfigContext.objects.all()
|
||||||
|
Loading…
Reference in New Issue
Block a user