|
6 | 6 | from django.contrib.auth import login |
7 | 7 | from django.contrib.auth.decorators import login_required |
8 | 8 | from django.contrib.auth.models import Group |
| 9 | +from django.db.models import Case, IntegerField, Value, When |
9 | 10 | from django.http import HttpResponse, HttpResponseRedirect |
10 | 11 | from django.shortcuts import get_object_or_404, render |
11 | 12 | from django.urls import reverse_lazy |
@@ -304,7 +305,19 @@ def list_coapplicant_invites(request, pk): |
304 | 305 | has_permission( |
305 | 306 | "co_applicants_view", user=request.user, object=submission, raise_exception=True |
306 | 307 | ) |
307 | | - co_applicant_invites = CoApplicantInvite.objects.filter(submission=submission) |
| 308 | + status_order = Case( |
| 309 | + When(status="accepted", then=Value(0)), |
| 310 | + When(status="pending", then=Value(1)), |
| 311 | + When(status="rejected", then=Value(2)), |
| 312 | + When(status="expired", then=Value(3)), |
| 313 | + default=Value(4), |
| 314 | + output_field=IntegerField(), |
| 315 | + ) |
| 316 | + co_applicant_invites = ( |
| 317 | + CoApplicantInvite.objects.filter(submission=submission) |
| 318 | + .annotate(status_priority=status_order) |
| 319 | + .order_by("status_priority", "-responded_on", "-created_at") |
| 320 | + ) |
308 | 321 | return render( |
309 | 322 | request, |
310 | 323 | "funds/includes/co-applicant-block.html", |
|
0 commit comments