Addressed PR comments.

This commit is contained in:
Julio-Oliveira-Encora 2024-06-10 11:47:49 -03:00
parent f159c9560a
commit 5b7e031e2c
2 changed files with 10 additions and 7 deletions

View File

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

View File

@ -381,12 +381,13 @@ class BookmarksWidget(DashboardWidget):
if request.user.is_anonymous: if request.user.is_anonymous:
bookmarks = list() bookmarks = list()
else: else:
if self.config['order_by'] == BookmarkOrderingChoices.ORDERING_NAME_AZ: user_bookmarks = Bookmark.objects.filter(user=request.user)
bookmarks = sorted(Bookmark.objects.filter(user=request.user), if self.config['order_by'] == BookmarkOrderingChoices.ORDERING_NAME_ALPHABETICAL_AZ:
key=lambda bookmark: bookmark.__str__().lower() bookmarks = sorted(user_bookmarks, key=lambda bookmark: bookmark.__str__().lower())
) elif self.config['order_by'] == BookmarkOrderingChoices.ORDERING_NAME_ALPHABETICAL_ZA:
bookmarks = sorted(user_bookmarks, key=lambda bookmark: bookmark.__str__().lower(), reverse=True)
else: else:
bookmarks = Bookmark.objects.filter(user=request.user).order_by(self.config['order_by']) bookmarks = user_bookmarks.order_by(self.config['order_by'])
if object_types := self.config.get('object_types'): if object_types := self.config.get('object_types'):
models = get_models_from_content_types(object_types) models = get_models_from_content_types(object_types)
conent_types = ObjectType.objects.get_for_models(*models).values() conent_types = ObjectType.objects.get_for_models(*models).values()