mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-19 17:59:11 -06:00
12084 saved filters (#12090)
* 12084 change back saved filter saving * 12084 doc string * 12084 add test * Pass SavedFilter initial parameters as JSON & relocate test --------- Co-authored-by: jeremystretch <jstretch@netboxlabs.com>
This commit is contained in:
parent
0330c652bd
commit
e467589730
@ -4,6 +4,7 @@ from django.test import TestCase
|
||||
from dcim.forms import SiteForm
|
||||
from dcim.models import Site
|
||||
from extras.choices import CustomFieldTypeChoices
|
||||
from extras.forms import SavedFilterForm
|
||||
from extras.models import CustomField
|
||||
|
||||
|
||||
@ -77,3 +78,24 @@ class CustomFieldModelFormTest(TestCase):
|
||||
for field_type, _ in CustomFieldTypeChoices.CHOICES:
|
||||
self.assertIn(field_type, instance.custom_field_data)
|
||||
self.assertIsNone(instance.custom_field_data[field_type])
|
||||
|
||||
|
||||
class SavedFilterFormTest(TestCase):
|
||||
|
||||
def test_basic_submit(self):
|
||||
"""
|
||||
Test form submission and validation
|
||||
"""
|
||||
form = SavedFilterForm({
|
||||
'name': 'test-sf',
|
||||
'slug': 'test-sf',
|
||||
'content_types': [ContentType.objects.get_for_model(Site).pk],
|
||||
'weight': 100,
|
||||
'parameters': {
|
||||
"status": [
|
||||
"active"
|
||||
]
|
||||
}
|
||||
})
|
||||
self.assertTrue(form.is_valid())
|
||||
form.save()
|
||||
|
@ -1,5 +1,6 @@
|
||||
import datetime
|
||||
import decimal
|
||||
import json
|
||||
from urllib.parse import quote
|
||||
from typing import Dict, Any
|
||||
|
||||
@ -321,7 +322,7 @@ def applied_filters(context, model, form, query_params):
|
||||
save_link = None
|
||||
if user.has_perm('extras.add_savedfilter') and 'filter_id' not in context['request'].GET:
|
||||
content_type = ContentType.objects.get_for_model(model).pk
|
||||
parameters = context['request'].GET.urlencode()
|
||||
parameters = json.dumps(context['request'].GET)
|
||||
url = reverse('extras:savedfilter_add')
|
||||
save_link = f"{url}?content_types={content_type}¶meters={quote(parameters)}"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user