mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
* 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:
@ -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(
|
||||
|
Reference in New Issue
Block a user