Skip to content

Commit

Permalink
lowercase grant title and sort asc and desc
Browse files Browse the repository at this point in the history
  • Loading branch information
Jer-Sch committed Nov 23, 2021
1 parent d462049 commit e4f1ae3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/grants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from django.core.paginator import EmptyPage, Paginator
from django.db import connection, transaction
from django.db.models import Q, Subquery
from django.db.models.functions import Lower
from django.http import Http404, HttpResponse, JsonResponse
from django.http.response import HttpResponseBadRequest, HttpResponseServerError
from django.shortcuts import get_object_or_404, redirect
Expand Down Expand Up @@ -760,6 +761,12 @@ def get_grants_by_filters(
field_name = f'clr_prediction_curve__{sort_by_index}__2'
_grants = _grants.order_by(f"{order}{field_name}")

elif 'title' in sort:
if sort[0] == '-':
_grants = _grants.order_by(Lower('title').desc())
else:
_grants = _grants.order_by(Lower('title'))

# elif 'random_shuffle' in sort:
# _grants = _grants.order_by('?')

Expand All @@ -769,7 +776,7 @@ def get_grants_by_filters(
_grants = _grants.filter(is_clr_active=True).order_by(f"{sort}")

elif sort.replace('-', '') in [
'weighted_shuffle', 'metadata__upcoming', 'metadata__gem', 'created_on', 'amount_received', 'contribution_count', 'contributor_count', 'last_update', 'title'
'weighted_shuffle', 'metadata__upcoming', 'metadata__gem', 'created_on', 'amount_received', 'contribution_count', 'contributor_count', 'last_update'
]:
print(f"Sort is {sort}")
_grants = _grants.order_by(f"{sort}")
Expand Down

0 comments on commit e4f1ae3

Please sign in to comment.