Rename choice constants & fix unrelated typo

This commit is contained in:
Jeremy Stretch 2024-06-11 09:01:41 -04:00
parent 5b7e031e2c
commit 46065e161b
2 changed files with 8 additions and 8 deletions

View File

@ -117,14 +117,14 @@ class BookmarkOrderingChoices(ChoiceSet):
ORDERING_NEWEST = '-created'
ORDERING_OLDEST = 'created'
ORDERING_NAME_ALPHABETICAL_AZ = 'name'
ORDERING_NAME_ALPHABETICAL_ZA = '-name'
ORDERING_ALPHABETICAL_AZ = 'name'
ORDERING_ALPHABETICAL_ZA = '-name'
CHOICES = (
(ORDERING_NEWEST, _('Newest')),
(ORDERING_OLDEST, _('Oldest')),
(ORDERING_NAME_ALPHABETICAL_AZ, _('Alphabetical (A-Z)')),
(ORDERING_NAME_ALPHABETICAL_ZA, _('Alphabetical (Z-A)')),
(ORDERING_ALPHABETICAL_AZ, _('Alphabetical (A-Z)')),
(ORDERING_ALPHABETICAL_ZA, _('Alphabetical (Z-A)')),
)
#

View File

@ -382,16 +382,16 @@ class BookmarksWidget(DashboardWidget):
bookmarks = list()
else:
user_bookmarks = Bookmark.objects.filter(user=request.user)
if self.config['order_by'] == BookmarkOrderingChoices.ORDERING_NAME_ALPHABETICAL_AZ:
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_NAME_ALPHABETICAL_ZA:
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'])
if object_types := self.config.get('object_types'):
models = get_models_from_content_types(object_types)
conent_types = ObjectType.objects.get_for_models(*models).values()
bookmarks = bookmarks.filter(object_type__in=conent_types)
content_types = ObjectType.objects.get_for_models(*models).values()
bookmarks = bookmarks.filter(object_type__in=content_types)
if max_items := self.config.get('max_items'):
bookmarks = bookmarks[:max_items]