Fix sorting by breaking ties

This commit is contained in:
Tanner Collin 2022-08-24 21:27:24 +00:00
parent fbb388b67c
commit 118a99aedd
2 changed files with 12 additions and 12 deletions

View File

@ -97,33 +97,33 @@ class SearchViewSet(Base, Retrieve):
elif self.action == 'create': elif self.action == 'create':
if sort == 'recently_vetted': if sort == 'recently_vetted':
queryset = queryset.filter(vetted_date__isnull=False) queryset = queryset.filter(vetted_date__isnull=False)
queryset = queryset.order_by('-vetted_date') queryset = queryset.order_by('-vetted_date', '-id')
elif sort == 'newest_active': elif sort == 'newest_active':
queryset = queryset.filter(paused_date__isnull=True) queryset = queryset.filter(paused_date__isnull=True)
queryset = queryset.order_by('-application_date') queryset = queryset.order_by('-application_date', '-id')
elif sort == 'newest_overall': elif sort == 'newest_overall':
queryset = queryset.order_by('-application_date') queryset = queryset.order_by('-application_date', '-id')
elif sort == 'oldest_active': elif sort == 'oldest_active':
queryset = queryset.filter(paused_date__isnull=True) queryset = queryset.filter(paused_date__isnull=True)
queryset = queryset.order_by('application_date') queryset = queryset.order_by('application_date', 'id')
elif sort == 'oldest_overall': elif sort == 'oldest_overall':
queryset = queryset.filter(application_date__isnull=False) queryset = queryset.filter(application_date__isnull=False)
queryset = queryset.order_by('application_date') queryset = queryset.order_by('application_date', 'id')
elif sort == 'recently_inactive': elif sort == 'recently_inactive':
queryset = queryset.filter(paused_date__isnull=False) queryset = queryset.filter(paused_date__isnull=False)
queryset = queryset.order_by('-paused_date') queryset = queryset.order_by('-paused_date')
elif sort == 'is_director': elif sort == 'is_director':
queryset = queryset.filter(is_director=True) queryset = queryset.filter(is_director=True)
queryset = queryset.order_by('application_date') queryset = queryset.order_by('application_date', 'id')
elif sort == 'is_instructor': elif sort == 'is_instructor':
queryset = queryset.filter(paused_date__isnull=True, is_instructor=True) queryset = queryset.filter(paused_date__isnull=True, is_instructor=True)
queryset = queryset.order_by('application_date') queryset = queryset.order_by('application_date', 'id')
elif sort == 'due': elif sort == 'due':
queryset = queryset.filter(status='Due') queryset = queryset.filter(status='Due')
queryset = queryset.order_by('expire_date') queryset = queryset.order_by('expire_date', 'id')
elif sort == 'overdue': elif sort == 'overdue':
queryset = queryset.filter(status='Overdue') queryset = queryset.filter(status='Overdue')
queryset = queryset.order_by('expire_date') queryset = queryset.order_by('expire_date', 'id')
elif sort == 'last_scanned': elif sort == 'last_scanned':
if self.request.user.member.allow_last_scanned: if self.request.user.member.allow_last_scanned:
queryset = queryset.filter(allow_last_scanned=True) queryset = queryset.filter(allow_last_scanned=True)
@ -133,7 +133,7 @@ class SearchViewSet(Base, Retrieve):
else: else:
queryset = [] queryset = []
elif sort == 'everyone': elif sort == 'everyone':
queryset = queryset.annotate(Count('user__transactions')).order_by('-user__transactions__count') queryset = queryset.annotate(Count('user__transactions')).order_by('-user__transactions__count', 'id')
elif sort == 'best_looking': elif sort == 'best_looking':
queryset = [] queryset = []
@ -984,7 +984,7 @@ class VettingViewSet(Base, List):
queryset = queryset.filter(vetted_date__isnull=True) queryset = queryset.filter(vetted_date__isnull=True)
queryset = queryset.filter(current_start_date__lte=four_weeks_ago) queryset = queryset.filter(current_start_date__lte=four_weeks_ago)
return queryset.order_by('-current_start_date') return queryset.order_by('-current_start_date', '-id')
class UsageViewSet(Base): class UsageViewSet(Base):

View File

@ -290,7 +290,7 @@ export function TransactionList(props) {
<Table.Body> <Table.Body>
{transactions.length ? {transactions.length ?
transactions.slice().sort((a, b) => a.date < b.date ? 1 : -1).map(x => transactions.map(x =>
<Table.Row key={x.id}> <Table.Row key={x.id}>
<Table.Cell style={{ minWidth: '8rem' }}> <Table.Cell style={{ minWidth: '8rem' }}>
<Link to={'/transactions/'+x.id}>{moment(x.date).format('ll')}</Link> <Link to={'/transactions/'+x.id}>{moment(x.date).format('ll')}</Link>