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

Closes #14153: Filter ContentTypes by supported feature (#14191)

* WIP

* Remove FeatureQuery

* Standardize use of proxy ContentType for models

* Remove TODO

* Correctly filter BookmarksWidget object_types choices

* Add feature-specific object type validation
This commit is contained in:
Jeremy Stretch
2023-11-16 12:12:51 -05:00
committed by GitHub
parent 69a4c31072
commit e15647a2ce
30 changed files with 152 additions and 142 deletions

View File

@ -32,13 +32,20 @@ __all__ = (
)
def get_content_type_labels():
def get_object_type_choices():
return [
(content_type_identifier(ct), content_type_name(ct))
for ct in ContentType.objects.public().order_by('app_label', 'model')
]
def get_bookmarks_object_type_choices():
return [
(content_type_identifier(ct), content_type_name(ct))
for ct in ContentType.objects.with_feature('bookmarks').order_by('app_label', 'model')
]
def get_models_from_content_types(content_types):
"""
Return a list of models corresponding to the given content types, identified by natural key.
@ -158,7 +165,7 @@ class ObjectCountsWidget(DashboardWidget):
class ConfigForm(WidgetConfigForm):
models = forms.MultipleChoiceField(
choices=get_content_type_labels
choices=get_object_type_choices
)
filters = forms.JSONField(
required=False,
@ -207,7 +214,7 @@ class ObjectListWidget(DashboardWidget):
class ConfigForm(WidgetConfigForm):
model = forms.ChoiceField(
choices=get_content_type_labels
choices=get_object_type_choices
)
page_size = forms.IntegerField(
required=False,
@ -343,8 +350,7 @@ class BookmarksWidget(DashboardWidget):
class ConfigForm(WidgetConfigForm):
object_types = forms.MultipleChoiceField(
# TODO: Restrict the choices by FeatureQuery('bookmarks')
choices=get_content_type_labels,
choices=get_bookmarks_object_type_choices,
required=False
)
order_by = forms.ChoiceField(