1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00
Files
netbox-community-netbox/netbox/netbox/registry.py
Jeremy Stretch 084a2cc52c Closes #9416: Dashboard widgets (#11823)
* Replace masonry with gridstack

* Initial work on dashboard widgets

* Implement function to save dashboard layout

* Define a default dashboard

* Clean up widgets

* Implement widget configuration views & forms

* Permit merging dict value with existing dict in user config

* Add widget deletion view

* Enable HTMX for widget configuration

* Implement view to add dashboard widgets

* ObjectCountsWidget: Identify models by app_label & name

* Add color customization to dashboard widgets

* Introduce Dashboard model to store user dashboard layout & config

* Clean up utility functions

* Remove hard-coded API URL

* Use fixed grid cell height

* Add modal close button

* Clean up dashboard views

* Rebuild JS
2023-02-24 16:04:00 -05:00

32 lines
894 B
Python

import collections
class Registry(dict):
"""
Central registry for registration of functionality. Once a Registry is initialized, keys cannot be added or
removed (though the value of each key is mutable).
"""
def __getitem__(self, key):
try:
return super().__getitem__(key)
except KeyError:
raise KeyError(f"Invalid store: {key}")
def __setitem__(self, key, value):
raise TypeError("Cannot add stores to registry after initialization")
def __delitem__(self, key):
raise TypeError("Cannot delete stores from registry")
# Initialize the global registry
registry = Registry({
'data_backends': dict(),
'denormalized_fields': collections.defaultdict(list),
'model_features': dict(),
'plugins': dict(),
'search': dict(),
'views': collections.defaultdict(dict),
'widgets': dict(),
})