Skip to content

Commit

Permalink
Update configuration attribute name for parent filter
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincarrogan committed Feb 12, 2024
1 parent bc0b79e commit b874f40
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions api/core/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

class ParentFilter(filters.BaseFilterBackend):
def filter_queryset(self, request, queryset, view):
parent_id_lookup_field = getattr(view, "parent_id_lookup_field", None)
if not parent_id_lookup_field:
parent_filter_id_lookup_field = getattr(view, "parent_filter_id_lookup_field", None)
if not parent_filter_id_lookup_field:
raise ImproperlyConfigured(
f"Cannot use {self.__class__.__name__} on a view which does not have a parent_id_lookup_field attribute"
f"Cannot use {self.__class__.__name__} on a view which does not have a parent_filter_id_lookup_field attribute"
)

lookup = {
parent_id_lookup_field: view.kwargs["pk"],
parent_filter_id_lookup_field: view.kwargs["pk"],
}
return queryset.filter(**lookup)
2 changes: 1 addition & 1 deletion api/core/tests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class MisconfiguredParentFilterView(RetrieveAPIView):

class ParentFilterView(RetrieveAPIView):
filter_backends = (ParentFilter,)
parent_id_lookup_field = "parent_id"
parent_filter_id_lookup_field = "parent_id"
queryset = ChildModel.objects.all()
serializer_class = ChildModelSerializer
2 changes: 1 addition & 1 deletion api/goods/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def delete(self, request, pk, doc_pk):
class GoodDocumentStream(DocumentStreamAPIView):
authentication_classes = (ExporterAuthentication,)
filter_backends = (ParentFilter,)
parent_id_lookup_field = "good_id"
parent_filter_id_lookup_field = "good_id"
lookup_url_kwarg = "doc_pk"
queryset = GoodDocument.objects.all()
permission_classes = (
Expand Down
4 changes: 2 additions & 2 deletions api/organisations/views/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
class DocumentOnOrganisationView(viewsets.ModelViewSet):
authentication_classes = (SharedAuthentication,)
filter_backends = (ParentFilter,)
parent_filter_id_lookup_field = "organisation_id"
lookup_url_kwarg = "document_on_application_pk"
parent_id_lookup_field = "organisation_id"
permission_classes = (permissions.IsCaseworkerOrInDocumentOrganisation,)
queryset = models.DocumentOnOrganisation.objects.all()
serializer_class = serializers.DocumentOnOrganisationSerializer
Expand Down Expand Up @@ -88,8 +88,8 @@ def update(self, request, pk, document_on_application_pk):
class DocumentOnOrganisationStreamView(DocumentStreamAPIView):
authentication_classes = (SharedAuthentication,)
filter_backends = (ParentFilter,)
parent_filter_id_lookup_field = "organisation_id"
lookup_url_kwarg = "document_on_application_pk"
parent_id_lookup_field = "organisation_id"
permission_classes = (permissions.IsCaseworkerOrInDocumentOrganisation,)
queryset = models.DocumentOnOrganisation.objects.all()

Expand Down

0 comments on commit b874f40

Please sign in to comment.