Skip to content

Commit 07cc480

Browse files
committed
Add types and docstring to codelist_sort_key
1 parent 60b1071 commit 07cc480

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

opencodelists/views/user.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1+
from datetime import datetime
2+
13
from django.shortcuts import get_object_or_404, render
24

3-
from codelists.models import Status
5+
from codelists.models import Codelist, Status
46

57
from ..models import User
68

79

810
def user(request, username):
911
user = get_object_or_404(User, username=username)
1012

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+
"""
1219
return (
1320
codelist.name.casefold(),
1421
codelist.owner != user,
@@ -47,10 +54,6 @@ def codelist_sort_key(codelist):
4754
),
4855
}
4956
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-
#
5457
# We can't use a queryset order_by (where versions_under_review/drafts are querysets of CodelistVersion
5558
# instances), as a codelist can have multiple versions and multiple handles, and this results in duplicates
5659
# in the returned queryset. See https://code.djangoproject.com/ticket/18165

0 commit comments

Comments
 (0)