Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions sortable_listview/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class SortableListView(ListView):
del_query_parameters = ['page'] # get paramaters we don't want to preserve
# End of Defaults

sort_order:str = None
sort_field:str = None
sort_link_list:list[dict] = None

def __init__(self, *args, **kwargs):
"""
Convert allowed_sort_fields to an OrderedDict data structure to preserve
Expand Down Expand Up @@ -126,7 +130,7 @@ def set_sort(self, request):
if not sort_field in self._allowed_sort_fields:
sort_order = self.default_sort_order
sort_field = self.default_sort_field
return (sort_order, sort_field)
return sort_order, sort_field

def get_sort_string(self, sort=None):
if not sort:
Expand All @@ -141,7 +145,7 @@ def get_next_sort_string(self, field):
If we're already sorted by the field then the sort query
returned reverses the sort order.
"""
# self.sort_field is the currect sort field
# self.sort_field is the current sort field
if field == self.sort_field:
next_sort = self.toggle_sort_order() + field
else:
Expand All @@ -153,7 +157,7 @@ def get_next_sort_string(self, field):
def get_sort_indicator(self, field):
"""
Returns a sort class for the active sort only. That is, if field is not
sort_field, then nothing will be returned becaues the sort is not
sort_field, then nothing will be returned because the sort is not
active.
"""
indicator = ''
Expand All @@ -164,6 +168,7 @@ def get_sort_indicator(self, field):
return indicator

def toggle_sort_order(self):
toggled_sort_order = ''
if self.sort_order == '-':
toggled_sort_order = ''
if self.sort_order == '':
Expand Down