Skip to content

Commit

Permalink
Annotate query results with QuerySet instead of BaseManager (#3668)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmsetzer authored Nov 26, 2024
1 parent 64cb146 commit 693bfe5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions perma_web/perma/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from django.core.paginator import EmptyPage, Page, Paginator
from django.core.serializers.json import DjangoJSONEncoder
from django.db.models import Q
from django.db.models.manager import BaseManager
from django.db.models.query import QuerySet
from django.http import (
Http404,
HttpRequest,
Expand Down Expand Up @@ -118,8 +118,8 @@ def get_help_text(self):
### list view helpers ###

def apply_search_query(
request: HttpRequest, queryset: BaseManager[T], fields: list[str]
) -> tuple[BaseManager[T], str]:
request: HttpRequest, queryset: QuerySet[T], fields: list[str]
) -> tuple[QuerySet[T], str]:
"""
For the given `queryset`,
apply consecutive .filter()s such that each word
Expand All @@ -146,10 +146,10 @@ def apply_search_query(

def apply_sort_order(
request: HttpRequest,
queryset: BaseManager[T],
queryset: QuerySet[T],
valid_sorts: list[str],
default_sort: str | None = None,
) -> tuple[BaseManager[T], str]:
) -> tuple[QuerySet[T], str]:
"""
For the given `queryset`,
apply sort order based on request.GET['sort'].
Expand All @@ -165,7 +165,7 @@ def apply_sort_order(
sort = default_sort
return queryset.order_by(sort), sort

def apply_pagination(request: HttpRequest, queryset: BaseManager[T]) -> Page:
def apply_pagination(request: HttpRequest, queryset: QuerySet[T]) -> Page:
"""
For the given `queryset`,
apply pagination based on request.GET['page'].
Expand All @@ -185,7 +185,7 @@ def apply_pagination(request: HttpRequest, queryset: BaseManager[T]) -> Page:


def export_queryset(
queryset: BaseManager[T],
queryset: QuerySet[T],
export_format: Literal['csv', 'json'],
field_names: list[str],
filename: str = 'export',
Expand Down
4 changes: 2 additions & 2 deletions perma_web/perma/views/user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.core.exceptions import PermissionDenied
from django.db.models import Count, F, Max, Sum
from django.db.models.functions import Coalesce, Greatest
from django.db.models.manager import BaseManager
from django.db.models.query import QuerySet
from django.http import (
Http404,
HttpRequest,
Expand Down Expand Up @@ -578,7 +578,7 @@ def list_users_in_group(request: HttpRequest, group_name: str, export: bool = Fa
@user_passes_test_or_403(lambda user: user.is_staff or user.is_registrar_user())
def list_sponsored_users(
request: HttpRequest, group_name: str = 'sponsored_user', export: bool = False
) -> HttpResponse | BaseManager[LinkUser]:
) -> HttpResponse | QuerySet[LinkUser]:
"""
Show list of sponsored users. Adapted from `list_users_in_group` for improved performance.
Expand Down
4 changes: 2 additions & 2 deletions perma_web/perma/views/user_sign_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.contrib import messages
from django.contrib.auth.tokens import default_token_generator
from django.db import transaction
from django.db.models.manager import BaseManager
from django.db.models.query import QuerySet
from django.http import HttpRequest, HttpResponseBadRequest, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.urls import reverse
Expand Down Expand Up @@ -386,7 +386,7 @@ def firm_request_response(request):
return render(request, 'registration/firm_request.html')


def suggest_registrars(user: LinkUser, limit: int = 5) -> BaseManager[Registrar]:
def suggest_registrars(user: LinkUser, limit: int = 5) -> QuerySet[Registrar]:
"""Suggest potential registrars for a user based on email domain.
This queries the database for registrars whose website matches the
Expand Down

0 comments on commit 693bfe5

Please sign in to comment.