feat: group people by role priority

This commit is contained in:
mohamad
2026-10-29 03:53:39 +08:00
parent 7c186b4230
commit 641f4e6cee
15 changed files with 186 additions and 45 deletions
+25
View File
@@ -0,0 +1,25 @@
from collections import OrderedDict
ROLE_PRIORITY = {"lead": 0, "leader": 0, "organizer": 1, "collaborator": 2}
ROLE_TITLES = {0: "Lead / Leader", 1: "Organizers", 2: "Collaborators"}
def person_sort_key(person):
role = (person.role or "").strip().casefold()
return (ROLE_PRIORITY.get(role, 3), role if role not in ROLE_PRIORITY else "", person.order, person.pk or 0)
def group_people(people):
groups = OrderedDict()
for person in sorted(people, key=person_sort_key):
role = (person.role or "").strip()
priority = ROLE_PRIORITY.get(role.casefold(), 3)
key = priority if priority < 3 else role.casefold()
if key not in groups:
groups[key] = {
"title": ROLE_TITLES[priority] if priority < 3 else role or "Other contributors",
"people": [],
}
groups[key]["people"].append(person)
return list(groups.values())