mirror of
https://github.com/netbox-community/netbox.git
synced 2026-03-27 20:01:47 +01:00
Closes #10697: Move application registry into core app
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from extras.registry import registry
|
||||
from netbox.registry import registry
|
||||
from netbox.search.backends import search_backend
|
||||
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ from django.core.exceptions import ImproperlyConfigured
|
||||
from django.template.loader import get_template
|
||||
from django.utils.module_loading import import_string
|
||||
|
||||
from extras.registry import registry
|
||||
from netbox.navigation import MenuGroup
|
||||
from netbox.registry import registry
|
||||
from netbox.search import register_search
|
||||
from utilities.choices import ButtonColorChoices
|
||||
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
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'] = dict()
|
||||
registry['views'] = collections.defaultdict(dict)
|
||||
@@ -3,7 +3,7 @@ from django.conf import settings
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from extras.plugins import PluginTemplateExtension
|
||||
from extras.registry import registry
|
||||
from netbox.registry import registry
|
||||
|
||||
register = template_.Library()
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ from django.test import Client, TestCase, override_settings
|
||||
from django.urls import reverse
|
||||
|
||||
from extras.plugins import PluginMenu
|
||||
from extras.registry import registry
|
||||
from extras.tests.dummy_plugin import config as dummy_config
|
||||
from netbox.graphql.schema import Query
|
||||
from netbox.registry import registry
|
||||
|
||||
|
||||
@skipIf('extras.tests.dummy_plugin' not in settings.PLUGINS, "dummy_plugin not in settings.PLUGINS")
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from extras.registry import Registry
|
||||
|
||||
|
||||
class RegistryTest(TestCase):
|
||||
|
||||
def test_add_store(self):
|
||||
reg = Registry()
|
||||
reg['foo'] = 123
|
||||
|
||||
self.assertEqual(reg['foo'], 123)
|
||||
|
||||
def test_manipulate_store(self):
|
||||
reg = Registry()
|
||||
reg['foo'] = [1, 2]
|
||||
reg['foo'].append(3)
|
||||
|
||||
self.assertListEqual(reg['foo'], [1, 2, 3])
|
||||
|
||||
def test_overwrite_store(self):
|
||||
reg = Registry()
|
||||
reg['foo'] = 123
|
||||
|
||||
with self.assertRaises(KeyError):
|
||||
reg['foo'] = 456
|
||||
|
||||
def test_delete_store(self):
|
||||
reg = Registry()
|
||||
reg['foo'] = 123
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
del reg['foo']
|
||||
@@ -3,7 +3,7 @@ from django.utils.deconstruct import deconstructible
|
||||
from taggit.managers import _TaggableManager
|
||||
|
||||
from extras.constants import EXTRAS_FEATURES
|
||||
from extras.registry import registry
|
||||
from netbox.registry import registry
|
||||
|
||||
|
||||
def is_taggable(obj):
|
||||
|
||||
@@ -5,11 +5,11 @@ from django.contrib.contenttypes.models import ContentType
|
||||
from django.utils import timezone
|
||||
from django_rq import get_queue
|
||||
|
||||
from netbox.registry import registry
|
||||
from utilities.api import get_serializer_for_model
|
||||
from utilities.utils import serialize_object
|
||||
from .choices import *
|
||||
from .models import Webhook
|
||||
from .registry import registry
|
||||
|
||||
|
||||
def serialize_for_webhook(instance):
|
||||
|
||||
Reference in New Issue
Block a user