diff --git a/src/peoplefinder/services/team.py b/src/peoplefinder/services/team.py index 46f756b99..8b09b9ba6 100644 --- a/src/peoplefinder/services/team.py +++ b/src/peoplefinder/services/team.py @@ -332,12 +332,18 @@ def profile_completion(self, team: Team) -> float | None: return cached_value # Get all people from all teams - members = self.get_team_members(team).select_related("person") - if not members: + people = Person.objects.filter( + id__in=Subquery(self.get_team_members(team).values("person_id")) + ) + completed_profiles = people.filter(profile_completion__gte=100) + + total_members = len(people) + total_completed_profiles = len(completed_profiles) + + if total_members == 0: return None - completed_profiles = members.filter(person__profile_completion__gte=100) - completed_profile_percent = len(completed_profiles) / len(members) + completed_profile_percent = total_completed_profiles / total_members # Cache the result for an hour. timeout = 60 * 60 diff --git a/src/peoplefinder/views/team.py b/src/peoplefinder/views/team.py index aec76fa4b..f51bd2072 100644 --- a/src/peoplefinder/views/team.py +++ b/src/peoplefinder/views/team.py @@ -62,7 +62,7 @@ def sub_teams(self) -> list[Team]: profile_completion = team_service.profile_completion(sub_team) if profile_completion: sub_team.profile_completion = ( - f"{profile_completion}% of profiles complete" + f"{profile_completion:.1%} of profiles complete" ) sub_teams.append(sub_team) @@ -109,7 +109,7 @@ def get_context_data(self, **kwargs: dict) -> dict: if profile_completion := team_service.profile_completion(self.object): context["profile_completion"] = ( - f"{profile_completion}% of profiles complete" + f"{profile_completion:.1%} of profiles complete" ) if self.request.user.has_perm("peoplefinder.delete_team"):