Added alphabetical ordering of bookmarks.

This commit is contained in:
Julio-Oliveira-Encora 2024-06-05 15:44:19 -03:00
parent c27cb6f153
commit 759cbc369d
2 changed files with 8 additions and 1 deletions

View File

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

View File

@ -381,7 +381,12 @@ class BookmarksWidget(DashboardWidget):
if request.user.is_anonymous:
bookmarks = list()
else:
bookmarks = Bookmark.objects.filter(user=request.user).order_by(self.config['order_by'])
if self.config['order_by'] == BookmarkOrderingChoices.ORDERING_NAME_AZ:
bookmarks = sorted(Bookmark.objects.filter(user=request.user),
key=lambda bookmark: bookmark.__str__().lower()
)
else:
bookmarks = Bookmark.objects.filter(user=request.user).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()