mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
Add search indexers for DataSource, DataFile
This commit is contained in:
parent
a8ed149840
commit
efcc3500e2
8
netbox/core/apps.py
Normal file
8
netbox/core/apps.py
Normal file
@ -0,0 +1,8 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CoreConfig(AppConfig):
|
||||
name = "core"
|
||||
|
||||
def ready(self):
|
||||
from . import data_backends, search
|
@ -1,6 +1,7 @@
|
||||
import logging
|
||||
|
||||
from extras.choices import JobResultStatusChoices
|
||||
from netbox.search.backends import search_backend
|
||||
from .choices import *
|
||||
from .exceptions import SyncError
|
||||
from .models import DataSource
|
||||
@ -17,6 +18,10 @@ def sync_datasource(job_result, *args, **kwargs):
|
||||
try:
|
||||
job_result.start()
|
||||
datasource.sync()
|
||||
|
||||
# Update the search cache for DataFiles belonging to this source
|
||||
search_backend.cache(datasource.datafiles.iterator())
|
||||
|
||||
except SyncError as e:
|
||||
job_result.set_status(JobResultStatusChoices.STATUS_ERRORED)
|
||||
job_result.save()
|
||||
|
20
netbox/core/search.py
Normal file
20
netbox/core/search.py
Normal file
@ -0,0 +1,20 @@
|
||||
from netbox.search import SearchIndex, register_search
|
||||
from . import models
|
||||
|
||||
|
||||
@register_search
|
||||
class DataSourceIndex(SearchIndex):
|
||||
model = models.DataSource
|
||||
fields = (
|
||||
('name', 100),
|
||||
('url', 300),
|
||||
('description', 500),
|
||||
)
|
||||
|
||||
|
||||
@register_search
|
||||
class DataFileIndex(SearchIndex):
|
||||
model = models.DataFile
|
||||
fields = (
|
||||
('path', 200),
|
||||
)
|
Loading…
Reference in New Issue
Block a user