File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -117,10 +117,14 @@ class BookmarkOrderingChoices(ChoiceSet):
117117
118118 ORDERING_NEWEST = '-created'
119119 ORDERING_OLDEST = 'created'
120+ ORDERING_ALPHABETICAL_AZ = 'name'
121+ ORDERING_ALPHABETICAL_ZA = '-name'
120122
121123 CHOICES = (
122124 (ORDERING_NEWEST , _ ('Newest' )),
123125 (ORDERING_OLDEST , _ ('Oldest' )),
126+ (ORDERING_ALPHABETICAL_AZ , _ ('Alphabetical (A-Z)' )),
127+ (ORDERING_ALPHABETICAL_ZA , _ ('Alphabetical (Z-A)' )),
124128 )
125129
126130#
Original file line number Diff line number Diff line change @@ -381,11 +381,17 @@ def render(self, request):
381381 if request .user .is_anonymous :
382382 bookmarks = list ()
383383 else :
384- bookmarks = Bookmark .objects .filter (user = request .user ).order_by (self .config ['order_by' ])
384+ user_bookmarks = Bookmark .objects .filter (user = request .user )
385+ if self .config ['order_by' ] == BookmarkOrderingChoices .ORDERING_ALPHABETICAL_AZ :
386+ bookmarks = sorted (user_bookmarks , key = lambda bookmark : bookmark .__str__ ().lower ())
387+ elif self .config ['order_by' ] == BookmarkOrderingChoices .ORDERING_ALPHABETICAL_ZA :
388+ bookmarks = sorted (user_bookmarks , key = lambda bookmark : bookmark .__str__ ().lower (), reverse = True )
389+ else :
390+ bookmarks = user_bookmarks .order_by (self .config ['order_by' ])
385391 if object_types := self .config .get ('object_types' ):
386392 models = get_models_from_content_types (object_types )
387- conent_types = ObjectType .objects .get_for_models (* models ).values ()
388- bookmarks = bookmarks .filter (object_type__in = conent_types )
393+ content_types = ObjectType .objects .get_for_models (* models ).values ()
394+ bookmarks = bookmarks .filter (object_type__in = content_types )
389395 if max_items := self .config .get ('max_items' ):
390396 bookmarks = bookmarks [:max_items ]
391397
You can’t perform that action at this time.
0 commit comments