mirror of
https://github.com/netbox-community/netbox.git
synced 2026-03-21 17:10:10 +01:00
8927 plugin search (#10489)
* #7016 base search classes * 7016 add search indexes * 7016 add search indexes * 7016 add search indexes * 7016 add search indexes * 7016 add search indexes * 7016 add search indexes * 8927 refactor search * 8927 refactor search * 8927 refactor search * 8927 refactor search * 8927 get search choices working * 8927 cleanup - optimize * 8927 use backend search function * 8927 fix for plugin search * 8927 add docs * Move search app to a module under netbox/ * Utilize global registry to register model search classes * Build search form options from registry * Determine search categories from model app by default * Enable dynamic search registration for plugins * Update docs & improve plugin support * Clean up search backend class * Docs for #8927 Co-authored-by: jeremystretch <jstretch@ns1.com>
This commit is contained in:
@@ -5,5 +5,4 @@ class ExtrasConfig(AppConfig):
|
||||
name = "extras"
|
||||
|
||||
def ready(self):
|
||||
import extras.lookups
|
||||
import extras.signals
|
||||
from . import lookups, search, signals
|
||||
|
||||
@@ -9,6 +9,7 @@ from django.template.loader import get_template
|
||||
from extras.plugins.utils import import_object
|
||||
from extras.registry import registry
|
||||
from netbox.navigation import MenuGroup
|
||||
from netbox.search import register_search
|
||||
from utilities.choices import ButtonColorChoices
|
||||
|
||||
|
||||
@@ -60,6 +61,7 @@ class PluginConfig(AppConfig):
|
||||
|
||||
# Default integration paths. Plugin authors can override these to customize the paths to
|
||||
# integrated components.
|
||||
search_indexes = 'search.indexes'
|
||||
graphql_schema = 'graphql.schema'
|
||||
menu = 'navigation.menu'
|
||||
menu_items = 'navigation.menu_items'
|
||||
@@ -69,6 +71,11 @@ class PluginConfig(AppConfig):
|
||||
def ready(self):
|
||||
plugin_name = self.name.rsplit('.', 1)[-1]
|
||||
|
||||
# Search extensions
|
||||
search_indexes = import_object(f"{self.__module__}.{self.search_indexes}") or []
|
||||
for idx in search_indexes:
|
||||
register_search()(idx)
|
||||
|
||||
# Register template content (if defined)
|
||||
template_extensions = import_object(f"{self.__module__}.{self.template_extensions}")
|
||||
if template_extensions is not None:
|
||||
|
||||
@@ -29,4 +29,5 @@ registry['model_features'] = {
|
||||
feature: collections.defaultdict(set) for feature in EXTRAS_FEATURES
|
||||
}
|
||||
registry['denormalized_fields'] = collections.defaultdict(list)
|
||||
registry['search'] = collections.defaultdict(dict)
|
||||
registry['views'] = collections.defaultdict(dict)
|
||||
|
||||
14
netbox/extras/search.py
Normal file
14
netbox/extras/search.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import extras.filtersets
|
||||
import extras.tables
|
||||
from extras.models import JournalEntry
|
||||
from netbox.search import SearchIndex, register_search
|
||||
|
||||
|
||||
@register_search()
|
||||
class JournalEntryIndex(SearchIndex):
|
||||
model = JournalEntry
|
||||
queryset = JournalEntry.objects.prefetch_related('assigned_object', 'created_by')
|
||||
filterset = extras.filtersets.JournalEntryFilterSet
|
||||
table = extras.tables.JournalEntryTable
|
||||
url = 'extras:journalentry_list'
|
||||
category = 'Journal'
|
||||
13
netbox/extras/tests/dummy_plugin/search.py
Normal file
13
netbox/extras/tests/dummy_plugin/search.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from netbox.search import SearchIndex
|
||||
from .models import DummyModel
|
||||
|
||||
|
||||
class DummyModelIndex(SearchIndex):
|
||||
model = DummyModel
|
||||
queryset = DummyModel.objects.all()
|
||||
url = 'plugins:dummy_plugin:dummy_models'
|
||||
|
||||
|
||||
indexes = (
|
||||
DummyModelIndex,
|
||||
)
|
||||
Reference in New Issue
Block a user