mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
ffce5d968d
* #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>
34 lines
1022 B
Python
34 lines
1022 B
Python
import collections
|
|
|
|
from extras.constants import EXTRAS_FEATURES
|
|
|
|
|
|
class Registry(dict):
|
|
"""
|
|
Central registry for registration of functionality. Once a store (key) is defined, it cannot be overwritten or
|
|
deleted (although its value may be manipulated).
|
|
"""
|
|
def __getitem__(self, key):
|
|
try:
|
|
return super().__getitem__(key)
|
|
except KeyError:
|
|
raise KeyError(f"Invalid store: {key}")
|
|
|
|
def __setitem__(self, key, value):
|
|
if key in self:
|
|
raise KeyError(f"Store already set: {key}")
|
|
super().__setitem__(key, value)
|
|
|
|
def __delitem__(self, key):
|
|
raise TypeError("Cannot delete stores from registry")
|
|
|
|
|
|
# Initialize the global registry
|
|
registry = Registry()
|
|
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)
|