1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

15815 convert dashboard widgets for users/groups (#15839)

* 15815 convert dashboard widgets for users/groups

* 15815 review fixes

* 15815 catch DoesNotExist for widget content type

* 15815 add logging
This commit is contained in:
Arthur Hanson
2024-05-01 06:56:46 -07:00
committed by GitHub
parent 0a7d1e29b4
commit 209f596397
2 changed files with 41 additions and 2 deletions

View File

@ -1,3 +1,4 @@
import logging
import uuid
from functools import cached_property
from hashlib import sha256
@ -32,6 +33,8 @@ __all__ = (
'WidgetConfigForm',
)
logger = logging.getLogger('netbox.data_backends')
def get_object_type_choices():
return [
@ -54,8 +57,15 @@ def get_models_from_content_types(content_types):
models = []
for content_type_id in content_types:
app_label, model_name = content_type_id.split('.')
content_type = ObjectType.objects.get_by_natural_key(app_label, model_name)
models.append(content_type.model_class())
try:
content_type = ObjectType.objects.get_by_natural_key(app_label, model_name)
if content_type.model_class():
models.append(content_type.model_class())
else:
logger.debug(f"Dashboard Widget model_class not found: {app_label}:{model_name}")
except ObjectType.DoesNotExist:
logger.debug(f"Dashboard Widget ObjectType not found: {app_label}:{model_name}")
return models