Remove .filter() from PageListingMixin.annotate_queryset()

pull/12324/head
Sage Abdullah 2024-09-16 11:23:51 +01:00 zatwierdzone przez Matt Westcott
rodzic 1449a64329
commit c50f7d1918
3 zmienionych plików z 21 dodań i 8 usunięć

Wyświetl plik

@ -198,11 +198,7 @@ class PageListingMixin:
return ordering
def annotate_queryset(self, pages):
pages = pages.prefetch_related("content_type", "sites_rooted_here").filter(
pk__in=page_permission_policy.explorable_instances(
self.request.user
).values_list("pk", flat=True)
)
pages = pages.prefetch_related("content_type", "sites_rooted_here")
# We want specific page instances, but do not need streamfield values here
pages = pages.defer_streamfields().specific()
@ -291,7 +287,11 @@ class IndexView(PageListingMixin, generic.IndexView):
return [col for col in PageListingMixin.columns if col.name != "type"]
def get_base_queryset(self):
pages = self.model.objects.filter(depth__gt=1)
pages = self.model.objects.filter(depth__gt=1).filter(
pk__in=page_permission_policy.explorable_instances(
self.request.user
).values_list("pk", flat=True)
)
pages = self.annotate_queryset(pages)
return pages
@ -365,6 +365,11 @@ class ExplorableIndexView(IndexView):
else:
pages = self.parent_page.get_children()
pages = pages.filter(
pk__in=page_permission_policy.explorable_instances(
self.request.user
).values_list("pk", flat=True)
)
pages = self.annotate_queryset(pages)
return pages

Wyświetl plik

@ -104,7 +104,11 @@ class SearchView(PageListingMixin, PermissionCheckedMixin, BaseListingView):
return super().get(request)
def get_queryset(self) -> QuerySet[Any]:
pages = self.all_pages = Page.objects.all()
pages = self.all_pages = Page.objects.all().filter(
pk__in=page_permission_policy.explorable_instances(
self.request.user
).values_list("pk", flat=True)
)
if self.show_locale_labels:
pages = pages.select_related("locale")

Wyświetl plik

@ -65,7 +65,11 @@ class ContentTypeUseView(PageListingMixin, PermissionCheckedMixin, BaseListingVi
return self.page_class._meta.verbose_name_plural
def get_base_queryset(self):
queryset = self.page_class.objects.all().specific(defer=True)
queryset = self.page_class._default_manager.all().filter(
pk__in=self.permission_policy.explorable_instances(
self.request.user
).values_list("pk", flat=True)
)
return self.annotate_queryset(queryset)
def get_index_url(self):