|
| 1 | +from datetime import datetime |
| 2 | + |
1 | 3 | from django.shortcuts import get_object_or_404, render |
2 | 4 |
|
3 | | -from codelists.models import Status |
| 5 | +from codelists.models import Codelist, Status |
4 | 6 |
|
5 | 7 | from ..models import User |
6 | 8 |
|
7 | 9 |
|
8 | 10 | def user(request, username): |
9 | 11 | user = get_object_or_404(User, username=username) |
10 | 12 |
|
11 | | - def codelist_sort_key(codelist): |
| 13 | + def codelist_sort_key(codelist: Codelist) -> tuple[str, bool, str, datetime]: |
| 14 | + """ |
| 15 | + We sort by name, then owner, then date (all case-insensitive where applicable), |
| 16 | + while making sure the current user's codelists appear before organisation ones |
| 17 | + when names are the same. |
| 18 | + """ |
12 | 19 | return ( |
13 | 20 | codelist.name.casefold(), |
14 | 21 | codelist.owner != user, |
@@ -47,10 +54,6 @@ def codelist_sort_key(codelist): |
47 | 54 | ), |
48 | 55 | } |
49 | 56 | for codelist in sorted(codelists_to_display, key=codelist_sort_key) |
50 | | - # We sort by name, then owner, then date (all case-insensitive where applicable), |
51 | | - # while making sure the current user's codelists appear before organisation ones |
52 | | - # when names are the same. |
53 | | - # |
54 | 57 | # We can't use a queryset order_by (where versions_under_review/drafts are querysets of CodelistVersion |
55 | 58 | # instances), as a codelist can have multiple versions and multiple handles, and this results in duplicates |
56 | 59 | # in the returned queryset. See https://code.djangoproject.com/ticket/18165 |
|
0 commit comments