Skip to content

Commit

Permalink
Change the sorting of training applications in the admin console (#2265)
Browse files Browse the repository at this point in the history
As outlined in #2263, the list of training applications is currently
sorted first by credentialing status and then by the timestamp of the
application submission. This makes it difficult to handle the
applications in the order they came in.

I propose to order the training applications by the keys (and order):

1. Date
2. Credentialed Status
3. Time

Like this, the applications can be handled by the day they came in,
while still handling applications of credentialed users first (as these
are the ones where an accepted training is immediately useful). Within
these groups, the applications are ordered by their exact timestamp.
  • Loading branch information
tompollard authored Jul 24, 2024
2 parents aa2679b + 030ffba commit f74b2dc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions physionet-django/console/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from django.contrib.contenttypes.models import ContentType
from django.contrib.redirects.models import Redirect
from django.db.models import Count, DurationField, F, Q
from django.db.models.functions import Cast
from django.db.models.functions import Cast, TruncDate
from django.forms import Select, Textarea, modelformset_factory
from django.forms.models import model_to_dict
from django.http import Http404, HttpResponse, JsonResponse, HttpResponseRedirect
Expand Down Expand Up @@ -1789,8 +1789,11 @@ def training_list(request, status):
"""
List all training applications.
"""
trainings = Training.objects.select_related(
'user__profile', 'training_type').order_by('-user__is_credentialed', 'application_datetime')
trainings = (
Training.objects.select_related("user__profile", "training_type")
.annotate(application_date=TruncDate("application_datetime"))
.order_by("application_date", "-user__is_credentialed", "application_datetime")
)

training_types = TrainingType.objects.values_list("name", flat=True)

Expand Down

0 comments on commit f74b2dc

Please sign in to comment.