Skip to content

Commit

Permalink
♻️ [#498] Move ordering to filterset
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm authored and Xaohs committed Nov 22, 2024
1 parent 4531ad7 commit 66bd715
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
15 changes: 14 additions & 1 deletion backend/src/openarchiefbeheer/destruction/api/filtersets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db.models import Case, QuerySet, Value, When
from django.db.models import Case, F, QuerySet, Value, When
from django.utils.translation import gettext_lazy as _

from django_filters import (
Expand Down Expand Up @@ -41,6 +41,13 @@ class DestructionListItemFilterset(FilterSet):
"to define the exact same ordering as the zaak endpoint"
),
)
order_review_ignored = BooleanFilter(
field_name="ordering",
method="filter_order_review_ignored",
help_text=_(
"Return the items where a record manager went against the advice of a reviewer first."
),
)

class Meta:
model = DestructionListItem
Expand All @@ -49,6 +56,7 @@ class Meta:
"status",
"processing_status",
"order_match_zaken",
"order_review_ignored",
)

def filter_in_destruction_list(
Expand Down Expand Up @@ -77,6 +85,11 @@ def filter_order_match_zaken(
) -> QuerySet[DestructionListItem]:
return queryset.order_by("zaak__pk")

def filter_order_review_ignored(
self, queryset: QuerySet[DestructionListItem], name: str, value: bool
) -> QuerySet[DestructionListItem]:
return queryset.order_by(F("review_advice_ignored").desc(nulls_last=True))


class DestructionListFilterset(FilterSet):
assignee = NumberFilter(
Expand Down
13 changes: 2 additions & 11 deletions backend/src/openarchiefbeheer/destruction/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@

from django.contrib.contenttypes.models import ContentType
from django.db import transaction
from django.db.models import (
Case,
F,
OuterRef,
Prefetch,
QuerySet,
Subquery,
Value,
When,
)
from django.db.models import Case, OuterRef, Prefetch, QuerySet, Subquery, Value, When
from django.shortcuts import get_object_or_404
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -445,7 +436,7 @@ def get_queryset(self):
)
)
)
return qs.order_by(F("review_advice_ignored").desc(nulls_last=True))
return qs


@extend_schema_view(
Expand Down

0 comments on commit 66bd715

Please sign in to comment.