Skip to content

Commit

Permalink
fix sorting meet column bug in attendee list page since 2023 Christmas
Browse files Browse the repository at this point in the history
  • Loading branch information
xjlin0 committed May 8, 2024
1 parent 01c1859 commit 47edbda
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions attendees/persons/services/attendee_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def by_datagrid_params(
qs.select_related()
.prefetch_related()
.annotate(
attending_meet_slugs=Coalesce(ArrayAgg('attendings__meets__slug',
filter=Q(attendings__attendingmeet__finish__gte=now,
attendings__attendingmeet__is_removed=False),
distinct=True), []), # Sorting only since <@ for JSONBAgg doesn't work
attendingmeets=JSONBAgg(
Func(
Value('attendingmeet_id'), 'attendings__attendingmeet',
Expand Down Expand Up @@ -221,12 +225,12 @@ def orderby_parser(orderby_string, meets, current_user):
:param current_user:
:return: a List of sorter for order_by()
"""
meet_sorters = { # this sorter only needed since there're dynamic columns (slug is column name)
meet.slug: Func(F("attendingmeets"), function="'{}'=ANY".format(meet.slug))
meet_sorters = { # function="'[{\"meet_slug\":\"" + meet.slug + "\"}]'::jsonb <@ " doesn't sort for JSONBAgg
meet.slug: Func("attending_meet_slugs", function="'{}'=ANY".format(meet.slug))
for meet in Meet.objects.filter(
id__in=meets, assembly__division__organization=current_user.organization
)
}
} # this sorter only needed since there're dynamic columns (slug is column name)

orderby_list = (
[]
Expand Down

0 comments on commit 47edbda

Please sign in to comment.