mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-15 02:33:13 +00:00
Refactor filters to not callback into views
This commit is contained in:
parent
86e1a60ad2
commit
6ed50e18c4
2 changed files with 15 additions and 2 deletions
|
|
@ -91,6 +91,9 @@ class BaseAPIEndpoint(GenericViewSet):
|
|||
return {'title'}
|
||||
|
||||
def get_serializer_context(self):
|
||||
"""
|
||||
The serialization context differs between listing and detail views.
|
||||
"""
|
||||
request = self.request
|
||||
if self.action == 'listing_view':
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -117,8 +117,13 @@ class ChildOfFilter(BaseFilterBackend):
|
|||
except (ValueError, AssertionError):
|
||||
raise BadRequestError("child_of must be a positive integer")
|
||||
|
||||
# Get live pages that are not in a private section
|
||||
pages = Page.objects.public().live()
|
||||
# Filter by site
|
||||
pages = pages.descendant_of(request.site.root_page, inclusive=True)
|
||||
|
||||
try:
|
||||
parent_page = view.get_queryset(request).get(id=parent_page_id)
|
||||
parent_page = pages.get(id=parent_page_id)
|
||||
queryset = queryset.child_of(parent_page)
|
||||
queryset._filtered_by_child_of = True
|
||||
return queryset
|
||||
|
|
@ -139,8 +144,13 @@ class DescendantOfFilter(BaseFilterBackend):
|
|||
except (ValueError, AssertionError):
|
||||
raise BadRequestError("descendant_of must be a positive integer")
|
||||
|
||||
# Get live pages that are not in a private section
|
||||
pages = Page.objects.public().live()
|
||||
# Filter by site
|
||||
pages = pages.descendant_of(request.site.root_page, inclusive=True)
|
||||
|
||||
try:
|
||||
ancestor_page = view.get_queryset(request).get(id=ancestor_page_id)
|
||||
ancestor_page = pages.get(id=ancestor_page_id)
|
||||
return queryset.descendant_of(ancestor_page)
|
||||
except Page.DoesNotExist:
|
||||
raise BadRequestError("ancestor page doesn't exist")
|
||||
|
|
|
|||
Loading…
Reference in a new issue