Move organization detail queryset optimizations to model; add tests for organization detail queryset
All checks were successful
Deploy to Server / deploy (push) Successful in 30s

This commit is contained in:
Joakim Hellsén 2026-04-12 05:19:24 +02:00
commit 1790bac2e0
Signed by: Joakim Hellsén
SSH key fingerprint: SHA256:/9h/CsExpFp+PRhsfA0xznFx2CGfTT5R/kpuFfUgEQk
3 changed files with 96 additions and 11 deletions

View file

@ -316,21 +316,18 @@ def organization_detail_view(request: HttpRequest, twitch_id: str) -> HttpRespon
Returns:
HttpResponse: The rendered organization detail page.
Raises:
Http404: If the organization is not found.
"""
try:
organization: Organization = Organization.objects.get(twitch_id=twitch_id)
except Organization.DoesNotExist as exc:
msg = "No organization found matching the query"
raise Http404(msg) from exc
organization: Organization = get_object_or_404(
Organization.for_detail_view(),
twitch_id=twitch_id,
)
games: QuerySet[Game] = organization.games.all() # pyright: ignore[reportAttributeAccessIssue]
games: list[Game] = list(getattr(organization, "games_for_detail", []))
org_name: str = organization.name or organization.twitch_id
games_count: int = games.count()
s: Literal["", "s"] = "" if games_count == 1 else "s"
org_description: str = f"{org_name} has {games_count} game{s}."
games_count: int = len(games)
noun: str = "game" if games_count == 1 else "games"
org_description: str = f"{org_name} has {games_count} {noun}."
url: str = build_absolute_uri(
reverse("twitch:organization_detail", args=[organization.twitch_id]),