Correctly filter BookmarksWidget object_types choices

This commit is contained in:
Jeremy Stretch 2023-11-06 09:45:22 -05:00
parent d575737f92
commit bfd10ebfe9

View File

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