From 8026f79cbba9678cc16cefb307f9e04782848c46 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 4 Jul 2024 08:23:05 -0400 Subject: [PATCH] Fixes #16813: Fix ordering of bookmarks in dashboard widget when filtering by object type --- netbox/extras/dashboard/widgets.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/netbox/extras/dashboard/widgets.py b/netbox/extras/dashboard/widgets.py index c4710468b..edf6df2e4 100644 --- a/netbox/extras/dashboard/widgets.py +++ b/netbox/extras/dashboard/widgets.py @@ -381,17 +381,17 @@ class BookmarksWidget(DashboardWidget): if request.user.is_anonymous: bookmarks = list() else: - user_bookmarks = Bookmark.objects.filter(user=request.user) - if self.config['order_by'] == BookmarkOrderingChoices.ORDERING_ALPHABETICAL_AZ: - bookmarks = sorted(user_bookmarks, key=lambda bookmark: bookmark.__str__().lower()) - elif self.config['order_by'] == BookmarkOrderingChoices.ORDERING_ALPHABETICAL_ZA: - bookmarks = sorted(user_bookmarks, key=lambda bookmark: bookmark.__str__().lower(), reverse=True) - else: - bookmarks = user_bookmarks.order_by(self.config['order_by']) + bookmarks = Bookmark.objects.filter(user=request.user) if object_types := self.config.get('object_types'): models = get_models_from_content_types(object_types) content_types = ObjectType.objects.get_for_models(*models).values() bookmarks = bookmarks.filter(object_type__in=content_types) + if self.config['order_by'] == BookmarkOrderingChoices.ORDERING_ALPHABETICAL_AZ: + bookmarks = sorted(bookmarks, key=lambda bookmark: bookmark.__str__().lower()) + elif self.config['order_by'] == BookmarkOrderingChoices.ORDERING_ALPHABETICAL_ZA: + bookmarks = sorted(bookmarks, key=lambda bookmark: bookmark.__str__().lower(), reverse=True) + else: + bookmarks = bookmarks.order_by(self.config['order_by']) if max_items := self.config.get('max_items'): bookmarks = bookmarks[:max_items]